Skip to content

Commit

Permalink
Merge pull request #706 from portagenetwork/aaron/issues/685
Browse files Browse the repository at this point in the history
Fix Ordering of Templates Within Create Plan Template Dropdown
  • Loading branch information
aaronskiba authored Apr 8, 2024
2 parents 0687420 + 0cc44e4 commit 280d8f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

- Edit Gemfile config for 'rollbar' to enable app tracking on rollbar.com [#687](https://github.com/portagenetwork/roadmap/pull/687)

- Fxed ordering of templates within the "Create a new plan" template dropdown [#706](https://github.com/portagenetwork/roadmap/pull/706)

## [4.0.2+portage-4.0.0] - 2024-02-01

### Added
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/template_options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ def index

org = org_from_params(params_in: { org_id: org_hash.to_json }) if org_hash.present?
funder = Org.find_by(name: Rails.application.config.default_funder_name)
# funder = org_from_params(params_in: { org_id: funder_hash.to_json }) if funder_hash.present?

@templates = []

return unless (org.present? && !org.new_record?) || (funder.present? && !funder.new_record?)
return unless funder.present? && !funder.new_record?

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 +45,8 @@ 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 @@ -65,7 +64,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 = @templates.uniq
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Expand Down

0 comments on commit 280d8f6

Please sign in to comment.