Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inherit_mode:
Layout/EmptyLineAfterMagicComment:
Enabled: true

Layout/LineLength:
Max: 130

RSpec/AnyInstance:
Enabled: false

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class AssessorInterface::ServiceLevelAgreementsController < AssessorInterface::BaseController
def index
authorize %i[assessor_interface service_level_agreement]

@view_object =
AssessorInterface::ServiceLevelAgreementIndexViewObject.new(params:)

render layout: "full_from_desktop"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AssessorInterface::ServiceLevelAgreementPolicy < ApplicationPolicy
def index?
user.manage_staff_permission? && !user.archived?
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# frozen_string_literal: true

class AssessorInterface::ServiceLevelAgreementIndexViewObject
include ActionView::Helpers::FormOptionsHelper
include Pagy::Backend

def initialize(params:)
@params = params
end

def application_forms_pagy
application_forms_with_pagy.first
end

def application_forms_records
application_forms_with_pagy.last
end

def breached_sla_for_starting_prioritisation_checks_count
application_forms_with_prioritisation_checks_not_started.where(
"working_days_between_submitted_and_today > ?",
WORKING_DAYS_TO_START_PRIORITISATION_CHECKS,
).count
end

def nearing_sla_for_starting_prioritisation_checks_count
application_forms_with_prioritisation_checks_not_started.where(
working_days_between_submitted_and_today:
WORKING_DAYS_NEARING_START_PRIORITISATION_CHECKS_DEADLINE..WORKING_DAYS_TO_START_PRIORITISATION_CHECKS,
).count
end

def breached_sla_for_completing_prioritised_applications_count
application_forms_prioritised_but_assessment_not_completed.where(
"working_days_between_submitted_and_today > ?",
WORKING_DAYS_TO_FINISH_ASSESSMENT_FOR_PRIORITISED,
).count
end

def nearing_sla_for_completing_prioritised_applications_count
application_forms_prioritised_but_assessment_not_completed.where(
working_days_between_submitted_and_today:
WORKING_DAYS_NEARING_FINISH_ASSESSMENT_FOR_PRIORITISED_DEADLINE..WORKING_DAYS_TO_FINISH_ASSESSMENT_FOR_PRIORITISED,
).count
end

def sla_start_prioritisation_checks_tag_colour(application_form)
return if application_form.assessment.nil?

if application_form.assessment.started_at.present? ||
application_form.assessment.prioritisation_work_history_checks.empty?
return
end

if application_form.working_days_between_submitted_and_today.to_i >
WORKING_DAYS_TO_START_PRIORITISATION_CHECKS
"red"
elsif application_form.working_days_between_submitted_and_today.to_i >=
WORKING_DAYS_NEARING_START_PRIORITISATION_CHECKS_DEADLINE
"yellow"
else
"green"
end
end

def sla_completed_prioritised_tag_colour(application_form)
return if application_form.assessment.nil?

if !application_form.assessment.prioritised? ||
application_form.assessment.verification_started_at.present?
return
end

if application_form.working_days_between_submitted_and_today.to_i >
WORKING_DAYS_TO_FINISH_ASSESSMENT_FOR_PRIORITISED
"red"
elsif application_form.working_days_between_submitted_and_today.to_i >=
WORKING_DAYS_NEARING_FINISH_ASSESSMENT_FOR_PRIORITISED_DEADLINE
"yellow"
else
"green"
end
end

private

WORKING_DAYS_TO_START_PRIORITISATION_CHECKS = 10
WORKING_DAYS_NEARING_START_PRIORITISATION_CHECKS_DEADLINE = 8

WORKING_DAYS_TO_FINISH_ASSESSMENT_FOR_PRIORITISED = 40
WORKING_DAYS_NEARING_FINISH_ASSESSMENT_FOR_PRIORITISED_DEADLINE = 35

def application_forms_with_pagy
@application_forms_with_pagy ||=
pagy(
application_forms_with_filter.order(
working_days_between_submitted_and_today: :desc,
),
)
end

def application_forms_with_filter
@application_forms_with_filter ||=
if params[:tab] == "40"
application_forms_prioritised_but_assessment_not_completed
else
application_forms_with_prioritisation_checks_not_started
end
end

def application_forms_with_prioritisation_checks_not_started
ApplicationForm
.joins(assessment: :prioritisation_work_history_checks)
.where(assessment: { started_at: nil })
.where.not(assessment: { prioritisation_work_history_checks: nil })
.distinct
end

def application_forms_prioritised_but_assessment_not_completed
ApplicationForm
.joins(:assessment)
.where(assessment: { verification_started_at: nil, prioritised: true })
.distinct
end

attr_reader :params
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<% content_for :page_title, "SLA Status" %>

<h1 class="govuk-heading-xl">SLA Status (Prioritisation)</h1>

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<h3 class="govuk-heading-m">Breached 10 day SLA</h3>
<%= govuk_inset_text { @view_object.breached_sla_for_starting_prioritisation_checks_count.to_s } %>
</div>
<div class="govuk-grid-column-one-half">
<h3 class="govuk-heading-m">Breached 40 day SLA</h3>
<%= govuk_inset_text { @view_object.breached_sla_for_completing_prioritised_applications_count.to_s } %>
</div>
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<h3 class="govuk-heading-m">Nearing 10 day SLA</h3>
<%= govuk_inset_text { @view_object.nearing_sla_for_starting_prioritisation_checks_count.to_s } %>
</div>
<div class="govuk-grid-column-one-half">
<h3 class="govuk-heading-m">Nearing 40 day SLA</h3>
<%= govuk_inset_text { @view_object.nearing_sla_for_completing_prioritised_applications_count.to_s } %>
</div>
</div>

<%= govuk_details(summary_text: "SLA definitions") do %>
<p class="govuk-body">10 day SLA relates to application forms that are going through prioritisation checks and expect checks to begin within 10 days of being submitted. For these applications, we consider them as nearing SLA once they are within 2 days of breaching the SLA.</p>
<p class="govuk-body">40 day SLA relates to application forms are prioritised and expect initial assessment to be completed and moved to verification within 40 days of being submitted. For these applications, we consider them as nearing SLA once they are within 5 days of breaching the SLA.</p>
<% end %>

<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">

<h2 class="govuk-heading-l">Application forms</h2>

<div class="govuk-tabs" data-module="govuk-tabs">
<h2 class="govuk-tabs__title">
Contents
</h2>
<ul class="govuk-tabs__list">
<li class="govuk-tabs__list-item <%= 'govuk-tabs__list-item--selected' if params[:tab] != "40" %>">
<%= link_to "10 day SLA", assessor_interface_service_level_agreements_path %>
</li>
<li class="govuk-tabs__list-item <%= 'govuk-tabs__list-item--selected' if params[:tab] == "40" %>">
<%= link_to "40 day SLA", assessor_interface_service_level_agreements_path(tab: "40") %>
</li>
</ul>
<div class="govuk-tabs__panel">
<% if (records = @view_object.application_forms_records).present? %>
<%=
govuk_table(classes: "application-forms-sla") do |table|
table.with_head do |head|
head.with_row do |row|
row.with_cell(header: true, text: "Reference")
row.with_cell(header: true, text: "Country/Region")
row.with_cell(header: true, text: "Working days since submission")
end
end

table.with_body do |body|
records.each do |application_form|
body.with_row do |row|
row.with_cell { govuk_link_to application_form.reference, [:assessor_interface, application_form] }
row.with_cell { CountryName.from_region(application_form.region) }
row.with_cell do
if params[:tab] == "40"
govuk_tag(text: application_form.working_days_between_submitted_and_today, colour: @view_object.sla_completed_prioritised_tag_colour(application_form) )
else
govuk_tag(text: application_form.working_days_between_submitted_and_today, colour: @view_object.sla_start_prioritisation_checks_tag_colour(application_form) )
end
end
end
end
end
end
%>
<%= govuk_pagination(pagy: @view_object.application_forms_pagy) %>
<% else %>
<h2 class="govuk-heading-m"><%= t(".results.empty") %></h2>
<% end %>
</div>
</div>

5 changes: 5 additions & 0 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
href: main_app.assessor_interface_staff_index_path,
active: current_page?(main_app.assessor_interface_staff_index_path)
) %>
<% service_navigation.with_navigation_item(
text: "SLA Status",
href: main_app.assessor_interface_service_level_agreements_path,
active: current_page?(main_app.assessor_interface_service_level_agreements_path)
) %>
<% end %>
<% service_navigation.with_navigation_item(text: "Sign out", href: main_app.destroy_staff_session_path) %>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace :assessor_interface, path: "/assessor" do
root to: redirect("/assessor/applications")

resources :service_level_agreements, only: %i[index]

resources :staff, only: %i[index edit update] do
member do
get "archive", to: "staff#edit_archive"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe AssessorInterface::ServiceLevelAgreementPolicy do
it_behaves_like "a policy"

describe "#index?" do
subject(:index?) { described_class.new(user, nil).index? }

it_behaves_like "a policy method requiring the manage staff permission"
end
end
Loading
Loading