Skip to content

Commit

Permalink
Fix title sorting within template dropdown
Browse files Browse the repository at this point in the history
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: #685 (comment)
  • Loading branch information
aaronskiba committed Mar 27, 2024
1 parent 75192b2 commit 751fa02
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions app/controllers/template_options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -63,9 +63,8 @@ def index
customization ||= Template.default
@templates.select! { |t| t.id != Template.default.id && t.id != customization.id }
# We want the default template to appear at the beggining of the list
@templates.unshift(customization)
@templates.unshift(customization).uniq
end
@templates = @templates.uniq.sort_by(&:title)
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Expand Down

0 comments on commit 751fa02

Please sign in to comment.