diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 67289090b..c2d437785 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -975,7 +975,7 @@ function reportHandsonTableConverter() { reportData.report = { name: $('.report-name').val(), description: $('#projectDescription').val(), - settings: { task: { protocol: {} } } + settings: { task: { protocol: {} }, deleted_repositories: [] } }; // Project reportData.project_id = dropdownSelector.getValues('#projectSelector'); @@ -1032,7 +1032,7 @@ function reportHandsonTableConverter() { reportData.project_content.tasks[experimentId].push(parseInt(myModule.value, 10)); }); }); - $.each($('.task-contents-container .repositories-contents .sci-checkbox:checked'), function(i, e) { + $.each($('.task-contents-container .repositories-contents .repositories-setting:checked'), function(i, e) { reportData.project_content.repositories.push(parseInt(e.value, 10)); }); @@ -1046,6 +1046,9 @@ function reportHandsonTableConverter() { $.each($('.task-contents-container .content-element .task-setting'), function(i, e) { reportData.report.settings.task[e.value] = e.checked; }); + $.each($('.task-contents-container .repositories-contents .deleted-repositories-setting:checked'), function(i, e) { + reportData.report.settings.deleted_repositories.push(parseInt(e.value, 10)); + }); reportData.report.settings.task.result_order = dropdownSelector.getValues('#taskResultsOrder'); diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index c287028e8..0abc21d59 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -30,6 +30,7 @@ class ReportsController < ApplicationController before_action :check_manage_permissions, only: BEFORE_ACTION_METHODS before_action :switch_team_with_param, only: :index + before_action :load_repositories, only: %i(new edit) after_action :generate_pdf_report, only: %i(create update generate_pdf) @@ -51,7 +52,6 @@ class ReportsController < ApplicationController # Report grouped by modules def new @templates = Extends::REPORT_TEMPLATES - @repositories = Repository.accessible_by_teams(current_team).active.select(:id, :name).order(:name) @report = current_team.reports.new end @@ -114,7 +114,6 @@ class ReportsController < ApplicationController @edit = true @templates = Extends::REPORT_TEMPLATES @active_template = @report.settings[:template] - @repositories = Repository.accessible_by_teams(current_team).active.select(:id, :name).order(:name) @report.settings = Report::DEFAULT_SETTINGS if @report.settings.blank? @project_contents = { @@ -495,6 +494,16 @@ class ReportsController < ApplicationController include StringUtility AvailableRepository = Struct.new(:id, :name) + def load_repositories + @repositories = Repository.accessible_by_teams(current_team).order(:name) + @deleted_repositories = RepositorySnapshot.where(team: current_team) + .group(:parent_id, :name) + .where.not( + original_repository: Repository.accessible_by_teams(current_team) + ) + .select(:parent_id, :name) + end + def load_vars @report = current_team.reports.find_by(id: params[:id]) render_404 unless @report diff --git a/app/services/report_actions/report_content.rb b/app/services/report_actions/report_content.rb index 47ad7dd50..4ac5e741f 100644 --- a/app/services/report_actions/report_content.rb +++ b/app/services/report_actions/report_content.rb @@ -14,7 +14,7 @@ module ReportActions @report = report @template_values = template_values @repositories = Repository.accessible_by_teams(report.project.team) - .where(id: @content['repositories']).active + .where(id: @content['repositories']) end def save_with_content diff --git a/app/services/reports/docx/draw_my_module.rb b/app/services/reports/docx/draw_my_module.rb index af3f24382..bec2ea5ff 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -88,6 +88,14 @@ module Reports::Docx::DrawMyModule end end + @settings['deleted_repositories']&.each do |repo| + draw_my_module_repository(nil, + my_module, + my_module.repository_snapshots + .where(parent_id: repo) + .find_by(selected: true)) + end + @docx.p subject.children.active.each do |child| public_send("draw_#{child.type_of}", child) diff --git a/app/services/reports/docx/draw_my_module_repository.rb b/app/services/reports/docx/draw_my_module_repository.rb index 2cc8e77ee..c4fa04fe5 100644 --- a/app/services/reports/docx/draw_my_module_repository.rb +++ b/app/services/reports/docx/draw_my_module_repository.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true module Reports::Docx::DrawMyModuleRepository - def draw_my_module_repository(subject) - my_module = subject.my_module - repository = subject.repository - return unless can_read_experiment?(@user, my_module.experiment) && can_read_repository?(@user, repository) + def draw_my_module_repository(subject, my_module = nil, snapshot = nil) + my_module ||= subject&.my_module + repository = subject&.repository + repository = assigned_repository_or_snapshot(my_module, repository&.id, nil, snapshot) + return unless can_read_experiment?(@user, my_module.experiment) && + (can_read_repository?(@user, repository) || repository.is_a?(RepositorySnapshot)) repository_data = my_module.repository_docx_json(repository) diff --git a/app/views/reports/elements/_my_module_element.html.erb b/app/views/reports/elements/_my_module_element.html.erb index 62b181235..f9651be0f 100644 --- a/app/views/reports/elements/_my_module_element.html.erb +++ b/app/views/reports/elements/_my_module_element.html.erb @@ -98,6 +98,10 @@ <%= render partial: 'reports/elements/my_module_result_text_element.html.erb', locals: { result: result, export_all: export_all } %> <% end %> <% end %> + + <% @settings['deleted_repositories']&.each do |repo| %> + <%= render partial: 'reports/elements/my_module_repository_element.html.erb', locals: { repository_snapshot: my_module.repository_snapshots.where(parent_id: repo).find_by(selected: true), export_all: export_all, my_module: my_module } %> + <% end %> <% if defined?(children) %> diff --git a/app/views/reports/elements/_my_module_repository_element.html.erb b/app/views/reports/elements/_my_module_repository_element.html.erb index 7240f1f8a..fa260a3ee 100644 --- a/app/views/reports/elements/_my_module_repository_element.html.erb +++ b/app/views/reports/elements/_my_module_repository_element.html.erb @@ -1,6 +1,7 @@ <% my_module ||= @my_module %> -<% element_id ||= repository&.id %> +<% repository ||= nil %> <% repository_snapshot ||= nil %> +<% element_id ||= repository&.id %> <% repository ||= assigned_repository_or_snapshot(my_module, element_id, repository, repository_snapshot) %> <% timestamp = Time.current + 1.year - 1.days %> <% rows_json = my_module.repository_json_hot(repository, :desc) %> diff --git a/app/views/reports/wizard/_third_step.html.erb b/app/views/reports/wizard/_third_step.html.erb index fd5ac3ad2..153f036f5 100644 --- a/app/views/reports/wizard/_third_step.html.erb +++ b/app/views/reports/wizard/_third_step.html.erb @@ -73,6 +73,24 @@ <%= repository.name %> + <% unless repository.active? %> + + <%= t("projects.reports.wizard.third_step.archived") %> + + <% end %> +
+ + <% end %> + <% @deleted_repositories.each do |repository| %> +