Add experiment to report screen

Only placeholder for now, JS still needs fixing.
This commit is contained in:
Jure Grabnar 2016-07-28 16:16:14 +02:00
parent ac708e7497
commit d82ba163ed
3 changed files with 76 additions and 11 deletions

View file

@ -400,23 +400,39 @@ class ReportsController < ApplicationController
.keys
.collect { |id| id.to_i }
modules.each do |module_id|
my_module = MyModule.find_by_id(module_id)
if my_module.present?
res << generate_new_el(false)
el = generate_el(
"reports/elements/my_module_element.html.erb",
{ my_module: my_module }
)
el[:children] = generate_module_contents_json(my_module)
res << el
end
# Get unique experiments from given modules
experiments = MyModule.where(id: modules).map(&:experiment).uniq
experiments.each do |experiment|
res << generate_new_el(false)
el = generate_el(
"reports/elements/experiment_element.html.erb",
{ experiment: experiment }
)
el[:children] = generate_experiment_contents_json(experiment, modules)
res << el
end
end
res << generate_new_el(false)
res
end
def generate_experiment_contents_json(experiment, selected_modules)
res = []
experiment.my_modules.each do |my_module|
if selected_modules.include?(my_module.id)
res << generate_new_el(false)
el = generate_el(
"reports/elements/my_module_element.html.erb",
{ my_module: my_module }
)
el[:children] = generate_module_contents_json(my_module)
res << el
res << generate_new_el(false)
end
end
res
end
def generate_module_contents_json(my_module)
res = []
if (in_params? :module_steps) && my_module.protocol.present? then

View file

@ -0,0 +1,40 @@
<% timestamp = experiment.created_at %>
<% name = experiment.name %>
<div class="report-element report-experiment-element"
data-ts="<%= timestamp.to_i %>"
data-type="experiment"
data-id="<%= experiment.id %>"
data-modal-title="<%=t "projects.reports.elements.modals.experiment_contents.head_title",
experiment: experiment.name %>" data-name="<%= name %>" data-icon-class="glyphicon-filter">
<div class="report-element-header">
<div class="row">
<div class="pull-left user-time">
<%=t "projects.reports.elements.experiment.user_time", timestamp: l(timestamp, format: :full) %>
</div>
<div class="pull-right controls">
<%= render partial: "reports/elements/module_element_controls.html.erb", locals: { show_sort: true } %>
</div>
</div>
</div>
<div class="report-element-body">
<div class="row">
<div class="pull-left experiment-name">
<h4>
<span class="glyphicon glyphicon-filter"></span>
<%= name %></h4>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<% if experiment.description.present? %>
<%= experiment.description %>
<% else %>
<em><%=t "projects.reports.elements.experiment.no_description" %></em>
<% end %>
</div>
</div>
</div>
<div class="report-element-children">
<%= children if (defined? children and children.present?) %>
</div>
</div>

View file

@ -275,6 +275,11 @@ en:
module_tab: "Task content"
steps_tab: "Protocols content"
results_tab: "Results content"
experiment_contents:
head_title: "Add contents to experiment %{experiment}"
module_tab: "Task content"
steps_tab: "Protocols content"
results_tab: "Results content"
module_contents_inner:
instructions: "Choose what information from task/s to include in the report"
header: "Report elements"
@ -332,6 +337,10 @@ en:
no_description: "No description"
tags_header: "Task tags:"
no_tags: "No tags"
experiment:
user_time: "Experiment created on %{timestamp}."
no_description: "No description"
no_tags: "No tags"
module_activity:
name: "Activity of task %{my_module}"
sidebar_name: "Activity"