Fix report saving [SCI-3443] (#1753)

* Fix report saving

* Fix the report saving by using the reports' structures

* Remove uneccesary yarn.lock (mistake)
This commit is contained in:
aignatov-bio 2019-05-13 10:55:08 +02:00 committed by GitHub
parent da5b24ef57
commit d3aa6371cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 21 additions and 13 deletions

View file

@ -180,7 +180,7 @@ function initializeNewElement(newEl) {
switch (parent.data("type")) {
case "experiment":
url = dh.data("add-experiment-contents-url"); break;
case 'my_module' || 'protocol':
case 'my_module':
url = dh.data("add-module-contents-url"); break;
case "step":
url = dh.data("add-step-contents-url"); break;

View file

@ -70,13 +70,6 @@ module ReportActions
def generate_module_contents_json(my_module)
res = []
res << generate_new_el(false)
el = generate_el(
'reports/elements/my_module_protocol_element.html.erb',
protocol: my_module.protocol
)
res << el
ReportExtends::MODULE_CONTENTS.each do |contents|
elements = []
contents.values.each do |element|

View file

@ -8,7 +8,6 @@ module ReportsHelper
def render_report_element(element, provided_locals = nil)
# Determine partial
file_name = element.type_of
if element.type_of.in? ReportExtends::MY_MODULE_CHILDREN_ELEMENTS
file_name = "my_module_#{element.type_of.singularize}"

View file

@ -27,6 +27,8 @@ module TinyMceImages
tm_asset_to_update = html_description.css(
"img[data-mce-token=\"#{Base62.encode(tm_asset.id)}\"]"
)[0]
next unless tm_asset_to_update
tm_asset_to_update.attributes['src'].value = new_tm_asset_src
description = html_description.css('body').inner_html.to_s
ensure

View file

@ -100,6 +100,7 @@ class Report < ApplicationRecord
exp.my_modules.each do |my_module|
module_children = []
module_children += gen_element_content(my_module, nil, 'my_module_protocol', true)
my_module.protocol.steps.each do |step|
step_children =
gen_element_content(step, step.assets, 'step_asset')

View file

@ -1,5 +1,5 @@
<div class="report-element report-module-protocol-element" data-ts="<%= protocol.created_at %>" data-type="protocol" data-id='{ "protocol_id": <%= protocol.id %> }' data-scroll-id="<%= protocol.id %>">
<% protocol ||= my_module.protocol %>
<div class="report-element report-module-protocol-element" data-ts="<%= protocol.created_at %>" data-type="my_module_protocol" data-id='{ "my_module_id": <%= my_module.id %> }' data-scroll-id="<%= protocol.id %>">
<div class="report-element-header">
<div class="row">
<div class="pull-left user-time">
@ -18,4 +18,5 @@
<em><%= t('my_modules.protocols.protocol_status_bar.no_description') %></em>
<% end %>
</div>
</div>
</div>

View file

@ -1,5 +1,4 @@
<% my_module_undefined = !defined? my_module or my_module.blank? %>
<div>
<em>
<%= t("projects.reports.elements.modals.module_contents_inner.instructions") %>
@ -12,6 +11,10 @@
<%= form.check_box :module_all, label: t("projects.reports.elements.modals.module_contents_inner.check_all") %>
<ul>
<li>
<%= form.check_box :module_protocol, label: t("projects.reports.elements.modals.module_contents_inner.protocol") %>
</li>
<% if my_module_undefined or my_module.protocol.steps.exists? %>
<li>
<%= form.check_box :module_steps, label: t("projects.reports.elements.modals.module_contents_inner.steps") %>

View file

@ -38,7 +38,8 @@ class Extends
project_samples: 14, # TODO
experiment: 15,
# Higher number because of addons
my_module_repository: 17 }
my_module_repository: 17,
my_module_protocol: 18 }
# Data type name should match corresponding model's name
REPOSITORY_DATA_TYPES = { RepositoryTextValue: 0,

View file

@ -59,6 +59,10 @@ module ReportExtends
# Module contents element
MODULE_CONTENTS = [
ModuleElement.new([:protocol],
:protocol,
false,
[:my_module]),
ModuleElement.new(%i(completed_steps uncompleted_steps),
:steps,
true,
@ -114,6 +118,7 @@ module ReportExtends
result_comments)
# sets local :my_module to the listed my_module child elements
MY_MODULE_ELEMENTS = %w(my_module
my_module_protocol
my_module_activity
my_module_repository)
@ -153,6 +158,7 @@ module ReportExtends
ElementReference.new(
proc do |report_element|
report_element.my_module? ||
report_element.my_module_protocol? ||
report_element.my_module_activity? ||
report_element.my_module_samples?
end,
@ -198,6 +204,7 @@ module ReportExtends
ElementReference.new(
proc do |report_element|
report_element.my_module? ||
report_element.my_module_protocol? ||
report_element.my_module_activity? ||
report_element.my_module_samples?
end,

View file

@ -410,6 +410,7 @@ en:
module_contents_inner:
instructions: "Select the information from your task that you would like to include to your report."
check_all: "All tasks content"
protocol: "Protocol"
steps: "Steps"
completed_steps: "Completed"
uncompleted_steps: "Uncompleted"