Skip to content

Commit

Permalink
Merge pull request #2127 from unboxed/bops-core-status-tag
Browse files Browse the repository at this point in the history
Extract shared status tag presenter to Bops Core
  • Loading branch information
rebeccaoneill authored Jan 22, 2025
2 parents ff3b9c3 + 01faca2 commit 90d6b63
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 135 deletions.
133 changes: 0 additions & 133 deletions app/presenters/concerns/status_presenter.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/presenters/planning_application_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PlanningApplicationPresenter

presents :planning_application

include StatusPresenter
include BopsCore::StatusPresenter
include ProposalDetailsPresenter
include ValidationTasksPresenter
include AssessmentTasksPresenter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def show
private

def set_planning_application
@planning_application = planning_applications_scope.find_by!(reference:)
planning_application = planning_applications_scope.find_by!(reference:)
@planning_application = PlanningApplicationPresenter.new(view_context, planning_application)
rescue ActiveRecord::RecordNotFound
render_not_found
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module BopsConsultees
class PlanningApplicationPresenter
include Presentable

presents :planning_application

include BopsCore::StatusPresenter

def initialize(template, planning_application)
@template = template
@planning_application = planning_application
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<p class="govuk-body">
<%= t(".application_number") %> <strong><%= @planning_application.reference %></strong>
<%= @planning_application.status_tag %>
</p>
</div>
</div>
135 changes: 135 additions & 0 deletions engines/bops_core/app/presenters/bops_core/status_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# frozen_string_literal: true

module BopsCore
module StatusPresenter
extend ActiveSupport::Concern

STATUS_COLOURS = {
invalidated: "red",
not_started: "blue",
in_assessment: "light-blue",
awaiting_determination: "purple",
to_be_reviewed: "yellow"
}.freeze

included do
def status_tag
classes = ["govuk-tag govuk-tag--#{status_tag_colour}"]

tag.span class: classes do
if determined?
decision.humanize
else
aasm.human_state.humanize
end
end
end

def appeal_status_tag
tag.span class: ["govuk-tag govuk-tag--purple"] do
appeal.display_status
end
end

def days_status_tag
classes = ["govuk-tag govuk-tag--#{status_date_tag_colour}"]

tag.span class: classes do
if not_started?
I18n.t("planning_applications.days_from", count: days_from)
elsif expiry_date.past?
I18n.t("planning_applications.overdue", count: days_overdue)
else
I18n.t("planning_applications.days_left", count: days_left)
end
end
end

alias_method :outcome, :status_tag

def next_relevant_date_tag
tag.strong(next_date_label) + tag.time(next_date.to_fs, datetime: next_date.iso8601)
end

def next_date_label
if in_progress?
"Expiry date"
elsif determined?
"#{decision.humanize} at"
else
"#{status.humanize} at"
end
end

def next_date
if in_progress?
expiry_date
elsif determined?
determination_date.to_date
else
send(:"#{status}_at")
end
end
end

def validation_status
if validation_complete?
:complete
elsif validation_requests.any? || any_validation_tasks_complete?
:in_progress
else
:not_started
end
end

private

def any_validation_tasks_complete?
valid_fee? ||
valid_red_line_boundary? ||
constraints_checked? ||
documents.any?(&:validated?) ||
documents_missing == false
end

def status_tag_colour
if planning_application.determined?
planning_application.granted? ? "green" : "red"
else
colour = STATUS_COLOURS[planning_application.status.to_sym]

colour || "grey"
end
end

def status_date_tag_colour
return "orange" if @planning_application.not_started?
return "grey" if @planning_application.determined?

number = planning_application.days_left

if number > 11
"green"
elsif number.between?(6, 10)
"yellow"
else
"red"
end
end

def status_consultation_date_tag_colour
return "grey" if planning_application.consultation.blank?
return "grey" if planning_application.consultation.start_date.blank?

number = planning_application.consultation.days_left

if number > 11
"green"
elsif number.between?(6, 10)
"yellow"
else
"red"
end
end
end
end

0 comments on commit 90d6b63

Please sign in to comment.