From 26848ecaef78eceb6b419c3d999e18724c6a6bd2 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Wed, 3 Apr 2019 13:07:30 +0200 Subject: [PATCH] Refactor step position + 1 into a method --- app/controllers/steps_controller.rb | 4 ++-- app/models/step.rb | 4 ++++ app/models/team_zip_export.rb | 4 ++-- .../index/_protocol_preview_modal_body.html.erb | 2 +- .../reports/elements/_my_module_step_element.html.erb | 11 +++++++++-- app/views/steps/_step.html.erb | 2 +- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index d863fb562..f29536ada 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -229,12 +229,12 @@ class StepsController < ApplicationController flash[:success] = t( 'protocols.steps.destroy.success_flash', - step: (@step.position + 1).to_s + step: (@step.position_plus_one).to_s ) else flash[:error] = t( 'protocols.steps.destroy.error_flash', - step: (@step.position + 1).to_s + step: (@step.position_plus_one).to_s ) end diff --git a/app/models/step.rb b/app/models/step.rb index e070120b3..23e09f725 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -97,6 +97,10 @@ class Step < ApplicationRecord protocol.present? ? protocol.my_module : nil end + def position_plus_one + position + 1 + end + def last_comments(last_id = 1, per_page = Constants::COMMENTS_SEARCH_LIMIT) last_id = Constants::INFINITY if last_id <= 1 comments = StepComment.joins(:step) diff --git a/app/models/team_zip_export.rb b/app/models/team_zip_export.rb index 79203a770..1112f130f 100644 --- a/app/models/team_zip_export.rb +++ b/app/models/team_zip_export.rb @@ -189,7 +189,7 @@ class TeamZipExport < ZipExport if type == :step name = "#{directory}/" \ "#{append_file_suffix(asset.file_file_name, - "_#{i}_Step#{element.step.position + 1}")}" + "_#{i}_Step#{element.step.position_plus_one}")}" elsif type == :result name = "#{directory}/#{append_file_suffix(asset.file_file_name, "_#{i}")}" @@ -212,7 +212,7 @@ class TeamZipExport < ZipExport if type == :step name = "#{directory}/#{to_filesystem_name(table_name)}" \ - "_#{i}_Step#{element.step.position + 1}.csv" + "_#{i}_Step#{element.step.position_plus_one}.csv" elsif type == :result name = "#{directory}/#{to_filesystem_name(table_name)}.csv" end 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 fa832112c..d43306eb6 100644 --- a/app/views/protocols/index/_protocol_preview_modal_body.html.erb +++ b/app/views/protocols/index/_protocol_preview_modal_body.html.erb @@ -70,7 +70,7 @@ <% protocol.steps.order(:position).each do |step| %>
">
- <%= step.position + 1 %> + <%= step.position_plus_one %>
diff --git a/app/views/reports/elements/_my_module_step_element.html.erb b/app/views/reports/elements/_my_module_step_element.html.erb index b6c602d0c..eef4688e0 100644 --- a/app/views/reports/elements/_my_module_step_element.html.erb +++ b/app/views/reports/elements/_my_module_step_element.html.erb @@ -7,7 +7,14 @@ <% checklists = step.checklists %> <% comments = step.step_comments %> <% pdf_export_ready = defined?(export_all) && export_all %> -
" data-name="<%=t "projects.reports.elements.step.sidebar_name", pos: (step.position + 1), name: step.name %>" data-icon-class="fas fa-arrow-circle-right"> +
" + data-name="<%=t "projects.reports.elements.step.sidebar_name", pos: (step.position_plus_one), name: step.name %>" + data-icon-class="fas fa-arrow-circle-right">
@@ -23,7 +30,7 @@
- <%=t "projects.reports.elements.step.step_pos", pos: (step.position + 1) %> <%= step.name %> + <%=t "projects.reports.elements.step.step_pos", pos: (step.position_plus_one) %> <%= step.name %> <%= step_status_label(step) %>
diff --git a/app/views/steps/_step.html.erb b/app/views/steps/_step.html.erb index be03e4616..6b60c4726 100644 --- a/app/views/steps/_step.html.erb +++ b/app/views/steps/_step.html.erb @@ -1,6 +1,6 @@
">
- <%= step.position + 1 %> + <%= step.position_plus_one %>