mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Add settings to reports [SCI-5612]
This commit is contained in:
parent
16da4394a2
commit
67302da968
|
@ -981,6 +981,12 @@ function reportHandsonTableConverter() {
|
|||
$('.reports-new-footer').attr('data-step', currentStep - 1);
|
||||
}
|
||||
|
||||
function allCheckboxesSelected(container) {
|
||||
let checked = container.find('.sci-checkbox:not(.skip-select-all):checked');
|
||||
let all = container.find('.sci-checkbox:not(.skip-select-all)');
|
||||
return checked.length === all.length;
|
||||
}
|
||||
|
||||
$('.continue-button').on('click', function() {
|
||||
nextStep();
|
||||
});
|
||||
|
@ -991,14 +997,23 @@ function reportHandsonTableConverter() {
|
|||
|
||||
$('.reports-new-body [href="#new-report-step-2"]').on('show.bs.tab', function() {
|
||||
var projectId = dropdownSelector.getValues('#projectSelector');
|
||||
var containerStep2 = $('#new-report-step-2');
|
||||
var projectContents = $('#new-report-step-2').find('.project-contents');
|
||||
animateSpinner('.reports-new-body');
|
||||
$.get(containerStep2.data('project-content-url'), { project_id: projectId }, function(data) {
|
||||
$.get(projectContents.data('project-content-url'), { project_id: projectId }, function(data) {
|
||||
animateSpinner('.reports-new-body', false);
|
||||
containerStep2.html(data.html);
|
||||
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() {
|
||||
$('.protocol-steps-checkbox').prop('checked', allCheckboxesSelected($('.report-protocol-settings')));
|
||||
$('.all-results-checkbox').prop('checked', allCheckboxesSelected($('.report-result-settings')));
|
||||
$('.select-all-task-contents').prop('checked', allCheckboxesSelected($('.report-task-settings')));
|
||||
});
|
||||
}
|
||||
|
||||
function initProjectContents() {
|
||||
|
|
|
@ -49,6 +49,7 @@ class ReportsController < ApplicationController
|
|||
# Report grouped by modules
|
||||
def new
|
||||
@templates = Extends::REPORT_TEMPLATES
|
||||
@report = current_team.reports.new
|
||||
end
|
||||
|
||||
def new_template_values
|
||||
|
@ -343,7 +344,7 @@ class ReportsController < ApplicationController
|
|||
def project_contents
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'reports/wizard/second_step.html.erb',
|
||||
partial: 'reports/wizard/project_contents.html.erb',
|
||||
locals: { project: @project }
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,22 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module SettingsModel
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
@@default_settings = HashWithIndifferentAccess.new
|
||||
|
||||
included do
|
||||
serialize :settings, JsonbHashSerializer
|
||||
after_initialize :init_default_settings, if: :new_record?
|
||||
end
|
||||
|
||||
class_methods do
|
||||
def default_settings(dfs)
|
||||
@@default_settings.merge!(dfs)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def init_default_settings
|
||||
self.settings = @@default_settings
|
||||
self.settings = self.class::DEFAULT_SETTINGS
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Report < ApplicationRecord
|
||||
include SettingsModel
|
||||
include SearchableModel
|
||||
include SearchableByNameModel
|
||||
|
||||
|
@ -30,6 +31,27 @@ class Report < ApplicationRecord
|
|||
# or many module elements (if grouped by module)
|
||||
has_many :report_elements, inverse_of: :report, dependent: :delete_all
|
||||
|
||||
DEFAULT_SETTINGS = {
|
||||
all_tasks: true,
|
||||
task: {
|
||||
protocol: {
|
||||
description: true,
|
||||
completed_steps: true,
|
||||
uncompleted_steps: true,
|
||||
step_checklists: true,
|
||||
step_files: true,
|
||||
step_tables: true,
|
||||
step_comments: true
|
||||
},
|
||||
file_results: false,
|
||||
file_results_previews: false,
|
||||
table_results: true,
|
||||
text_results: true,
|
||||
result_comments: true,
|
||||
activities: true
|
||||
}
|
||||
}.freeze
|
||||
|
||||
def self.search(
|
||||
user,
|
||||
include_archived,
|
||||
|
|
|
@ -34,7 +34,7 @@ class User < ApplicationRecord
|
|||
|
||||
store_accessor :settings, :time_zone, :notifications_settings
|
||||
|
||||
default_settings(
|
||||
DEFAULT_SETTINGS = {
|
||||
time_zone: 'UTC',
|
||||
date_format: Constants::DEFAULT_DATE_FORMAT,
|
||||
notifications_settings: {
|
||||
|
@ -44,7 +44,7 @@ class User < ApplicationRecord
|
|||
recent_email: false,
|
||||
system_message_email: false
|
||||
}
|
||||
)
|
||||
}.freeze
|
||||
|
||||
store_accessor :variables, :export_vars
|
||||
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
<div role="tabpanel" class="tab-pane active" id="new-report-step-1">
|
||||
<%= render partial: 'reports/wizard/first_step' %>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="new-report-step-2" data-project-content-url="<%= project_contents_reports_path %>">
|
||||
<div role="tabpanel" class="tab-pane" id="new-report-step-2">
|
||||
<%= render partial: 'reports/wizard/second_step', locals: { report: @report } %>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="new-report-step-3">
|
||||
<%= render partial: 'reports/wizard/third_step' %>
|
||||
<%= render partial: 'reports/wizard/third_step', locals: { report: @report } %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
36
app/views/reports/wizard/_project_contents.html.erb
Normal file
36
app/views/reports/wizard/_project_contents.html.erb
Normal file
|
@ -0,0 +1,36 @@
|
|||
<ul>
|
||||
<% project.experiments.includes(:my_modules).active.each do |experiment| %>
|
||||
<li class="experiment-element">
|
||||
<div class="experiment-block">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" value="<%= experiment.id %>" class="sci-checkbox report-experiment-checkbox"/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<i class="fas fa-caret-down " data-toggle="collapse" href="#experimentContentContainer<%= experiment.id %>" aria-expanded="false"></i>
|
||||
<span class="experiment-name">
|
||||
<%= experiment.name %>
|
||||
</span>
|
||||
<div class="move-buttons sci-btn-group">
|
||||
<button class="btn btn-light icon-btn move-up">
|
||||
<i class="fas fa-arrow-up"></i>
|
||||
</button>
|
||||
<button class="btn btn-light icon-btn move-down">
|
||||
<i class="fas fa-arrow-down"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="experiment-contents collapse in" id="experimentContentContainer<%= experiment.id %>">
|
||||
<% experiment.my_modules.active.each do |my_module| %>
|
||||
<li class="experiment-my-module">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" value="<%= my_module.id %>" class="sci-checkbox report-my-module-checkbox"/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<%= my_module.name %>
|
||||
<i class="fas fa-grip-vertical"></i>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
|
@ -23,46 +23,11 @@
|
|||
</div>
|
||||
<div class="select-all-my-modules">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" class="sci-checkbox select-all-my-modules-checkbox" checked/>
|
||||
<input type="checkbox" class="sci-checkbox select-all-my-modules-checkbox" <%= 'checked' if report.settings.dig(:all_tasks) %>/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<%= t("projects.reports.wizard.second_step.select_all_tasks") %>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<ul>
|
||||
<% project.experiments.includes(:my_modules).active.each do |experiment| %>
|
||||
<li class="experiment-element">
|
||||
<div class="experiment-block">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" value="<%= experiment.id %>" class="sci-checkbox report-experiment-checkbox" checked/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<i class="fas fa-caret-down " data-toggle="collapse" href="#experimentContentContainer<%= experiment.id %>" aria-expanded="false"></i>
|
||||
<span class="experiment-name">
|
||||
<%= experiment.name %>
|
||||
</span>
|
||||
<div class="move-buttons sci-btn-group">
|
||||
<button class="btn btn-light icon-btn move-up">
|
||||
<i class="fas fa-arrow-up"></i>
|
||||
</button>
|
||||
<button class="btn btn-light icon-btn move-down">
|
||||
<i class="fas fa-arrow-down"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="experiment-contents collapse in" id="experimentContentContainer<%= experiment.id %>">
|
||||
<% experiment.my_modules.active.each do |my_module| %>
|
||||
<li class="experiment-my-module">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" value="<%= my_module.id %>" class="sci-checkbox report-my-module-checkbox" checked/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<%= my_module.name %>
|
||||
<i class="fas fa-grip-vertical"></i>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<div class="project-contents" data-project-content-url="<%= project_contents_reports_path %>"></div>
|
||||
</div>
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
</div>
|
||||
<div class="select-all-container">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" class="sci-checkbox select-all-task-contents" checked/>
|
||||
<input type="checkbox" class="sci-checkbox select-all-task-contents"/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<%= t("projects.reports.wizard.third_step.select_all") %>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<ul>
|
||||
<ul class="report-task-settings">
|
||||
<li class="content-element">
|
||||
<i class="fas fa-caret-down " data-toggle="collapse" href="#protocolContents" aria-expanded="false"></i>
|
||||
<span class="content-element-title">
|
||||
|
@ -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/>
|
||||
<input type="checkbox" class="sci-checkbox" value="protocol_description" <%= 'checked' if report.settings.dig(:task, :protocol, :description) %>/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<%= t("projects.reports.wizard.third_step.protocol_description") %>
|
||||
|
@ -27,16 +27,16 @@
|
|||
</li>
|
||||
<li>
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" class="sci-checkbox protocol-steps-checkbox" value="protocol_steps" checked/>
|
||||
<input type="checkbox" class="sci-checkbox protocol-steps-checkbox" value="protocol_steps"/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<%= t("projects.reports.wizard.third_step.protocol_step") %>
|
||||
<div class="divider"></div>
|
||||
<ul class="step-contents">
|
||||
<% ['completed_steps', 'uncompleted_steps', 'step_checklists', 'step_files', 'step_tables', 'step_comments'].each do |step_content| %>
|
||||
<ul class="step-contents report-protocol-settings">
|
||||
<% %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/>
|
||||
<input type="checkbox" class="sci-checkbox" 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}") %>
|
||||
|
@ -56,7 +56,7 @@
|
|||
<li>
|
||||
<div class="all-results-container">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" class="sci-checkbox all-results-checkbox" value="all_results" checked/>
|
||||
<input type="checkbox" class="sci-checkbox all-results-checkbox" value="all_results"/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<span>
|
||||
|
@ -75,18 +75,18 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<ul class="results-type-contents">
|
||||
<ul class="results-type-contents report-result-settings">
|
||||
<li>
|
||||
<div class="file-result-title-container">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox" class="sci-checkbox" value="file_results" checked/>
|
||||
<input type="checkbox" class="sci-checkbox" 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"/>
|
||||
<input type="checkbox" class="sci-checkbox skip-select-all" value="include_file_pages" <%= '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/>
|
||||
<input type="checkbox" class="sci-checkbox" 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/>
|
||||
<input type="checkbox" class="sci-checkbox" 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="all_results" checked/>
|
||||
<input type="checkbox" class="sci-checkbox" 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="task_activity" checked/>
|
||||
<input type="checkbox" class="sci-checkbox" value="activities" <%= 'checked' if report.settings.dig(:task, :activities) %>/>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<%= t("projects.reports.wizard.third_step.task_activity") %>
|
||||
|
|
7
db/migrate/20210407143303_add_settings_to_reports.rb
Normal file
7
db/migrate/20210407143303_add_settings_to_reports.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddSettingsToReports < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :reports, :settings, :jsonb, default: {}, null: false
|
||||
end
|
||||
end
|
|
@ -1308,7 +1308,8 @@ CREATE TABLE public.reports (
|
|||
last_modified_by_id bigint,
|
||||
team_id bigint,
|
||||
pdf_file_processing boolean DEFAULT false,
|
||||
docx_file_processing boolean DEFAULT false
|
||||
docx_file_processing boolean DEFAULT false,
|
||||
settings jsonb DEFAULT '{}'::jsonb NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
@ -7231,6 +7232,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20210128105458'),
|
||||
('20210217114042'),
|
||||
('20210312185911'),
|
||||
('20210325152257');
|
||||
('20210325152257'),
|
||||
('20210407143303');
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue