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

Update to answers and plans controllers and added an index to the set… #3428

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 21 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Changelog

Performance improvements
- Update ActiveRecord query on the answers_controller so that it stops performing a `select * from answers where question id in (???)` and instead uses `select * from answers where question id in (???) AND plan_id = ?`.
- Add an index to the `settings` table. This table is written to every time someone downloads their plan, and is read each time the download page is loaded.
- Update ActiveRecord query on the plans_controller's download action so that it `includes` settings


## v4.2.0

**Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.**
**Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.**

Note that this will have a significant impact on any scss and html customizations you may have made to your fork of this project.
Note that this will have a significant impact on any scss and html customizations you may have made to your fork of this project.

The following links will be helpful:

Expand All @@ -17,9 +23,9 @@ The following links will be helpful:
[What happened to $grid-float-breakpoint in Bootstrap 4. And screen size breakpoint shift from 3 -> 4](
https://bibwild.wordpress.com/2019/06/10/what-happened-to-grid-float-breakpoint-in-bootstrap-4-and-screen-size-breakpoint-shift-from-3-4/)<br>
[What are media queries in Bootstrap 4?](https://www.educative.io/answers/what-are-media-queries-in-bootstrap-4)<br>

### Key changes

- Node package changes:
* Changed version of `bootstrap "^3.4.1"` --> `"^5.2.3"`
* Added `@popperjs/core.`
Expand All @@ -37,7 +43,7 @@ https://bibwild.wordpress.com/2019/06/10/what-happened-to-grid-float-breakpoint-
+ `@use "../../../../node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss" as * ;`<br>
with <br>
`@use "../../../../node_modules/bootstrap/scss/bootstrap" as *;`
+ Enclosed all division calculations using symbol `/` with `calc()` function,<br>
+ Enclosed all division calculations using symbol `/` with `calc()` function,<br>
e.g., replaced<br>
`padding-right: $grid-gutter-width / 2;`<br>
with<br>
Expand All @@ -46,7 +52,7 @@ https://bibwild.wordpress.com/2019/06/10/what-happened-to-grid-float-breakpoint-
- `@media (max-width: $grid-float-breakpoint-max) {}`<br>
with<br>
`@include media-breakpoint-down(md){}`

- `@media (max-width: $grid-float-breakpoint-max) {}`<br>
with<br>
`@include media-breakpoint-down(md) {}`
Expand All @@ -67,7 +73,7 @@ When we use a native DOM element in Javascript, we obtain it by applying get() t
We sometimes use the button native Dom element to programmatically click, as the Jquery button element with trigger('click') won't work because the trigger() function cannot be used to mimic native browser events, such as clicking (cf., https://learn.jquery.com/events/triggering-event-handlers/ )

+ Accordion & spinners
- Bespoke versions replaced by Bootstrap 5 accordion and spinner now.
- Bespoke versions replaced by Bootstrap 5 accordion and spinner now.
- Accordion
* Changed the default Bootstrap arrow icon for the accordion to use the fontawesome icons plus and minus icons. Created a several accordion specific colour variables:
<br>// Accordion colors
Expand All @@ -83,7 +89,7 @@ We sometimes use the button native Dom element to programmatically click, as the
- Bootstrap dropped `btn-block` class for utilities. So we removed any styling using it.
- Close Buttons: Renamed `close` to`btn-close`.
- Renamed `btn-default` to `btn-secondary` and variable `$btn-default-color` changed to `$btn-secondary-color`.
+ Dropdowns
+ Dropdowns
- Dropdown list items with class `dropdown` have class `dropdown-item` added usually with`px-3` for positioning.
- Added new `dropdown-menu-dark` variant and associated variables for on-demand dark dropdowns.
- Data attributes changes required by Bootstrap 5 (as used by accordion and dropdown buttons):
Expand All @@ -92,7 +98,7 @@ We sometimes use the button native Dom element to programmatically click, as the
* `data-target` --> `data-bs-target`
* `data-toggle` --> `data-bs-toggle`
- Bootstrap 5 Popover added to some dropdown-menu items by adding attribute `data-bs-toggle="popover"`
+ Form
+ Form
- `form-group` class replaced with `form-control`.
- Form labels now require `form-label` or `form-check-label` to go with `form-control` and `form-check` respectively. So all obsolete `control-label` replaced by `form-label` and missing ones added.
- Dropped form-specific layout classes for our grid system. Use Bootstrap grid and utilities instead of `form-group`, `form-row`, or `form-inline`.
Expand All @@ -119,7 +125,7 @@ We sometimes use the button native Dom element to programmatically click, as the
- Bootstrap rewrote component with flexbox. Dropped nearly all > selectors for simpler styling via un-nested classes.
Instead of HTML-specific selectors like .nav > li > a, we use separate classes for `navs, nav-items, and nav-links`. (Note because the `nav-link` class has not always been added as it comes with styles not appropriate for our styling for links.)
This makes your HTML more flexible while bringing along increased extensibility. So we have dropped HTML-specific selectors and css in `_navs.scss`
e.g.,
e.g.,
<br>`.nav-tabs > li > a:hover` --> `nav-tabs nav-link:hover`,
<br>`.nav-pills > li > a:hover` -->`nav-pills .nav-link:hover`.
- Pages with css classes `nav` and`navbar` updated to work with Bootstrap 5. So `app/assets/stylesheets/blocks/_navbars.scss` and `app/assets/stylesheets/blocks/_navs.scss` updated.
Expand All @@ -131,8 +137,8 @@ We sometimes use the button native Dom element to programmatically click, as the
+ Notifications
- Notifications now use classes `d-block` and `d-none` to show and hide respectively.
+ Panels, thumbnails & wells (replacements)
- Bootstrap 5 dropped panels, thumbnails and wells. So pages with them updated with Bootstrap 5 replacements.
* All views with css classes`panel, panel-body, panel-*` Have panel replaced by card to give `card, card_body, card-*`, etc.
- Bootstrap 5 dropped panels, thumbnails and wells. So pages with them updated with Bootstrap 5 replacements.
* All views with css classes`panel, panel-body, panel-*` Have panel replaced by card to give `card, card_body, card-*`, etc.
* As `panel-default` and some otherpanel css classes don't have card equivalents with same suffixes we have added these classes temporarily in `_cards.sccs`, e.g.,`.card-default`, etc.
+ Utilities
- Bootstrap renamed several utilities to use logical property names instead of directional names with the addition of RTL support:
Expand All @@ -147,9 +153,9 @@ We sometimes use the button native Dom element to programmatically click, as the
* As Bootstrap 5.2 dropped class `text-justify` we have created a custom version based on comment https://github.com/twbs/bootstrap/pull/29793#issuecomment-1814683346
* `text-*` utilities do not add hover and focus states to links anymore. `link-*` helper classes can be used instead.

### Fixed
- Fixed rubocop errors after Bootstrap upgrade
- Fixed RSpec tests after Bootstrap upgrade
### Fixed
- Fixed rubocop errors after Bootstrap upgrade
- Fixed RSpec tests after Bootstrap upgrade
- Fix "undefined" Tooltip Messages [#3364](https://github.com/DMPRoadmap/roadmap/pull/3364)
- Fixed rubocop errors after V4.1.1 release
- Fixed MySQL and PostgreSQL GitHub Actions [PR #3376](https://github.com/DMPRoadmap/roadmap/pull/3376)
Expand Down
10 changes: 2 additions & 8 deletions app/controllers/answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,8 @@ def create_or_update
# check should probably happen on create/update
# rubocop:disable Style/GuardClause
if @answer.present?
@plan = Plan.includes(
sections: {
questions: %i[
answers
question_format
]
}
).find(p_params[:plan_id])
@plan = Plan.includes(answers: { question: [:question_format] })
.find(p_params[:plan_id])
@question = @answer.question
@section = @plan.sections.find_by(id: @question.section_id)
template = @section.phase.template
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ def answer

# GET /plans/:id/download
def download
@plan = Plan.find(params[:id])
@plan = Plan.includes(:research_outputs, template: [:phases], roles: [:user])
.find(params[:id])
@has_research_outputs = @plan.research_outputs.any?
authorize @plan
@phase_options = @plan.phases.order(:number).pluck(:title, :id)
@phase_options.insert(0, ['All phases', 'All']) if @phase_options.length > 1
Expand Down
2 changes: 1 addition & 1 deletion app/views/plans/_download_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<%= _('unanswered questions') %>
<% end %>
</div>
<% if @plan.research_outputs.any? %>
<% if @has_research_outputs %>
<div class="form-check">
<%= label_tag 'export[research_outputs]', class:'form-check-label' do %>
<%= check_box_tag 'export[research_outputs]', true, true %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240617115900_add_index_to_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIndexToSettings < ActiveRecord::Migration[6.1]
def change
add_index :settings, [:target_id, :target_type], name: 'settings_target'
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@
t.string "target_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["target_id", "target_type"], name: "settings_target"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a corresponding migration file for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes 💯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just added one

end

create_table "stats", id: :integer, force: :cascade do |t|
Expand Down
Loading