mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Merge pull request #8046 from andrej-scinote/aj_SCI_11291
Fix generating of reports [SCI-11291][SCI-11292]
This commit is contained in:
commit
969f40bb1d
3 changed files with 26 additions and 16 deletions
|
@ -9,6 +9,7 @@ class ReportsController < ApplicationController
|
|||
before_action :load_vars_nested, only: %i(create edit update generate_pdf
|
||||
generate_docx new_template_values new_docx_template_values project_contents)
|
||||
before_action :load_wizard_vars, only: %i(new edit)
|
||||
before_action :load_repositories_vars, only: %i(new edit create update)
|
||||
before_action :load_available_repositories, only: %i(index save_pdf_to_inventory_modal available_repositories)
|
||||
before_action :check_project_read_permissions, only: %i(create edit update generate_pdf
|
||||
generate_docx new_template_values new_docx_template_values project_contents)
|
||||
|
@ -355,13 +356,6 @@ class ReportsController < ApplicationController
|
|||
def load_wizard_vars
|
||||
@templates = Extends::REPORT_TEMPLATES
|
||||
@docx_templates = Extends::DOCX_REPORT_TEMPLATES
|
||||
live_repositories = Repository.viewable_by_user(current_user).sort_by { |r| r.name.downcase }
|
||||
snapshots_of_deleted = RepositorySnapshot.left_outer_joins(:original_repository)
|
||||
.where(team: current_team)
|
||||
.where.not(original_repository: live_repositories)
|
||||
.select('DISTINCT ON ("repositories"."parent_id") "repositories".*')
|
||||
.sort_by { |r| r.name.downcase }
|
||||
@repositories = live_repositories + snapshots_of_deleted
|
||||
@visible_projects = current_team.projects
|
||||
.active
|
||||
.joins(experiments: :my_modules)
|
||||
|
@ -375,6 +369,16 @@ class ReportsController < ApplicationController
|
|||
@default_docx_template = Extends::DOCX_REPORT_TEMPLATES.keys.first.to_s if Extends::DOCX_REPORT_TEMPLATES.one? && custom_templates(Extends::DOCX_REPORT_TEMPLATES)
|
||||
end
|
||||
|
||||
def load_repositories_vars
|
||||
live_repositories = Repository.viewable_by_user(current_user).sort_by { |r| r.name.downcase }
|
||||
snapshots_of_deleted = RepositorySnapshot.left_outer_joins(:original_repository)
|
||||
.where(team: current_team)
|
||||
.where.not(original_repository: live_repositories)
|
||||
.select('DISTINCT ON ("repositories"."parent_id") "repositories".*')
|
||||
.sort_by { |r| r.name.downcase }
|
||||
@repositories = live_repositories + snapshots_of_deleted
|
||||
end
|
||||
|
||||
def check_project_read_permissions
|
||||
render_403 unless can_read_project?(@project)
|
||||
end
|
||||
|
@ -407,7 +411,7 @@ class ReportsController < ApplicationController
|
|||
|
||||
def report_params
|
||||
params.require(:report)
|
||||
.permit(:name, :description, :grouped_by, :report_contents, settings: permit_report_settings_structure(Report::DEFAULT_SETTINGS))
|
||||
.permit(:name, :description, :grouped_by, :report_contents, settings: permit_report_settings_structure(Report::DEFAULT_SETTINGS, @repositories))
|
||||
end
|
||||
|
||||
def search_params
|
||||
|
|
|
@ -107,11 +107,14 @@ module ReportsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def permit_report_settings_structure(settings_definition)
|
||||
def permit_report_settings_structure(settings_definition, repositories)
|
||||
settings_definition.each_with_object([]) do |(key, value), permitted|
|
||||
permitted << case value
|
||||
permitted << if key == :excluded_repository_columns && repositories.present?
|
||||
{ key => repositories.each_with_object({}) { |repository, hash| hash[repository.id.to_s] = [] } }
|
||||
else
|
||||
case value
|
||||
when Hash
|
||||
{ key => permit_report_settings_structure(value) }
|
||||
{ key => permit_report_settings_structure(value, repositories) }
|
||||
when Array
|
||||
{ key => [] }
|
||||
else
|
||||
|
@ -119,6 +122,7 @@ module ReportsHelper
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def custom_templates(templates)
|
||||
templates.any? { |template, _| template != :scinote_template }
|
||||
|
|
|
@ -66,7 +66,9 @@ class Report < ApplicationRecord
|
|||
activities: true,
|
||||
repositories: [],
|
||||
excluded_repository_columns: {}
|
||||
}
|
||||
},
|
||||
template: 'scinote_template',
|
||||
docx_template: 'scinote_template'
|
||||
}.freeze
|
||||
|
||||
def self.search(
|
||||
|
|
Loading…
Reference in a new issue