From 8d0c22327b88e46045409c4845ab7132f339fe94 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 4 May 2017 15:17:34 +0200 Subject: [PATCH] adds asc order to checklists [fixes SCI-1228] --- app/controllers/concerns/report_actions.rb | 2 +- app/models/checklist.rb | 1 + app/models/protocol.rb | 2 +- app/views/protocols/index/_protocol_preview_modal_body.html.erb | 2 +- app/views/steps/_step.html.erb | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/report_actions.rb b/app/controllers/concerns/report_actions.rb index 50deeeedc..783b52f43 100644 --- a/app/controllers/concerns/report_actions.rb +++ b/app/controllers/concerns/report_actions.rb @@ -105,7 +105,7 @@ module ReportActions def generate_step_contents_json(step) res = [] if in_params? :step_checklists - step.checklists.each do |checklist| + step.checklists.asc.each do |checklist| res << generate_new_el(false) res << generate_el( 'reports/elements/step_checklist_element.html.erb', diff --git a/app/models/checklist.rb b/app/models/checklist.rb index 738761c80..da0c08581 100644 --- a/app/models/checklist.rb +++ b/app/models/checklist.rb @@ -22,6 +22,7 @@ class Checklist < ActiveRecord::Base reject_if: :all_blank, allow_destroy: true + scope :asc, -> { order('checklists.created_at ASC') } def self.search(user, include_archived, query = nil, page = 1) step_ids = Step diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 5b1d98bf7..e4fc85ea9 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -273,7 +273,7 @@ class Protocol < ActiveRecord::Base step2.save # Copy checklists - step.checklists.each do |checklist| + step.checklists.asc.each do |checklist| checklist2 = Checklist.new( name: checklist.name, step: step2 diff --git a/app/views/protocols/index/_protocol_preview_modal_body.html.erb b/app/views/protocols/index/_protocol_preview_modal_body.html.erb index 41e57247e..cec5aa74d 100644 --- a/app/views/protocols/index/_protocol_preview_modal_body.html.erb +++ b/app/views/protocols/index/_protocol_preview_modal_body.html.erb @@ -160,7 +160,7 @@ <% unless step.checklists.blank? then %>
- <% step.checklists.each do |checklist| %> + <% step.checklists.asc.each do |checklist| %> <%= checklist.name %> <% if checklist.checklist_items.empty? %>
diff --git a/app/views/steps/_step.html.erb b/app/views/steps/_step.html.erb index e03e0d6ac..f248dfef5 100644 --- a/app/views/steps/_step.html.erb +++ b/app/views/steps/_step.html.erb @@ -132,7 +132,7 @@ <% unless step.checklists.blank? then %>
- <% step.checklists.each do |checklist| %> + <% step.checklists.asc.each do |checklist| %> <%= custom_auto_link(checklist.name) %> <% if checklist.checklist_items.empty? %>