From 9c80115e5c07d80fbdec551efb9dd3829852c961 Mon Sep 17 00:00:00 2001 From: Elliot Anders Date: Mon, 23 Dec 2024 15:10:21 -0500 Subject: [PATCH] Update match progress report to handle duplicate program names --- .../reports/match_progress_controller.rb | 26 ++++++++++++------- .../reports/match_progress/index.xlsx.axlsx | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/controllers/reports/match_progress_controller.rb b/app/controllers/reports/match_progress_controller.rb index 65af0389b..267976a27 100644 --- a/app/controllers/reports/match_progress_controller.rb +++ b/app/controllers/reports/match_progress_controller.rb @@ -19,7 +19,7 @@ def index respond_to do |format| format.html {} format.xlsx do - @included_sub_programs = sub_program_list.invert.slice(*report_params[:sub_programs]) + @included_sub_programs = sub_program_list.select { |sp| sp.last.in?(report_params[:sub_programs]) } filename = 'CAS Match Progress.xlsx' render xlsx: 'index', filename: filename end @@ -85,20 +85,26 @@ def step_names(sub_program_id) def sub_programs @sub_programs ||= SubProgram. - joins(:program). - preload(:program). - pluck(p_t[:name], sp_t[:name], :id). - sort + joins(:program, :match_route). + preload(:program, :match_route). + order(p_t[:name].asc, sp_t[:name].asc, id: :asc). + map do |sp| + { + program: sp.program.name, + sub_program: sp.name, + route: sp.match_route.title, + id: sp.id, + } + end end - helper_method :sub_programs def sub_program_list - @sub_program_list ||= sub_programs.map do |project_name, sub_project_name, id| + @sub_program_list ||= sub_programs.map do |sp| [ - [project_name, sub_project_name].join('|'), - id, + [sp[:program], sp[:sub_program], sp[:route]].compact_blank.join('|'), + sp[:id], ] - end.to_h + end.uniq end helper_method :sub_program_list diff --git a/app/views/reports/match_progress/index.xlsx.axlsx b/app/views/reports/match_progress/index.xlsx.axlsx index b9d69c204..2f5866b27 100644 --- a/app/views/reports/match_progress/index.xlsx.axlsx +++ b/app/views/reports/match_progress/index.xlsx.axlsx @@ -1,6 +1,6 @@ wb = xlsx_package.workbook -@included_sub_programs.each.with_index do |(sub_program_id, sub_program_name), i| +@included_sub_programs.each.with_index do |(sub_program_name, sub_program_id), i| wb.add_worksheet(name: "#{sub_program_name[0..(30 - i.to_s.length)].gsub(/['\*\/\\\?\[\]\:]/, '-')}#{i}") do |sheet| steps = step_names(sub_program_id) shown_steps = (2..steps.count - 1)