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

Handle Ordering of Templates When "No research organization" Box is Checked #718

Merged
merged 3 commits into from
Apr 11, 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: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

- 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)
- Fixed ordering of templates within the "Create a new plan" template dropdown [#706](https://github.com/portagenetwork/roadmap/pull/706) and [#718](https://github.com/portagenetwork/roadmap/pull/718)

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

Expand Down
6 changes: 4 additions & 2 deletions app/controllers/template_options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ def index
# Retrieve the Org's templates
@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,
# only show publicly available template without customization
@templates = Template.published.publicly_visible.where(org_id: funder.id, customization_of: nil)
@templates << Template.default if Template.default.present?
@templates << Template.published.publicly_visible.where(org_id: funder.id, customization_of: nil,
is_default: false).sort_by(&:title).to_a
end
@templates = @templates.flatten
Copy link
Collaborator Author

@aaronskiba aaronskiba Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would've called @templates = @templates.flatten.uniq at the end of the else block. But because it already exists in the if block as well, I just moved it outside of the blocks to avoid redundancy (and the rubocop offense).

I also changed @templates = @templates.flatten.uniq to @templates = @templates.flatten. @templates = @templates.uniq gets called at the end of the controller action, so calling .uniq again on line 57 would have been redundant.

# DMP Assistant: We do not want to include not customized templates from default funder
# Include customizable funder templates
# @templates << funder_templates = Template.latest_customizable
Expand Down
Loading