Skip to content

Commit

Permalink
Merge pull request #3174 from DMPRoadmap/development
Browse files Browse the repository at this point in the history
Update master prior to v3.1.1

(brakeman fails on end of life warning, so ignoring.)
  • Loading branch information
raycarrick-ed committed May 12, 2022
2 parents 7cac435 + 5f6eaab commit 47be9ba
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 41 deletions.
8 changes: 4 additions & 4 deletions app/controllers/api/v0/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/paginable/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/plan_exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions app/javascript/src/utils/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,23 @@
* </div>
*/
$(() => {
$('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);
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/src/utils/sectionUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
16 changes: 7 additions & 9 deletions app/models/concerns/exportable_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
Expand All @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion app/models/phase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions app/policies/department_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/views/org_admin/sections/_section.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
<% end %>
</div>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/org_admin/sections/_section_group.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- TODO: Move this away from using ID attr -->
<div class="panel-group section-group"
<div class="panel-group section-group sections_accordion"
data-modifiable="<%= modifiable %>"
id="<%= panel_id %>"
role="tablist">
Expand All @@ -12,4 +12,4 @@
data_parent: panel_id,
draggable: draggable_for_section?(section) } %>
<% end%>
</div>
</div>
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 @@ -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] %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<p><%= sanitize(result.description) %></p>

<% website = result.locations.select { |loc| loc["type"] == "website" }.first %>
<% website = result&.locations&.select { |loc| loc["type"] == "website" }&.first %>
<% if website.present? %>
<div>
<%= link_to website["url"], website["url"], target: "_blank", class: "has-new-window-popup-info" %>
Expand Down
7 changes: 3 additions & 4 deletions app/views/shared/export/_plan_styling.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,5 +58,5 @@
}
.bold {
font-weight: bold;
}
}
</style>
2 changes: 1 addition & 1 deletion app/views/shared/export/_plan_txt.erb
Original file line number Diff line number Diff line change
@@ -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] %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/template_exports/template_export.docx.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<% if q_format.option_based? %>
<ul>
<% question.question_options.each do |option| %>
<li><%= option.text.chomp.strip %></li>
<li><%= option.text.chomp.strip %><%= option.is_default? ? ' - ' + _('default') : '' %></li>
<% end %>
</ul>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/template_exports/template_export.pdf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<% if q_format.option_based? %>
<ul>
<% question.question_options.each do |option| %>
<li><%= option.text.chomp.strip %></li>
<li><%= option.text.chomp.strip %><%= option.is_default? ? ' - ' + _('default') : '' %></li>
<% end %>
</ul>
<% end %>
Expand Down
14 changes: 8 additions & 6 deletions config/locales/localization.en-CA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"

0 comments on commit 47be9ba

Please sign in to comment.