Add logic for preparing wizard data for report [SCI-5593]

This commit is contained in:
aignatov-bio 2021-04-09 13:19:22 +02:00
parent 57b133d0fc
commit 101d46956c
7 changed files with 102 additions and 23 deletions

View file

@ -968,6 +968,74 @@ function reportHandsonTableConverter() {
}
(function() {
function getReportData() {
var reportData = {};
// Report name
reportData.name = $('.report-name').val();
// Project
reportData.project_id = dropdownSelector.getValues('#projectSelector');
// Template
reportData.template_id = dropdownSelector.getValues('#templateSelector');
// Template values
reportData.template_values = {};
$.each($('.report-template-values-container').find('.sci-input-field, select'), function(i, field) {
reportData.template_values[field.name] = field.value;
});
$.each($('.report-template-values-container .sci-checkbox'), function(i, checkbox) {
if (checkbox.name.includes('[]')) {
let name = checkbox.name.replace('[]', '');
if (!reportData.template_values[name]) {
reportData.template_values[name] = {};
}
reportData
.template_values[name][checkbox.value] = checkbox.checked;
} else {
reportData.template_values[checkbox.name] = checkbox.checked;
}
});
// Project content
reportData.project_content = [];
$.each($('.project-contents-container .experiment-element'), function(i, experiment) {
let experimentHash = {};
if (!$(experiment).find('.report-experiment-checkbox').prop('checked')) return;
experimentHash.experiment_id = $(experiment).find('.report-experiment-checkbox').val();
experimentHash.my_modules = [];
$.each($(experiment).find('.report-my-module-checkbox:checked'), function(j, myModule) {
experimentHash.my_modules.push(myModule.value);
});
reportData.project_content.push(experimentHash);
});
// Settings
reportData.settings = { task: { protocol: {} } };
reportData.settings.all_tasks = $('.task-contents-container .select-all-task-contents').prop('checked');
$.each($('.task-contents-container .content-element .protocol-setting'), function(i, e) {
reportData.settings.task.protocol[e.value] = e.checked;
});
$.each($('.task-contents-container .content-element .task-setting'), function(i, e) {
reportData.settings.task[e.value] = e.checked;
});
reportData.settings.task.result_order = dropdownSelector.getValues('#taskResultsOrder');
return reportData;
}
function initGenerateButton() {
$('.reports-new').on('click', '.generate-button', function() {
$.post(this.dataset.createUrl, getReportData(), function() {
// TODO
});
});
}
function initReportWizard() {
function nextStep() {
var currentStep = parseInt($('.reports-new-footer').attr('data-step'), 10);
@ -996,17 +1064,19 @@ function reportHandsonTableConverter() {
});
$('.reports-new-body [href="#new-report-step-2"]').on('show.bs.tab', function() {
var projectId = dropdownSelector.getValues('#projectSelector');
var projectContents = $('#new-report-step-2').find('.project-contents');
animateSpinner('.reports-new-body');
$.get(projectContents.data('project-content-url'), { project_id: projectId }, function(data) {
animateSpinner('.reports-new-body', false);
projectContents.html(data.html);
if ($('.select-all-my-modules-checkbox').prop('checked')) {
$('.select-all-my-modules-checkbox').trigger('change');
}
$('.experiment-contents').sortable();
});
if (projectContents.is(':empty')) {
let projectId = dropdownSelector.getValues('#projectSelector');
animateSpinner('.reports-new-body');
$.get(projectContents.data('project-content-url'), { project_id: projectId }, function(data) {
animateSpinner('.reports-new-body', false);
projectContents.html(data.html);
if ($('.select-all-my-modules-checkbox').prop('checked')) {
$('.select-all-my-modules-checkbox').trigger('change');
}
$('.experiment-contents').sortable();
});
}
});
$('.reports-new-body [href="#new-report-step-3"]').on('show.bs.tab', function() {
@ -1093,6 +1163,7 @@ function reportHandsonTableConverter() {
closeOnSelect: true,
selectAppearance: 'simple',
onChange: function() {
$('#new-report-step-2 .project-contents').empty();
$('.continue-button').attr('disabled', false);
}
});
@ -1136,6 +1207,7 @@ function reportHandsonTableConverter() {
});
}
initGenerateButton();
initReportWizard();
initDropdowns();
initTaskContents();

View file

@ -1,4 +1,7 @@
<div>
<%= check_box_tag @name, true %>
<div class="sci-checkbox-container">
<%= check_box_tag @name, true, false, class: 'sci-checkbox' %>
<span class="sci-checkbox-label"></span>
</div>
<%= @label %>
</div>

View file

@ -3,7 +3,10 @@
<ul>
<% @items.each do |key, value| %>
<li>
<%= check_box_tag "#{@name}[]", key %>
<div class="sci-checkbox-container">
<%= check_box_tag "#{@name}[]", key, false ,class: 'sci-checkbox' %>
<span class="sci-checkbox-label"></span>
</div>
<%= value %>
</li>
<% end %>

View file

@ -48,6 +48,7 @@ class Report < ApplicationRecord
table_results: true,
text_results: true,
result_comments: true,
result_order: "atoz",
activities: true
}
}.freeze

View file

@ -53,7 +53,7 @@
<button class="btn btn-primary continue-button" disabled>
<%= t("projects.reports.new.continue_button") %>
</button>
<button class="btn btn-primary generate-button">
<button class="btn btn-primary generate-button" data-create-url="<%= reports_path %>">
<%= t("projects.reports.new.generate_button") %>
</button>
</div>

View file

@ -19,7 +19,7 @@
<ul class="protocol-contents collapse in" id="protocolContents">
<li>
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox" value="protocol_description" <%= 'checked' if report.settings.dig(:task, :protocol, :description) %>/>
<input type="checkbox" class="sci-checkbox protocol-setting" value="description" <%= 'checked' if report.settings.dig(:task, :protocol, :description) %>/>
<span class="sci-checkbox-label"></span>
</span>
<%= t("projects.reports.wizard.third_step.protocol_description") %>
@ -36,7 +36,7 @@
<% %i(completed_steps uncompleted_steps step_checklists step_files step_tables step_comments).each do |step_content| %>
<li>
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox" value="<%= step_content %>" <%= 'checked' if report.settings.dig(:task, :protocol, step_content) %> />
<input type="checkbox" class="sci-checkbox protocol-setting" value="<%= step_content %>" <%= 'checked' if report.settings.dig(:task, :protocol, step_content) %> />
<span class="sci-checkbox-label"></span>
</span>
<%= t("projects.reports.wizard.third_step.#{step_content}") %>
@ -65,7 +65,7 @@
<label>
<%= t("projects.reports.wizard.third_step.order_results") %>
</label>
<select class="order-results">
<select class="order-results" id="taskResultsOrder">
<option value="atoz"><%= t("projects.reports.wizard.third_step.atoz") %></option>
<option value="ztoa"><%= t("projects.reports.wizard.third_step.ztoa") %></option>
<option value="new"><%= t("projects.reports.wizard.third_step.new_results") %></option>
@ -79,14 +79,14 @@
<li>
<div class="file-result-title-container">
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox" value="file_results" <%= 'checked' if report.settings.dig(:task, :file_results) %>/>
<input type="checkbox" class="sci-checkbox task-setting" value="file_results" <%= 'checked' if report.settings.dig(:task, :file_results) %>/>
<span class="sci-checkbox-label"></span>
</span>
<span>
<%= t("projects.reports.wizard.third_step.file_results") %>
<div class="include-pages-container">
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox skip-select-all" value="include_file_pages" <%= 'checked' if report.settings.dig(:task, :file_results_previews) %>/>
<input type="checkbox" class="sci-checkbox task-setting skip-select-all" value="file_results_previews" <%= 'checked' if report.settings.dig(:task, :file_results_previews) %>/>
<span class="sci-checkbox-label"></span>
</span>
<%= t("projects.reports.wizard.third_step.insert_pages_from_pdf") %><br>
@ -99,7 +99,7 @@
</li>
<li>
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox" value="table_results" <%= 'checked' if report.settings.dig(:task, :table_results) %>/>
<input type="checkbox" class="sci-checkbox task-setting " value="table_results" <%= 'checked' if report.settings.dig(:task, :table_results) %>/>
<span class="sci-checkbox-label"></span>
</span>
<%= t("projects.reports.wizard.third_step.table_results") %>
@ -107,7 +107,7 @@
</li>
<li>
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox" value="text_results " <%= 'checked' if report.settings.dig(:task, :text_results) %>/>
<input type="checkbox" class="sci-checkbox task-setting" value="text_results" <%= 'checked' if report.settings.dig(:task, :text_results) %>/>
<span class="sci-checkbox-label"></span>
</span>
<%= t("projects.reports.wizard.third_step.text_results") %>
@ -117,7 +117,7 @@
</li>
<li>
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox" value="result_comments" <%= 'checked' if report.settings.dig(:task, :result_comments) %>/>
<input type="checkbox" class="sci-checkbox task-setting" value="result_comments" <%= 'checked' if report.settings.dig(:task, :result_comments) %>/>
<span class="sci-checkbox-label"></span>
</span>
<%= t("projects.reports.wizard.third_step.results_comments") %>
@ -134,7 +134,7 @@
<li>
<div class="select-all-container">
<span class="sci-checkbox-container">
<input type="checkbox" class="sci-checkbox" value="activities" <%= 'checked' if report.settings.dig(:task, :activities) %>/>
<input type="checkbox" class="sci-checkbox task-setting" value="activities" <%= 'checked' if report.settings.dig(:task, :activities) %>/>
<span class="sci-checkbox-label"></span>
</span>
<%= t("projects.reports.wizard.third_step.task_activity") %>

View file

@ -194,7 +194,7 @@ Rails.application.routes.draw do
via: [:get, :post, :put, :patch]
end
resources :reports, only: [:index, :new] do
resources :reports, only: [:index, :new, :create] do
member do
get :document_preview
end