Skip to content

Commit

Permalink
Update match progress report to handle duplicate program names
Browse files Browse the repository at this point in the history
  • Loading branch information
eanders committed Dec 23, 2024
1 parent 17c1139 commit 9c80115
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions app/controllers/reports/match_progress_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/views/reports/match_progress/index.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 9c80115

Please sign in to comment.