diff --git a/app/controllers/admin/decisions_controller.rb b/app/controllers/admin/decisions_controller.rb index e24adfbb14..3a654261e3 100644 --- a/app/controllers/admin/decisions_controller.rb +++ b/app/controllers/admin/decisions_controller.rb @@ -1,6 +1,4 @@ class Admin::DecisionsController < Admin::BaseAdminController - include AdminTaskPagination - before_action :ensure_service_operator before_action :load_claim before_action :reject_decided_claims, unless: -> { qa_decision_task? } @@ -10,8 +8,8 @@ class Admin::DecisionsController < Admin::BaseAdminController def new @decision = Decision.new @claim_checking_tasks = ClaimCheckingTasks.new(@claim) - set_pagination @claims_preventing_payment = claims_preventing_payment_finder.claims_preventing_payment + @task_pagination = Admin::TaskPagination.new(claim: @claim, current_task_name:) end def create @@ -22,7 +20,7 @@ def create redirect_after_decision rescue ActiveRecord::RecordInvalid @claims_preventing_payment = claims_preventing_payment_finder.claims_preventing_payment - set_pagination + @task_pagination = Admin::TaskPagination.new(claim: @claim, current_task_name:) render "new" end diff --git a/app/controllers/admin/payroll_gender_tasks_controller.rb b/app/controllers/admin/payroll_gender_tasks_controller.rb index 3379a00534..6ca3552b36 100644 --- a/app/controllers/admin/payroll_gender_tasks_controller.rb +++ b/app/controllers/admin/payroll_gender_tasks_controller.rb @@ -1,17 +1,15 @@ class Admin::PayrollGenderTasksController < Admin::TasksController - include AdminTaskPagination - def create @claim_checking_tasks = ClaimCheckingTasks.new(@claim) @task = @claim.tasks.build(check_params) @current_task_name = current_task_name @claim.attributes = claim_params + @task_pagination = Admin::TaskPagination.new(claim: @claim, current_task_name:) if claim_and_task_saved? - redirect_to next_task_path + redirect_to @task_pagination.next_task_path else @tasks_presenter = @claim.policy::AdminTasksPresenter.new(@claim) - set_pagination render @task.name end end diff --git a/app/controllers/admin/tasks_controller.rb b/app/controllers/admin/tasks_controller.rb index f98582e2b4..aaf8521f18 100644 --- a/app/controllers/admin/tasks_controller.rb +++ b/app/controllers/admin/tasks_controller.rb @@ -1,6 +1,4 @@ class Admin::TasksController < Admin::BaseAdminController - include AdminTaskPagination - before_action :ensure_service_operator before_action :load_claim before_action :ensure_task_has_not_already_been_completed, only: [:create] @@ -17,7 +15,7 @@ def show @task = @claim.tasks.find_or_initialize_by(name: params[:name]) @current_task_name = current_task_name @notes = @claim.notes.automated.by_label(params[:name]) - set_pagination + @task_pagination = Admin::TaskPagination.new(claim: @claim, current_task_name:) render @task.name end @@ -26,12 +24,12 @@ def create @claim_checking_tasks = ClaimCheckingTasks.new(@claim) @task = @claim.tasks.build(check_params) @current_task_name = current_task_name + @task_pagination = Admin::TaskPagination.new(claim: @claim, current_task_name:) if @task.save - redirect_to next_task_path + redirect_to @task_pagination.next_task_path else @tasks_presenter = @claim.policy::AdminTasksPresenter.new(@claim) - set_pagination render @task.name end end @@ -40,12 +38,12 @@ def update @claim_checking_tasks = ClaimCheckingTasks.new(@claim) @task = @claim.tasks.where(name: params[:name]).first @current_task_name = current_task_name + @task_pagination = Admin::TaskPagination.new(claim: @claim, current_task_name:) if @task.update(check_params) - redirect_to next_task_path + redirect_to @task_pagination.next_task_path else @tasks_presenter = @claim.policy::AdminTasksPresenter.new(@claim) - set_pagination render @task.name end end diff --git a/app/controllers/concerns/admin_task_pagination.rb b/app/controllers/concerns/admin_task_pagination.rb deleted file mode 100644 index 4b8beacb62..0000000000 --- a/app/controllers/concerns/admin_task_pagination.rb +++ /dev/null @@ -1,38 +0,0 @@ -module AdminTaskPagination - def previous_task_name - return @claim_checking_tasks.applicable_task_names.last unless current_task_index.present? - - previous_index = current_task_index - 1 - (previous_index >= 0) ? @claim_checking_tasks.applicable_task_names[current_task_index - 1] : nil - end - - def next_task_name - return unless current_task_index.present? - @claim_checking_tasks.applicable_task_names[current_task_index + 1] - end - - def current_task_index - @claim_checking_tasks.applicable_task_names.index(current_task_name) - end - - def previous_task_path - return unless previous_task_name.present? - admin_claim_task_path(@claim, name: previous_task_name) - end - - def next_task_path - if next_task_name.present? - admin_claim_task_path(@claim, name: next_task_name) - else - new_admin_claim_decision_path(@claim) - end - end - - def set_pagination - @previous_task_name = previous_task_name - @previous_task_path = previous_task_path - @next_task_name = next_task_name - @next_task_name ||= "decision" unless current_task_name == "decision" - @next_task_path = next_task_path - end -end diff --git a/app/models/admin/task_pagination.rb b/app/models/admin/task_pagination.rb new file mode 100644 index 0000000000..37f7baa1d3 --- /dev/null +++ b/app/models/admin/task_pagination.rb @@ -0,0 +1,54 @@ +module Admin + class TaskPagination + include Rails.application.routes.url_helpers + + attr_reader :claim, :current_task_name + + def initialize(claim:, current_task_name:) + @claim = claim + @current_task_name = current_task_name + end + + def next_task_name + return unless current_task_index.present? + + string = claim_checking_tasks + .applicable_task_names[current_task_index + 1] + + string || "decision" + end + + def next_task_path + if next_task_name == "decision" + new_admin_claim_decision_path(claim) + elsif next_task_name.present? + admin_claim_task_path(claim, name: next_task_name) + end + end + + def previous_task_name + return claim_checking_tasks.applicable_task_names.last unless current_task_index.present? + + previous_index = current_task_index - 1 + (previous_index >= 0) ? claim_checking_tasks.applicable_task_names[current_task_index - 1] : nil + end + + def previous_task_path + return unless previous_task_name.present? + + admin_claim_task_path(claim, name: previous_task_name) + end + + private + + def current_task_index + claim_checking_tasks + .applicable_task_names + .index(current_task_name) + end + + def claim_checking_tasks + @claim_checking_tasks ||= ClaimCheckingTasks.new(claim) + end + end +end diff --git a/app/views/admin/_task_pagination.html.erb b/app/views/admin/_task_pagination.html.erb index 7569a409c5..b37ac04e0a 100644 --- a/app/views/admin/_task_pagination.html.erb +++ b/app/views/admin/_task_pagination.html.erb @@ -1,23 +1,23 @@