diff --git a/app/controllers/api/v0/plans_controller.rb b/app/controllers/api/v0/plans_controller.rb index f81c0e7f68..374d5401d9 100644 --- a/app/controllers/api/v0/plans_controller.rb +++ b/app/controllers/api/v0/plans_controller.rb @@ -73,10 +73,10 @@ def index # Get all the Org Admin plans org_admin_plans = @user.org.org_admin_plans - @plans = org_admin_plans.includes([{ roles: :user }, { answers: :question_options }, - template: [{ phases: { - sections: { questions: %i[question_format themes] } - } }, :org]]) + @plans = org_admin_plans.preload([{ roles: :user }, { answers: :question_options }, + template: [{ phases: { + sections: { questions: %i[question_format themes] } + } }, :org]]) # Filter on list of users user_ids = extract_param_list(params, 'user') diff --git a/app/controllers/paginable/templates_controller.rb b/app/controllers/paginable/templates_controller.rb index 5ea6b552e8..4456ffa00b 100644 --- a/app/controllers/paginable/templates_controller.rb +++ b/app/controllers/paginable/templates_controller.rb @@ -105,8 +105,9 @@ def history paginable_renderise( partial: 'history', scope: @templates, - query_params: { sort_field: 'templates.title', sort_direction: :asc }, - locals: { current: @templates.maximum(:version) } + query_params: { sort_field: 'templates.version', sort_direction: :desc }, + locals: { current: @templates.maximum(:version) }, + format: :json ) end end diff --git a/app/controllers/plan_exports_controller.rb b/app/controllers/plan_exports_controller.rb index 41edc38212..46bcbef953 100644 --- a/app/controllers/plan_exports_controller.rb +++ b/app/controllers/plan_exports_controller.rb @@ -85,6 +85,9 @@ def show_docx def show_pdf render pdf: file_name, margin: @formatting[:margin], + # wkhtmltopdf behavior is based on the OS so force the zoom level + # See 'Gotchas' section of https://github.com/mileszs/wicked_pdf + zoom: 0.78125, footer: { center: format(_('Created using %{application_name}. Last modified %{date}'), application_name: ApplicationService.application_name, diff --git a/app/javascript/src/utils/accordion.js b/app/javascript/src/utils/accordion.js index d80ee9c5ee..253893bbd9 100644 --- a/app/javascript/src/utils/accordion.js +++ b/app/javascript/src/utils/accordion.js @@ -31,21 +31,23 @@ * */ $(() => { - $('body').on('click', '.accordion-controls', (e) => { + $('body').on('click', '.accordion-controls a', (e) => { e.preventDefault(); const currentTarget = $(e.currentTarget); const target = $(e.target); const direction = target.attr('data-toggle-direction'); + const parentTargetName = currentTarget.parent().attr('data-parent'); if (direction) { // Selects all .panel elements where the parent is currentTarget.attr('data-parent') and // after gets the immediately children whose class selector is panel-collapse - $(`#${currentTarget.attr('data-parent')} > .panel`).children('.panel-collapse').each((i, el) => { + const parentTarget = $(`#${parentTargetName}`).length ? $(`#${parentTargetName}`) : $(`.${parentTargetName}`); + $(parentTarget).find('.panel').find('.panel-collapse').each((i, el) => { const panelCollapse = $(el); // Expands or collapses the panel according to the // direction passed (e.g. show --> expands, hide --> collapses) if (direction === 'show') { - if (!panelCollapse.hasClass('in')) { - panelCollapse.prev().trigger('click'); + if (!panelCollapse.find('.panel-body').attr('data-loaded') || !panelCollapse.hasClass('in')) { + panelCollapse.prev()[0].click(); } } else { panelCollapse.collapse(direction); diff --git a/app/javascript/src/utils/sectionUpdate.js b/app/javascript/src/utils/sectionUpdate.js index 5e470b2de2..d31ce3331a 100644 --- a/app/javascript/src/utils/sectionUpdate.js +++ b/app/javascript/src/utils/sectionUpdate.js @@ -19,4 +19,4 @@ export const updateSectionProgress = (id, numSecAnswers, numSecQuestions) => { // given a question id find the containing div // used inconditional questions -export const getQuestionDiv = (id) => $(`#answer-form-${id}`).closest('.row'); +export const getQuestionDiv = (id) => $(`#answer-form-${id}`).closest('.question-body'); diff --git a/app/models/concerns/exportable_plan.rb b/app/models/concerns/exportable_plan.rb index 0e39130a5a..b106db3a7a 100644 --- a/app/models/concerns/exportable_plan.rb +++ b/app/models/concerns/exportable_plan.rb @@ -131,15 +131,14 @@ def prepare_coversheet hash end # rubocop:enable Metrics/AbcSize - # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity - # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize def prepare_coversheet_for_csv(csv, _headings, hash) - csv << [if hash[:attribution].many? - _('Creators: ') - else - _('Creator:') - end, format(_('%{authors}'), authors: hash[:attribution].join(', '))] + csv << if Array(hash[:attribution]).many? + [_('Creators: '), format(_('%{authors}'), authors: Array(hash[:attribution]).join(', '))] + else + [_('Creator:'), format(_('%{authors}'), authors: hash[:attribution])] + end csv << ['Affiliation: ', format(_('%{affiliation}'), affiliation: hash[:affiliation])] csv << if hash[:funder].present? [_('Template: '), format(_('%{funder}'), funder: hash[:funder])] @@ -161,10 +160,9 @@ def prepare_coversheet_for_csv(csv, _headings, hash) csv << [] csv << [] end - # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity + # rubocop:enable Metrics/MethodLength, Metrics/AbcSize # rubocop:disable Metrics/AbcSize, Metrics/BlockLength, Metrics/MethodLength - # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity # rubocop:disable Metrics/ParameterLists def show_section_for_csv(csv, phase, section, headings, unanswered, hash) section[:questions].each do |question| diff --git a/app/models/phase.rb b/app/models/phase.rb index 7b466b68b0..9dfd1b11cd 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -139,7 +139,7 @@ def num_answers_not_removed(plan) end def visibility_allowed?(plan) - value = Rational(num_answered_questions(plan), plan.num_questions) * 100 + value = Rational(num_answered_questions(plan), plan.num_questions).to_f * 100 value >= Rails.configuration.x.plans.default_percentage_answered.to_f end end diff --git a/app/policies/department_policy.rb b/app/policies/department_policy.rb index 95018eb5cf..ed98bbf3ce 100644 --- a/app/policies/department_policy.rb +++ b/app/policies/department_policy.rb @@ -6,8 +6,7 @@ class DepartmentPolicy < ApplicationPolicy # NOTE: @user is the signed_in_user and @record is an instance of Department def index? - (@user.can_org_admin? && @user.org.id == @department.org_id) || - @user.can_super_admin? + @user.can_org_admin? || @user.can_super_admin? end def new? diff --git a/app/views/org_admin/sections/_section.html.erb b/app/views/org_admin/sections/_section.html.erb index ca7062ca7f..cb56aa07b2 100644 --- a/app/views/org_admin/sections/_section.html.erb +++ b/app/views/org_admin/sections/_section.html.erb @@ -46,4 +46,4 @@ <% end %> - + \ No newline at end of file diff --git a/app/views/org_admin/sections/_section_group.html.erb b/app/views/org_admin/sections/_section_group.html.erb index 4623c019b0..37a960ab59 100644 --- a/app/views/org_admin/sections/_section_group.html.erb +++ b/app/views/org_admin/sections/_section_group.html.erb @@ -1,5 +1,5 @@ -
@@ -12,4 +12,4 @@ data_parent: panel_id, draggable: draggable_for_section?(section) } %> <% end%> -
+ \ No newline at end of file diff --git a/app/views/plans/_download_form.html.erb b/app/views/plans/_download_form.html.erb index d4fe9fae91..b9cb41799c 100644 --- a/app/views/plans/_download_form.html.erb +++ b/app/views/plans/_download_form.html.erb @@ -119,7 +119,7 @@ options_for_select(Settings::Template::VALID_MARGIN_RANGE.to_a, @export_settings.formatting[:margin][:right]), class: 'form-control', - "data-default": @plan.template.settings(:export).formatting[:margin][:rigth] %> + "data-default": @plan.template.settings(:export).formatting[:margin][:right] %> diff --git a/app/views/research_outputs/metadata_standards/_search_result.html.erb b/app/views/research_outputs/metadata_standards/_search_result.html.erb index 099223e4ac..9d8ed5e102 100644 --- a/app/views/research_outputs/metadata_standards/_search_result.html.erb +++ b/app/views/research_outputs/metadata_standards/_search_result.html.erb @@ -5,7 +5,7 @@

<%= sanitize(result.description) %>

- <% website = result.locations.select { |loc| loc["type"] == "website" }.first %> + <% website = result&.locations&.select { |loc| loc["type"] == "website" }&.first %> <% if website.present? %>
<%= link_to website["url"], website["url"], target: "_blank", class: "has-new-window-popup-info" %> diff --git a/app/views/shared/export/_plan_styling.erb b/app/views/shared/export/_plan_styling.erb index 4eda615477..7ed339fecc 100644 --- a/app/views/shared/export/_plan_styling.erb +++ b/app/views/shared/export/_plan_styling.erb @@ -2,11 +2,10 @@ @import 'https://fonts.googleapis.com/css?family=<%= font_face.downcase.include?('times') ? 'Times' : 'Helvetica' %>'; body { - font-family: @font-face; + font-family: <%= font_face %>; font-size: <%= font_size %>; - margin: <%= margin %>; } - h1 { + h1 { font-size: 1.5rem; font-weight: bold; padding: 0; @@ -59,5 +58,5 @@ } .bold { font-weight: bold; - } + } \ No newline at end of file diff --git a/app/views/shared/export/_plan_txt.erb b/app/views/shared/export/_plan_txt.erb index 32f83e8303..ce479c16cd 100644 --- a/app/views/shared/export/_plan_txt.erb +++ b/app/views/shared/export/_plan_txt.erb @@ -1,7 +1,7 @@ <%= "#{@plan.title}" %> <%= "----------------------------------------------------------\n" %> <% if @show_coversheet %> -<%= @hash[:attribution].length > 1 ? _("Creators: ") : _('Creator:') %> <%= @hash[:attribution].join(', ') %> +<%= Array(@hash[:attribution]).many? ? _("Creators: ") + Array(@hash[:attribution]).join(", ") : _('Creator:') + @hash[:attribution] %> <%= _("Affiliation: ") + @hash[:affiliation] %> <% if @hash[:funder].present? %> <%= _("Template: ") + @hash[:funder] %> diff --git a/app/views/template_exports/template_export.docx.erb b/app/views/template_exports/template_export.docx.erb index 77de02ac05..3448fa4b7a 100644 --- a/app/views/template_exports/template_export.docx.erb +++ b/app/views/template_exports/template_export.docx.erb @@ -26,7 +26,7 @@ <% if q_format.option_based? %> <% end %> diff --git a/app/views/template_exports/template_export.pdf.erb b/app/views/template_exports/template_export.pdf.erb index be138d642d..55fcbe0763 100644 --- a/app/views/template_exports/template_export.pdf.erb +++ b/app/views/template_exports/template_export.pdf.erb @@ -70,7 +70,7 @@ <% if q_format.option_based? %> <% end %> diff --git a/config/locales/localization.en-CA.yml b/config/locales/localization.en-CA.yml index bdd7f16661..c176fa139c 100644 --- a/config/locales/localization.en-CA.yml +++ b/config/locales/localization.en-CA.yml @@ -14,12 +14,14 @@ en-CA: date: formats: default: "%d-%m-%Y" - long: "%B %d, %Y" + long: "%d %B, %Y" short: "%d %b" + csv: "%d/%m/%Y" + readable: "%B %d, %Y" order: - - :year - - :month - :day + - :month + - :year number: currency: format: @@ -62,6 +64,6 @@ en-CA: words_connector: ", " time: formats: - default: "%a, %d %b %Y %I:%M:%S %p %Z" - long: "%B %d, %Y %I:%M %p" - short: "%d %b %I:%M %p" + default: "%a, %d %b %Y %H:%M:%S %z" + long: "%d %B, %Y %H:%M" + short: "%d %b %H:%M"