Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ordering of Templates Within Create Plan Template Dropdown #706

Merged
merged 5 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading