From 101d46956c28c0f1e7ef35ecd858567752d36a16 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Fri, 9 Apr 2021 13:19:22 +0200 Subject: [PATCH] Add logic for preparing wizard data for report [SCI-5593] --- app/assets/javascripts/reports/new.js | 92 +++++++++++++++++-- .../reports/checkbox_input_component.html.erb | 5 +- .../multi_checkbox_input_component.html.erb | 5 +- app/models/report.rb | 1 + app/views/reports/new.html.erb | 2 +- app/views/reports/wizard/_third_step.html.erb | 18 ++-- config/routes.rb | 2 +- 7 files changed, 102 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 3e43313a7..34502036c 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -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(); diff --git a/app/components/reports/checkbox_input_component.html.erb b/app/components/reports/checkbox_input_component.html.erb index 5fcb429e6..d52de0c6b 100644 --- a/app/components/reports/checkbox_input_component.html.erb +++ b/app/components/reports/checkbox_input_component.html.erb @@ -1,4 +1,7 @@
- <%= check_box_tag @name, true %> +
+ <%= check_box_tag @name, true, false, class: 'sci-checkbox' %> + +
<%= @label %>
diff --git a/app/components/reports/multi_checkbox_input_component.html.erb b/app/components/reports/multi_checkbox_input_component.html.erb index 2bf1bb9d1..01ba36d2b 100644 --- a/app/components/reports/multi_checkbox_input_component.html.erb +++ b/app/components/reports/multi_checkbox_input_component.html.erb @@ -3,7 +3,10 @@