diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 98023b3f0..bcc8ad5d3 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -968,6 +968,16 @@ function reportHandsonTableConverter() { } (function() { + function getSelectedRepositoryColumnValues(element, selectedAll = false) { + const values = []; + $(element).find('option').each((_, option) => { + if ($(option).attr('selected-value') || selectedAll) { + values.push(option.value); + } + }); + return values; + } + function getReportData() { var reportData = {}; @@ -1046,8 +1056,17 @@ function reportHandsonTableConverter() { reportData.report.settings.task[e.value] = e.checked; }); reportData.report.settings.task.repositories = []; - $.each($('.task-contents-container .repositories-contents .repositories-setting:checked'), function(i, e) { - reportData.report.settings.task.repositories.push(parseInt(e.value, 10)); + reportData.report.settings.task.excluded_repository_columns = {}; + + $.each($('.task-contents-container .repositories-contents .repositories-setting:checked'), (_, e) => { + const value = parseInt(e.value, 10); + const $repositoryColumn = $(e).parent().siblings('.repository-columns')[0]; + const selectedValues = dropdownSelector.getValues($repositoryColumn); + const excludedValues = getSelectedRepositoryColumnValues($repositoryColumn, true) + .filter((item) => !selectedValues.includes(item)) + .map((el) => parseInt(el, 10)); + reportData.report.settings.task.repositories.push(value); + reportData.report.settings.task.excluded_repository_columns[value] = excludedValues; }); reportData.report.settings.task.result_order = dropdownSelector.getValues('#taskResultsOrder'); @@ -1359,6 +1378,20 @@ function reportHandsonTableConverter() { if (dropdownSelector.getValues('#docxTemplateSelector').length > 0) { loadDocxTemplate(); } + + $('.repository-columns').each((_, element) => { + const elementId = `#${$(element).attr('id')}`; + const elements = getSelectedRepositoryColumnValues(elementId); + + dropdownSelector.init(elementId, { + selectAppearance: 'simple', + optionClass: 'checkbox-icon' + }); + + if (elements.length) { + dropdownSelector.selectValues(elementId, elements); + } + }); } function loadTemplate() { diff --git a/app/assets/stylesheets/reports/new.scss b/app/assets/stylesheets/reports/new.scss index b5258df6e..8b50742d8 100644 --- a/app/assets/stylesheets/reports/new.scss +++ b/app/assets/stylesheets/reports/new.scss @@ -260,6 +260,15 @@ } // scss-lint:enable ImportantRule + .repositories-contents { + .dropdown-selector-container { + display: inline-flex; + flex-shrink: 0; + margin-left: auto; + width: 200px; + } + } + .project-selector-container { background: $color-white; box-shadow: $modal-shadow; diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 36b7578ff..bca3c406e 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -391,17 +391,17 @@ class MyModule < ApplicationRecord { data: data, headers: headers } end - def repository_docx_json(repository) - headers = [ - I18n.t('repositories.table.id'), - I18n.t('repositories.table.row_name'), - I18n.t('repositories.table.added_on'), - I18n.t('repositories.table.added_by') - ] + def repository_docx_json(repository, excluded_columns) + headers = Report.default_repository_columns.filter_map do |key, value| + value unless excluded_columns.include?(key.to_s.to_i) + end + custom_columns = [] return false unless repository repository.repository_columns.order(:id).each do |column| + next if excluded_columns.include?(column.id) + if column.data_type == 'RepositoryStockValue' if repository.has_stock_consumption? headers.push(I18n.t('repositories.table.row_consumption')) @@ -416,7 +416,7 @@ class MyModule < ApplicationRecord records = repository.assigned_rows(self) .select(:id, :name, :created_at, :created_by_id, :repository_id, :parent_id, :archived) - { headers: headers, rows: records, custom_columns: custom_columns } + { headers: headers, rows: records, custom_columns: custom_columns, excluded_columns: excluded_columns } end def deep_clone(current_user) diff --git a/app/models/report.rb b/app/models/report.rb index 2d9a85908..61f092e33 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -64,7 +64,8 @@ class Report < ApplicationRecord result_comments: true, result_order: 'new', activities: true, - repositories: [] + repositories: [], + excluded_repository_columns: {} } }.freeze @@ -126,4 +127,13 @@ class Report < ApplicationRecord ReportActions::ReportContent.new(report, content, {}, current_user).save_with_content report end + + def self.default_repository_columns + { + '-1': I18n.t('repositories.table.id'), + '-2': I18n.t('repositories.table.row_name'), + '-3': I18n.t('repositories.table.added_on'), + '-4': I18n.t('repositories.table.added_by') + } + end end diff --git a/app/services/reports/docx/draw_my_module_repository.rb b/app/services/reports/docx/draw_my_module_repository.rb index e6560c46e..a82b44b40 100644 --- a/app/services/reports/docx/draw_my_module_repository.rb +++ b/app/services/reports/docx/draw_my_module_repository.rb @@ -5,11 +5,12 @@ module Reports::Docx::DrawMyModuleRepository my_module = subject.my_module repository = subject.repository repository = assigned_repository_or_snapshot(my_module, repository) + excluded_repository_columns = @settings.dig(:task, :excluded_repository_columns, repository.id.to_s) || {} return unless repository && can_read_experiment?(@user, my_module.experiment) && (repository.is_a?(RepositorySnapshot) || can_read_repository?(@user, repository)) - repository_data = my_module.repository_docx_json(repository) + repository_data = my_module.repository_docx_json(repository, excluded_repository_columns) return false unless repository_data[:rows].any? && can_read_repository?(@user, repository) diff --git a/app/services/reports/docx/repository_helper.rb b/app/services/reports/docx/repository_helper.rb index 50b693891..d962fd97d 100644 --- a/app/services/reports/docx/repository_helper.rb +++ b/app/services/reports/docx/repository_helper.rb @@ -6,12 +6,16 @@ module Reports::Docx::RepositoryHelper def prepare_row_columns(repository_data, my_module = nil, repository = nil) result = [repository_data[:headers]] + excluded_columns = repository_data[:excluded_columns] + repository_data[:rows].each do |record| row = [] - row.push(record.code) - row.push(escape_input(record.archived ? "#{record.name} [#{I18n.t('general.archived')}]" : record.name)) - row.push(I18n.l(record.created_at, format: :full)) - row.push(escape_input(record.created_by.full_name)) + row.push(record.code) unless excluded_columns.include?(-1) + unless excluded_columns.include?(-2) + row.push(escape_input(record.archived ? "#{record.name} [#{I18n.t('general.archived')}]" : record.name)) + end + row.push(I18n.l(record.created_at, format: :full)) unless excluded_columns.include?(-3) + row.push(escape_input(record.created_by.full_name)) unless excluded_columns.include?(-4) cell_values = {} custom_cells = record.repository_cells @@ -38,6 +42,8 @@ module Reports::Docx::RepositoryHelper end repository_data[:custom_columns].each do |column_id| + next if excluded_columns.include?(column_id) + value = cell_values[column_id] row.push(value) end diff --git a/app/views/reports/wizard/_third_step.html.erb b/app/views/reports/wizard/_third_step.html.erb index 327c1d857..2cbf865db 100644 --- a/app/views/reports/wizard/_third_step.html.erb +++ b/app/views/reports/wizard/_third_step.html.erb @@ -55,7 +55,10 @@
- <%= t("projects.reports.wizard.third_step.assigned_items_description") %> +
+

<%= t("projects.reports.wizard.third_step.assigned_items_description") %>

+

<%= t("projects.reports.wizard.third_step.assigned_items_repository_items_description_html") %>

+