Allow saving & editing of reports with repository elements

Closes SCI-1279.
This commit is contained in:
Luka Murn 2017-06-05 12:24:06 +02:00
parent b5f6d1da94
commit 02dd6636ba
24 changed files with 82 additions and 78 deletions

View file

@ -217,9 +217,7 @@ function initializeNewElement(newEl) {
url: url, url: url,
type: "GET", type: "GET",
dataType: "json", dataType: "json",
data: { data: parentElementId,
id: parentElementId
},
success: function(data, status, jqxhr) { success: function(data, status, jqxhr) {
// Open modal, set its title, and display module contents // Open modal, set its title, and display module contents
addContentsModal.find(".modal-title").text(modalTitle); addContentsModal.find(".modal-title").text(modalTitle);
@ -500,11 +498,11 @@ function initializeUnsavedWorkDialog() {
*/ */
function getSidebarEl(reportEl) { function getSidebarEl(reportEl) {
var type = reportEl.data("type"); var type = reportEl.data("type");
var id = reportEl.data("id"); var scrollId = reportEl.data("scroll-id");
return $(SIDEBAR_PARENT_TREE).find( return $(SIDEBAR_PARENT_TREE).find(
"li" + "li" +
"[data-type='" + type + "']" + "[data-type='" + type + "']" +
"[data-id='" + id + "']" "[data-scroll-id='" + scrollId + "']"
); );
} }
@ -516,11 +514,11 @@ function getSidebarEl(reportEl) {
*/ */
function getReportEl(sidebarEl) { function getReportEl(sidebarEl) {
var type = sidebarEl.data("type"); var type = sidebarEl.data("type");
var id = sidebarEl.data("id"); var scrollId = sidebarEl.data("scroll-id");
return $(REPORT_CONTENT).find( return $(REPORT_CONTENT).find(
"div.report-element" + "div.report-element" +
"[data-type='" + type + "']" + "[data-type='" + type + "']" +
"[data-id='" + id + "']" "[data-scroll-id='" + scrollId + "']"
); );
} }
@ -565,14 +563,14 @@ function initSidebarElement(reportEl) {
var elChildrenContainer = reportEl.children(".report-element-children"); var elChildrenContainer = reportEl.children(".report-element-children");
var type = reportEl.data("type"); var type = reportEl.data("type");
var name = reportEl.data("name"); var name = reportEl.data("name");
var id = reportEl.data("id"); var scrollId = reportEl.data("scroll-id");
var iconClass = "glyphicon " + reportEl.data("icon-class"); var iconClass = "glyphicon " + reportEl.data("icon-class");
// Generate list element // Generate list element
var newLi = $(document.createElement("li")); var newLi = $(document.createElement("li"));
newLi newLi
.attr("data-type", type) .attr("data-type", type)
.attr("data-id", id); .attr("data-scroll-id", scrollId);
var newSpan = $(document.createElement("span")); var newSpan = $(document.createElement("span"));
newSpan.appendTo(newLi); newSpan.appendTo(newLi);
@ -1025,7 +1023,7 @@ function addElement(jsonEl, prevEl) {
.find( .find(
".report-element" + ".report-element" +
"[data-type='" + el.attr("data-type") + "']" + "[data-type='" + el.attr("data-type") + "']" +
"[data-id='" + el.attr("data-id") + "']" "[data-scroll-id='" + el.attr("data-scroll-id") + "']"
); );
if (existing.length && existing.length > 0) { if (existing.length && existing.length > 0) {
// TODO Remove event listeners on existing element // TODO Remove event listeners on existing element

View file

@ -233,7 +233,7 @@ class ReportsController < ApplicationController
# Experiment for adding contents into experiment element # Experiment for adding contents into experiment element
def experiment_contents_modal def experiment_contents_modal
experiment = Experiment.find_by_id(params[:id]) experiment = Experiment.find_by_id(params[:experiment_id])
respond_to do |format| respond_to do |format|
if experiment.blank? if experiment.blank?
@ -255,7 +255,7 @@ class ReportsController < ApplicationController
# Modal for adding contents into module element # Modal for adding contents into module element
def module_contents_modal def module_contents_modal
my_module = MyModule.find_by_id(params[:id]) my_module = MyModule.find_by_id(params[:my_module_id])
respond_to do |format| respond_to do |format|
if my_module.blank? if my_module.blank?
@ -277,7 +277,7 @@ class ReportsController < ApplicationController
# Modal for adding contents into step element # Modal for adding contents into step element
def step_contents_modal def step_contents_modal
step = Step.find_by_id(params[:id]) step = Step.find_by_id(params[:step_id])
respond_to do |format| respond_to do |format|
if step.blank? if step.blank?
@ -299,7 +299,7 @@ class ReportsController < ApplicationController
# Modal for adding contents into result element # Modal for adding contents into result element
def result_contents_modal def result_contents_modal
result = Result.find_by_id(params[:id]) result = Result.find_by_id(params[:result_id])
respond_to do |format| respond_to do |format|
if result.blank? if result.blank?

View file

@ -45,13 +45,9 @@ module ReportsHelper
ReportElement.type_ofs.keys.each do |type| ReportElement.type_ofs.keys.each do |type|
next unless element.public_send("#{type}?") next unless element.public_send("#{type}?")
local_sym = type.split('_').last.to_sym element.element_references.each do |el_ref|
local_sym = type locals[el_ref.class.name.underscore.to_sym] = el_ref
.split('_') end
.first
.to_sym if type.in? ReportExtends::FIRST_PART_ELEMENTS
local_sym = :my_module if type.in? ReportExtends::MY_MODULE_ELEMENTS
locals[local_sym] = element.element_reference
locals[:order] = element locals[:order] = element
.sort_order if type.in? ReportExtends::SORTED_ELEMENTS .sort_order if type.in? ReportExtends::SORTED_ELEMENTS
end end

View file

@ -95,7 +95,7 @@ class Report < ActiveRecord::Base
el.parent = parent el.parent = parent
el.type_of = json_element['type_of'] el.type_of = json_element['type_of']
el.sort_order = json_element['sort_order'] el.sort_order = json_element['sort_order']
el.set_element_reference(json_element['id']) el.set_element_references(json_element['id'])
el.save! el.save!
if json_element['children'].present? if json_element['children'].present?

View file

@ -31,6 +31,7 @@ class ReportElement < ActiveRecord::Base
belongs_to :checklist, inverse_of: :report_elements belongs_to :checklist, inverse_of: :report_elements
belongs_to :asset, inverse_of: :report_elements belongs_to :asset, inverse_of: :report_elements
belongs_to :table, inverse_of: :report_elements belongs_to :table, inverse_of: :report_elements
belongs_to :repository, inverse_of: :report_elements
def has_children? def has_children?
children.length > 0 children.length > 0
@ -44,19 +45,21 @@ class ReportElement < ActiveRecord::Base
step_comments? or result_comments? step_comments? or result_comments?
end end
# Get the referenced element (previously, element's type_of must be set) # Get the referenced elements (previously, element's type_of must be set)
def element_reference def element_references
ReportExtends::ELEMENT_REFERENCES.each do |el_ref| ReportExtends::ELEMENT_REFERENCES.each do |el_ref|
return eval(el_ref.element.gsub('_id', '')) if el_ref.check(self) return el_ref.elements.map { |el| eval(el.gsub('_id', '')) } if el_ref.check(self)
end end
end end
# Set the element reference (previously, element's type_of must be set) # Set the element references (previously, element's type_of must be set)
def set_element_reference(ref_id) def set_element_references(ref_ids)
ReportExtends::SET_ELEMENT_REFERENCES_LIST.each do |el_ref| ReportExtends::SET_ELEMENT_REFERENCES_LIST.each do |el_ref|
check = el_ref.check(self) check = el_ref.check(self)
next unless check next unless check
public_send("#{el_ref.element}=", ref_id) el_ref.elements.each do |element|
public_send("#{element}=", ref_ids[element])
end
break break
end end
end end
@ -64,7 +67,7 @@ class ReportElement < ActiveRecord::Base
# removes element that are archived or deleted # removes element that are archived or deleted
def clean_removed_or_archived_elements def clean_removed_or_archived_elements
parent_model = '' parent_model = ''
%w(project experiment my_module step result checklist asset table) %w(project experiment my_module step result checklist asset table repository)
.each do |el| .each do |el|
parent_model = el if send el parent_model = el if send el
end end
@ -81,17 +84,12 @@ class ReportElement < ActiveRecord::Base
private private
def has_one_of_referenced_elements def has_one_of_referenced_elements
num_of_refs = [project, element_references.each do |el|
experiment, if el.nil?
my_module, errors.add(:base,
step, 'Report element doesn\'t have correct element references.')
result, break
checklist, end
asset,
table].count { |r| r.present? }
if num_of_refs != 1
errors.add(:base,
'Report element must have exactly one element reference.')
end end
end end
end end

View file

@ -5,6 +5,7 @@ class Repository < ActiveRecord::Base
has_many :repository_rows has_many :repository_rows
has_many :repository_table_states, has_many :repository_table_states,
inverse_of: :repository, dependent: :destroy inverse_of: :repository, dependent: :destroy
has_many :report_elements, inverse_of: :repository, dependent: :destroy
auto_strip_attributes :name, nullify: false auto_strip_attributes :name, nullify: false
validates :name, validates :name,

View file

@ -3,7 +3,8 @@
<div class="report-element report-experiment-element" <div class="report-element report-experiment-element"
data-ts="<%= timestamp.to_i %>" data-ts="<%= timestamp.to_i %>"
data-type="experiment" data-type="experiment"
data-id="<%= experiment.id %>" data-id='{ "experiment_id": <%= experiment.id %> }'
data-scroll-id="<%= experiment.id %>"
data-modal-title="<%=t "projects.reports.elements.modals.experiment_contents.head_title", data-modal-title="<%=t "projects.reports.elements.modals.experiment_contents.head_title",
experiment: experiment.name %>" data-name="<%= name %>" data-icon-class="fa fa-flask"> experiment: experiment.name %>" data-name="<%= name %>" data-icon-class="fa fa-flask">
<div class="report-element-header"> <div class="report-element-header">

View file

@ -2,7 +2,7 @@
<% if order.blank? and @order.present? then order = @order end %> <% if order.blank? and @order.present? then order = @order end %>
<% timestamp = Time.current + 1.year - 2.days %> <% timestamp = Time.current + 1.year - 2.days %>
<% activities = my_module.activities.order(created_at: order) %> <% activities = my_module.activities.order(created_at: order) %>
<div class="report-element report-module-activity-element" data-ts="<%= timestamp.to_i %>" data-type="my_module_activity" data-id="<%= my_module.id %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-name="<%=t "projects.reports.elements.module_activity.sidebar_name" %>" data-icon-class="glyphicon glyphicon-equalizer"> <div class="report-element report-module-activity-element" data-ts="<%= timestamp.to_i %>" data-type="my_module_activity" data-id='{ "my_module_id": <%= my_module.id %> }' data-scroll-id="<%= my_module.id %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-name="<%=t "projects.reports.elements.module_activity.sidebar_name" %>" data-icon-class="glyphicon glyphicon-equalizer">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left activity-icon"> <div class="pull-left activity-icon">

View file

@ -1,7 +1,7 @@
<% if my_module.blank? and @my_module.present? then my_module = @my_module end %> <% if my_module.blank? and @my_module.present? then my_module = @my_module end %>
<% timestamp = my_module.created_at %> <% timestamp = my_module.created_at %>
<% name = my_module.name %> <% name = my_module.name %>
<div class="report-element report-module-element" data-ts="<%= timestamp.to_i %>" data-type="my_module" data-id="<%= my_module.id %>" data-modal-title="<%=t "projects.reports.elements.modals.module_contents.head_title", module: my_module.name %>" data-name="<%= name %>" data-icon-class="glyphicon-credit-card"> <div class="report-element report-module-element" data-ts="<%= timestamp.to_i %>" data-type="my_module" data-id='{ "my_module_id": <%= my_module.id %> }' data-scroll-id="<%= my_module.id %>" data-modal-title="<%=t "projects.reports.elements.modals.module_contents.head_title", module: my_module.name %>" data-name="<%= name %>" data-icon-class="glyphicon-credit-card">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left user-time"> <div class="pull-left user-time">

View file

@ -1,10 +1,10 @@
<% repository = Repository.find(element_id) %> <% repository ||= Repository.find(element_id) %>
<% if my_module.blank? and @my_module.present? then my_module = @my_module end %> <% if my_module.blank? and @my_module.present? then my_module = @my_module end %>
<% rows = my_module.repository_rows.where(repository: repository) %> <% rows = my_module.repository_rows.where(repository: repository) %>
<% if order.blank? and @order.present? then order = @order end %> <% if order.blank? and @order.present? then order = @order end %>
<% timestamp = Time.current + 1.year - 1.days %> <% timestamp = Time.current + 1.year - 1.days %>
<% rows_json = my_module.repository_json_hot(element_id, order) %> <% rows_json = my_module.repository_json_hot(repository.id, order) %>
<div class="report-element report-module-repository-element" data-sort-hot="1" data-ts="<%= timestamp.to_i %>" data-type="my_module_repository" data-id="<%= "#{my_module.id}_#{repository.id}" %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-name="<%= repository.name %>" data-icon-class="glyphicon-oil"> <div class="report-element report-module-repository-element" data-sort-hot="1" data-ts="<%= timestamp.to_i %>" data-type="my_module_repository" data-id='{ "my_module_id": <%= my_module.id %>, "repository_id": <%= repository.id %> }' data-scroll-id="<%= "#{my_module.id}_#{repository.id}" %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-name="<%= repository.name %>" data-icon-class="glyphicon-oil">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left repository-icon"> <div class="pull-left repository-icon">

View file

@ -5,7 +5,7 @@
<% timestamp = asset.created_at %> <% timestamp = asset.created_at %>
<% name = result.name %> <% name = result.name %>
<% icon_class = is_image ? "glyphicon-picture" : "glyphicon-file" %> <% icon_class = is_image ? "glyphicon-picture" : "glyphicon-file" %>
<div class="report-element report-result-element report-result-asset-element" data-ts="<%= timestamp.to_i %>" data-type="result_asset" data-id="<%= result.id %>" data-modal-title="<%=t "projects.reports.elements.modals.result_contents.head_title", result: result.name %>" data-name="<%= name %>" data-icon-class="<%= icon_class %>"> <div class="report-element report-result-element report-result-asset-element" data-ts="<%= timestamp.to_i %>" data-type="result_asset" data-id='{ "result_id": <%= result.id %> }' data-scroll-id="<%= result.id %>" data-modal-title="<%=t "projects.reports.elements.modals.result_contents.head_title", result: result.name %>" data-name="<%= name %>" data-icon-class="<%= icon_class %>">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left result-icon"> <div class="pull-left result-icon">

View file

@ -3,7 +3,7 @@
<% comments = result.result_comments %> <% comments = result.result_comments %>
<% timestamp = table.created_at %> <% timestamp = table.created_at %>
<% name = result.name %> <% name = result.name %>
<div class="report-element report-result-element report-result-table-element" data-ts="<%= timestamp.to_i %>" data-type="result_table" data-id="<%= result.id %>" data-modal-title="<%=t "projects.reports.elements.modals.result_contents.head_title", result: result.name %>" data-name="<%= name %>" data-icon-class="glyphicon-th"> <div class="report-element report-result-element report-result-table-element" data-ts="<%= timestamp.to_i %>" data-type="result_table" data-id='{ "result_id": <%= result.id %> }' data-scroll-id="<%= result.id %>" data-modal-title="<%=t "projects.reports.elements.modals.result_contents.head_title", result: result.name %>" data-name="<%= name %>" data-icon-class="glyphicon-th">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left result-name-container"> <div class="pull-left result-name-container">

View file

@ -3,7 +3,7 @@
<% comments = result.result_comments %> <% comments = result.result_comments %>
<% timestamp = result.created_at %> <% timestamp = result.created_at %>
<% name = result.name %> <% name = result.name %>
<div class="report-element report-result-element report-result-text-element" data-ts="<%= timestamp.to_i %>" data-type="result_text" data-id="<%= result.id %>" data-modal-title="<%=t "projects.reports.elements.modals.result_contents.head_title", result: result.name %>" data-name="<%= name %>" data-icon-class="glyphicon-asterisk"> <div class="report-element report-result-element report-result-text-element" data-ts="<%= timestamp.to_i %>" data-type="result_text" data-id='{ "result_id": <%= result.id %> }' data-scroll-id="<%= result.id %>" data-modal-title="<%=t "projects.reports.elements.modals.result_contents.head_title", result: result.name %>" data-name="<%= name %>" data-icon-class="glyphicon-asterisk">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left result-icon"> <div class="pull-left result-icon">

View file

@ -2,7 +2,7 @@
<% if order.blank? and @order.present? then order = @order end %> <% if order.blank? and @order.present? then order = @order end %>
<% timestamp = Time.current + 1.year - 1.days %> <% timestamp = Time.current + 1.year - 1.days %>
<% samples_json = my_module.samples_json_hot(order) %> <% samples_json = my_module.samples_json_hot(order) %>
<div class="report-element report-module-samples-element" data-sort-hot="3" data-ts="<%= timestamp.to_i %>" data-type="my_module_samples" data-id="<%= my_module.id %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-name="<%=t "projects.reports.elements.module_samples.sidebar_name" %>" data-icon-class="glyphicon-tint"> <div class="report-element report-module-samples-element" data-sort-hot="3" data-ts="<%= timestamp.to_i %>" data-type="my_module_samples" data-id='{ "my_module_id": <%= my_module.id %> }' data-scroll-id="<%= my_module.id %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-name="<%=t "projects.reports.elements.module_samples.sidebar_name" %>" data-icon-class="glyphicon-tint">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left samples-icon"> <div class="pull-left samples-icon">

View file

@ -6,7 +6,7 @@
<% assets = step.assets %> <% assets = step.assets %>
<% checklists = step.checklists %> <% checklists = step.checklists %>
<% comments = step.step_comments %> <% comments = step.step_comments %>
<div class="report-element report-step-element" data-ts="<%= timestamp.to_i %>" data-type="step" data-id="<%= step.id %>" data-modal-title="<%=t "projects.reports.elements.modals.step_contents.head_title", step: step.name %>" data-name="<%=t "projects.reports.elements.step.sidebar_name", pos: (step.position + 1), name: step.name %>" data-icon-class="glyphicon-circle-arrow-right"> <div class="report-element report-step-element" data-ts="<%= timestamp.to_i %>" data-type="step" data-id='{ "step_id": <%= step.id %> }' data-scroll-id="<%= step.id %>" data-modal-title="<%=t "projects.reports.elements.modals.step_contents.head_title", step: step.name %>" data-name="<%=t "projects.reports.elements.step.sidebar_name", pos: (step.position + 1), name: step.name %>" data-icon-class="glyphicon-circle-arrow-right">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left user-time"> <div class="pull-left user-time">

View file

@ -1,6 +1,6 @@
<% if project.blank? and @project.present? then project = @project end %> <% if project.blank? and @project.present? then project = @project end %>
<% name = t("projects.reports.elements.project_header.title", project: project.name) %> <% name = t("projects.reports.elements.project_header.title", project: project.name) %>
<div class="report-element report-project-header-element" data-ts="ignore" data-type="project_header" data-id="<%= project.id %>" data-name="<%= name %>" data-icon-class="glyphicon-header"> <div class="report-element report-project-header-element" data-ts="ignore" data-type="project_header" data-id='{ "project_id": <%= project.id %> }' data-scroll-id="<%= project.id %>" data-name="<%= name %>" data-icon-class="glyphicon-header">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left user-time"> <div class="pull-left user-time">

View file

@ -2,7 +2,7 @@
<% if order.blank? and @order.present? then order = @order end %> <% if order.blank? and @order.present? then order = @order end %>
<% comments = result.result_comments.order(created_at: order) %> <% comments = result.result_comments.order(created_at: order) %>
<% timestamp = Time.current + 1.year %> <% timestamp = Time.current + 1.year %>
<div class="report-element report-comments-element report-result-comments-element" data-ts="<%= timestamp.to_i %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-type="result_comments" data-id="<%= result.id %>" data-name="<%=t "projects.reports.elements.result_comments.sidebar_name" %>" data-icon-class="glyphicon-comment"> <div class="report-element report-comments-element report-result-comments-element" data-ts="<%= timestamp.to_i %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-type="result_comments" data-id='{ "result_id": <%= result.id %> }' data-scroll-id="<%= result.id %>" data-name="<%=t "projects.reports.elements.result_comments.sidebar_name" %>" data-icon-class="glyphicon-comment">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left comments-icon"> <div class="pull-left comments-icon">

View file

@ -2,7 +2,7 @@
<% is_image = asset.is_image? %> <% is_image = asset.is_image? %>
<% timestamp = asset.created_at %> <% timestamp = asset.created_at %>
<% icon_class = is_image ? 'glyphicon-picture' : 'glyphicon-file' %> <% icon_class = is_image ? 'glyphicon-picture' : 'glyphicon-file' %>
<div class="report-element report-step-attachment-element report-step-asset-element" data-ts="<%= timestamp.to_i %>" data-type="step_asset" data-id="<%= asset.id %>" data-name="<%=t "projects.reports.elements.step_asset.sidebar_name", file: asset.file_file_name %>" data-icon-class="<%= icon_class %>"> <div class="report-element report-step-attachment-element report-step-asset-element" data-ts="<%= timestamp.to_i %>" data-type="step_asset" data-id='{ "asset_id": <%= asset.id %> }' data-scroll-id="<%= asset.id %>" data-name="<%=t "projects.reports.elements.step_asset.sidebar_name", file: asset.file_file_name %>" data-icon-class="<%= icon_class %>">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left attachment-icon"> <div class="pull-left attachment-icon">

View file

@ -1,7 +1,7 @@
<% if checklist.blank? and @checklist.present? then checklist = @checklist end %> <% if checklist.blank? and @checklist.present? then checklist = @checklist end %>
<% items = checklist.checklist_items %> <% items = checklist.checklist_items %>
<% timestamp = checklist.created_at %> <% timestamp = checklist.created_at %>
<div class="report-element report-step-attachment-element report-step-checklist-element" data-ts="<%= timestamp.to_i %>" data-type="step_checklist" data-id="<%= checklist.id %>" data-name="<%= checklist.name %>" data-icon-class="glyphicon-list"> <div class="report-element report-step-attachment-element report-step-checklist-element" data-ts="<%= timestamp.to_i %>" data-type="step_checklist" data-id='{ "checklist_id": <%= checklist.id %> }' data-scroll-id="<%= checklist.id %>" data-name="<%= checklist.name %>" data-icon-class="glyphicon-list">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left attachment-icon"> <div class="pull-left attachment-icon">

View file

@ -2,7 +2,7 @@
<% if order.blank? and @order.present? then order = @order end %> <% if order.blank? and @order.present? then order = @order end %>
<% comments = step.step_comments.order(created_at: order) %> <% comments = step.step_comments.order(created_at: order) %>
<% timestamp = Time.current + 1.year %> <% timestamp = Time.current + 1.year %>
<div class="report-element report-comments-element report-step-comments-element" data-ts="<%= timestamp.to_i %>" data-order="asc" data-type="step_comments" data-id="<%= step.id %>" data-name="<%=t "projects.reports.elements.step_comments.sidebar_name" %>" data-icon-class="glyphicon-comment"> <div class="report-element report-comments-element report-step-comments-element" data-ts="<%= timestamp.to_i %>" data-order="asc" data-type="step_comments" data-id='{ "step_id": <%= step.id %> }' data-scroll-id="<%= step.id %>" data-name="<%=t "projects.reports.elements.step_comments.sidebar_name" %>" data-icon-class="glyphicon-comment">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left comments-icon"> <div class="pull-left comments-icon">

View file

@ -1,6 +1,6 @@
<% if table.blank? and @table.present? then table = @table end %> <% if table.blank? and @table.present? then table = @table end %>
<% timestamp = table.created_at %> <% timestamp = table.created_at %>
<div class="report-element report-step-attachment-element report-step-table-element" data-ts="<%= timestamp.to_i %>" data-type="step_table" data-id="<%= table.id %>" data-name="<%= table.name %>" data-icon-class="glyphicon-th"> <div class="report-element report-step-attachment-element report-step-table-element" data-ts="<%= timestamp.to_i %>" data-type="step_table" data-id='{ "table_id": <%= table.id %> }' data-scroll-id="<%= table.id %>" data-name="<%= table.name %>" data-icon-class="glyphicon-th">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left attachment-icon"> <div class="pull-left attachment-icon">

View file

@ -35,7 +35,8 @@ class Extends
result_comments: 12, result_comments: 12,
project_activity: 13, # TODO project_activity: 13, # TODO
project_samples: 14, # TODO project_samples: 14, # TODO
experiment: 15 } experiment: 15,
my_module_repository: 16 }
# Data type name should match corresponding model's name # Data type name should match corresponding model's name
REPOSITORY_DATA_TYPES = { RepositoryTextValue: 0, REPOSITORY_DATA_TYPES = { RepositoryTextValue: 0,

View file

@ -108,10 +108,11 @@ module ReportExtends
# ADD REPORT ELEMENT TYPE WHICH YOU WANT TO PASS 'ORDER' LOCAL IN THE PARTIAL # ADD REPORT ELEMENT TYPE WHICH YOU WANT TO PASS 'ORDER' LOCAL IN THE PARTIAL
SORTED_ELEMENTS = %w(my_module_activity SORTED_ELEMENTS = %w(my_module_activity
my_module_samples my_module_samples
my_module_repository
step_comments step_comments
result_comments) result_comments)
# sets local :my_module to the listed my_module child elements # sets local :my_module to the listed my_module child elements
MY_MODULE_ELEMENTS = %w(my_module my_module_activity my_module_samples) MY_MODULE_ELEMENTS = %w(my_module my_module_activity my_module_samples my_module_repository)
# sets local name to first element of the listed elements # sets local name to first element of the listed elements
FIRST_PART_ELEMENTS = %w(result_comments FIRST_PART_ELEMENTS = %w(result_comments
@ -124,9 +125,9 @@ module ReportExtends
# path: app/models/report_element.rb # path: app/models/report_element.rb
# method: set_element_reference # method: set_element_reference
ElementReference = Struct.new(:checker, :element) do ElementReference = Struct.new(:checker, :elements) do
def initialize(checker, element = :element_reference_needed!) def initialize(checker, elements = :element_reference_needed!)
super(checker, element) super(checker, elements)
end end
def check(report_element) def check(report_element)
@ -141,22 +142,23 @@ module ReportExtends
report_element.project_activity? || report_element.project_activity? ||
report_element.project_samples? report_element.project_samples?
end, end,
'project_id' ['project_id']
), ),
ElementReference.new(proc(&:experiment?), 'experiment_id'), ElementReference.new(proc(&:experiment?), ['experiment_id']),
ElementReference.new( ElementReference.new(
proc do |report_element| proc do |report_element|
report_element.my_module? || report_element.my_module? ||
report_element.my_module_activity? || report_element.my_module_activity? ||
report_element.my_module_samples? report_element.my_module_samples?
end, end,
'my_module_id' ['my_module_id']
), ),
ElementReference.new(proc(&:my_module_repository?), ['my_module_id', 'repository_id']),
ElementReference.new( ElementReference.new(
proc do |report_element| proc do |report_element|
report_element.step? || report_element.step_comments? report_element.step? || report_element.step_comments?
end, end,
'step_id' ['step_id']
), ),
ElementReference.new( ElementReference.new(
proc do |report_element| proc do |report_element|
@ -165,11 +167,11 @@ module ReportExtends
report_element.result_text? || report_element.result_text? ||
report_element.result_comments? report_element.result_comments?
end, end,
'result_id' ['result_id']
), ),
ElementReference.new(proc(&:step_checklist?), 'checklist_id'), ElementReference.new(proc(&:step_checklist?), ['checklist_id']),
ElementReference.new(proc(&:step_asset?), 'asset_id'), ElementReference.new(proc(&:step_asset?), ['asset_id']),
ElementReference.new(proc(&:step_table?), 'table_id') ElementReference.new(proc(&:step_table?), ['table_id'])
] ]
# path: app/models/report_element.rb # path: app/models/report_element.rb
@ -182,23 +184,24 @@ module ReportExtends
report_element.project_activity? || report_element.project_activity? ||
report_element.project_samples? report_element.project_samples?
end, end,
'project_id' ['project_id']
), ),
ElementReference.new(proc(&:experiment?), 'experiment_id'), ElementReference.new(proc(&:experiment?), ['experiment_id']),
ElementReference.new( ElementReference.new(
proc do |report_element| proc do |report_element|
report_element.my_module? || report_element.my_module? ||
report_element.my_module_activity? || report_element.my_module_activity? ||
report_element.my_module_samples? report_element.my_module_samples?
end, end,
'my_module_id' ['my_module_id']
), ),
ElementReference.new(proc(&:my_module_repository?), ['my_module_id', 'repository_id']),
ElementReference.new( ElementReference.new(
proc do |report_element| proc do |report_element|
report_element.step? || report_element.step? ||
report_element.step_comments? report_element.step_comments?
end, end,
'step_id' ['step_id']
), ),
ElementReference.new( ElementReference.new(
proc do |report_element| proc do |report_element|
@ -207,10 +210,10 @@ module ReportExtends
report_element.result_text? || report_element.result_text? ||
report_element.result_comments? report_element.result_comments?
end, end,
'result_id' ['result_id']
), ),
ElementReference.new(proc(&:step_checklist?), 'checklist_id'), ElementReference.new(proc(&:step_checklist?), ['checklist_id']),
ElementReference.new(proc(&:step_asset?), 'asset_id'), ElementReference.new(proc(&:step_asset?), ['asset_id']),
ElementReference.new(proc(&:step_table?), 'table_id') ElementReference.new(proc(&:step_table?), ['table_id'])
] ]
end end

View file

@ -0,0 +1,6 @@
class AddRepositoryIdToReportElement < ActiveRecord::Migration
def change
add_column :report_elements, :repository_id, :integer
add_index :report_elements, :repository_id
end
end