From 763423a9db870da1f5db28d4bdb8f3bef503f3d6 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 8 Dec 2023 12:52:24 +0000 Subject: [PATCH] feat: DRY up routing --- app/helpers/schemes_helper.rb | 8 ++++++++ app/views/organisations/schemes.html.erb | 4 ++-- app/views/schemes/index.html.erb | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb index 8dee3c9be..9cfd20909 100644 --- a/app/helpers/schemes_helper.rb +++ b/app/helpers/schemes_helper.rb @@ -68,6 +68,14 @@ module SchemesHelper end end + def primary_schemes_csv_download_url(download_type) + csv_download_schemes_path(search: @searched, download_type:) + end + + def secondary_schemes_csv_download_url(download_type) + schemes_csv_download_organisation_path(@organisation, search: @searched, download_type:) + end + private ActivePeriod = Struct.new(:from, :to) diff --git a/app/views/organisations/schemes.html.erb b/app/views/organisations/schemes.html.erb index 44f089f55..2f38d78da 100644 --- a/app/views/organisations/schemes.html.erb +++ b/app/views/organisations/schemes.html.erb @@ -28,9 +28,9 @@
<% if current_user.support? %> - <%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count, schemes_csv_download_url: schemes_csv_download_organisation_path(@organisation, search: @searched, download_type: "schemes"), locations_csv_download_url: schemes_csv_download_organisation_path(@organisation, search: @searched, download_type: "locations"), combined_csv_download_url: schemes_csv_download_organisation_path(@organisation, search: @searched, download_type: "combined") } %> + <%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count, schemes_csv_download_url: secondary_schemes_csv_download_url("schemes"), locations_csv_download_url: secondary_schemes_csv_download_url("locations"), combined_csv_download_url: secondary_schemes_csv_download_url("combined") } %> <% else %> - <%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count, schemes_csv_download_url: csv_download_schemes_path(search: @searched, download_type: "schemes"), locations_csv_download_url: csv_download_schemes_path(search: @searched, download_type: "locations"), combined_csv_download_url: csv_download_schemes_path(search: @searched, download_type: "combined") } %> + <%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count, schemes_csv_download_url: primary_schemes_csv_download_url("schemes"), locations_csv_download_url: primary_schemes_csv_download_url("locations"), combined_csv_download_url: primary_schemes_csv_download_url("combined") } %> <% end %> <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "schemes" } %> diff --git a/app/views/schemes/index.html.erb b/app/views/schemes/index.html.erb index 571fac07c..3ee8c802c 100644 --- a/app/views/schemes/index.html.erb +++ b/app/views/schemes/index.html.erb @@ -15,7 +15,7 @@
- <%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count, schemes_csv_download_url: csv_download_schemes_path(search: @searched, download_type: "schemes"), locations_csv_download_url: csv_download_schemes_path(search: @searched, download_type: "locations"), combined_csv_download_url: csv_download_schemes_path(search: @searched, download_type: "combined") } %> + <%= render partial: "schemes/scheme_list", locals: { schemes: @schemes, title:, pagy: @pagy, searched: @searched, item_label:, total_count: @total_count, schemes_csv_download_url: primary_schemes_csv_download_url("schemes"), locations_csv_download_url: primary_schemes_csv_download_url("locations"), combined_csv_download_url: primary_schemes_csv_download_url("combined") } %> <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "schemes" } %>