Skip to content

Commit

Permalink
Merge pull request #3282 from DFE-Digital/task-pagination-refactor
Browse files Browse the repository at this point in the history
[CAPT-1614] Refactors admin task pagination
  • Loading branch information
asmega authored Oct 8, 2024
2 parents 4bb7f84 + 273e3dc commit 8131f96
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 78 deletions.
6 changes: 2 additions & 4 deletions app/controllers/admin/decisions_controller.rb
Original file line number Diff line number Diff line change
@@ -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? }
Expand All @@ -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
Expand All @@ -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

Expand Down
6 changes: 2 additions & 4 deletions app/controllers/admin/payroll_gender_tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 5 additions & 7 deletions app/controllers/admin/tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
38 changes: 0 additions & 38 deletions app/controllers/concerns/admin_task_pagination.rb

This file was deleted.

54 changes: 54 additions & 0 deletions app/models/admin/task_pagination.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions app/views/admin/_task_pagination.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<nav class="govuk-pagination govuk-pagination--block" aria-label="results">
<% if @previous_task_name.present? %>
<% if task_pagination.previous_task_name.present? %>
<div class="govuk-pagination__prev">
<%= link_to @previous_task_path, class: "govuk-link govuk-pagination__link", rel: "prev" do %>
<%= link_to task_pagination.previous_task_path, class: "govuk-link govuk-pagination__link", rel: "prev" do %>
<svg class="govuk-pagination__icon govuk-pagination__icon--prev" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"></path>
</svg>
<span class="govuk-pagination__link-title">Previous</span><span class="govuk-visually-hidden">:</span>
<span class="govuk-pagination__link-label"><%= @previous_task_name.humanize %></span>
<span class="govuk-pagination__link-label"><%= task_pagination.previous_task_name.humanize %></span>
<% end %>
</div>
<% end %>

<% if @next_task_name.present? %>
<% if task_pagination.next_task_name.present? %>
<div class="govuk-pagination__next">
<%= link_to @next_task_path, class: "govuk-link govuk-pagination__link", rel: "next" do %>
<%= link_to task_pagination.next_task_path, class: "govuk-link govuk-pagination__link", rel: "next" do %>
<svg class="govuk-pagination__icon govuk-pagination__icon--next" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path>
</svg> <span class="govuk-pagination__link-title">Next</span><span class="govuk-visually-hidden">:</span>
<span class="govuk-pagination__link-label"><%= @next_task_name.humanize %></span>
<span class="govuk-pagination__link-label"><%= task_pagination.next_task_name.humanize %></span>
<% end %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/decisions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<%= render("incomplete_tasks", claim: @claim, incomplete_task_names: @claim_checking_tasks.incomplete_task_names) if @claim_checking_tasks.incomplete_task_names.any? %>
<%= render "decision_form", claim: @claim, decision: @decision, claims_preventing_payment: @claims_preventing_payment %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/arrival_date.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<%= render "form", task_name: "arrival_date", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/census_subjects_taught.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<%= render "form", task_name: "census_subjects_taught", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/employment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
<%= render "form", task_name: "employment", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/employment_contract.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<%= render "form", task_name: "employment_contract", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/employment_start.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= render "form", task_name: "employment_start", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/tasks/identity_confirmation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
<%= render "form", task_name: "identity_confirmation", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/induction_confirmation.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<%= render "form", task_name: "induction_confirmation", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/matching_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
<%= render "form", task_name: "matching_details", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/payroll_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@
<% end %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/payroll_gender.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
</div>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/previous_payment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
<%= render "form", task_name: "previous_payment", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/previous_residency.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
<%= render "form", task_name: "previous_residency", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/provider_verification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
<%= render "form", task_name: "provider_verification", claim: @claim %>
<% end %>
<% end %>
<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/qualifications.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<%= render "form", task_name: "qualifications", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/student_loan_amount.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<%= render "form", task_name: "student_loan_amount", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/student_loan_plan.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
</div>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/tasks/subject.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= render "form", task_name: "subject", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/tasks/teaching_hours.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<%= render "form", task_name: "teaching_hours", claim: @claim %>
<% end %>

<%= render partial: "admin/task_pagination" %>
<%= render partial: "admin/task_pagination", locals: { task_pagination: @task_pagination } %>
</div>
</div>

0 comments on commit 8131f96

Please sign in to comment.