From d1274442c8324167cc4ab23f0d2fbd3cff797820 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Wed, 27 Mar 2024 14:47:09 -0600 Subject: [PATCH] Fix title sorting within template dropdown Prior to this commit, all of the templates were simply being sorted by title. Now, the sorting follows the instructions specified within the following GitHub issue comment: https://github.com/portagenetwork/roadmap/issues/685#issuecomment-2004404407 --- app/controllers/template_options_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/template_options_controller.rb b/app/controllers/template_options_controller.rb index 61d6f42017..4be0803ea7 100644 --- a/app/controllers/template_options_controller.rb +++ b/app/controllers/template_options_controller.rb @@ -28,7 +28,7 @@ def index if org.present? && !org.new_record? # Load the funder's template(s) minus the default template (that gets swapped # in below if NO other templates are available) - @templates = Template.latest_customizable.where(org_id: funder.id, is_default: false).to_a + @templates = Template.latest_customizable.where(org_id: funder.id, is_default: false).sort_by(&:title).to_a # Swap out any organisational cusotmizations of a funder template @templates = @templates.map do |tmplt| customization = Template.published @@ -47,7 +47,7 @@ def index # If the no funder was specified OR the funder matches the org # if funder.blank? || funder.id == org&.id # Retrieve the Org's templates - @templates << Template.published.organisationally_visible.where(org_id: org.id, customization_of: nil).to_a + @templates << Template.published.organisationally_visible.where(org_id: org.id, customization_of: nil).sort_by(&:title).to_a @templates = @templates.flatten.uniq else # if'No Primary Research Institution' checkbox is checked, @@ -65,7 +65,7 @@ def index # We want the default template to appear at the beggining of the list @templates.unshift(customization) end - @templates = @templates.uniq.sort_by(&:title) + @templates.uniq end # rubocop:enable Metrics/AbcSize, Metrics/MethodLength # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity