From c372263eb61a141ad34f7cf518f8d7428fdf7210 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 15 Jun 2023 15:34:25 +0100 Subject: [PATCH] Change status tag method --- app/helpers/schemes_helper.rb | 2 +- app/helpers/tag_helper.rb | 14 +++++++++----- app/views/locations/index.html.erb | 2 +- app/views/locations/show.html.erb | 2 +- app/views/schemes/_scheme_list.html.erb | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb index f28a18211..1f51db6b6 100644 --- a/app/helpers/schemes_helper.rb +++ b/app/helpers/schemes_helper.rb @@ -14,7 +14,7 @@ module SchemesHelper { name: "Level of support given", value: scheme.support_type }, { name: "Intended length of stay", value: scheme.intended_stay }, { name: "Availability", value: scheme_availability(scheme) }, - { name: "Status", value: status_tag(scheme.status) }, + { name: "Status", value: status_tag_from_resource(scheme) }, ] if user.data_coordinator? diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb index 6fc6927e5..375381a59 100644 --- a/app/helpers/tag_helper.rb +++ b/app/helpers/tag_helper.rb @@ -27,13 +27,17 @@ module TagHelper deactivated: "grey", }.freeze - def status_tag(resource, classes = []) - display_status = resource.status - display_status = :active if resource.deactivates_in_more_than_6_months? + def status_tag(status, classes = []) govuk_tag( classes:, - colour: COLOUR[display_status.to_sym], - text: TEXT[display_status.to_sym], + colour: COLOUR[status.to_sym], + text: TEXT[status.to_sym], ) end + + def status_tag_from_resource(resource, classes = []) + status = resource.status + status = :active if resource.deactivates_in_more_than_6_months? + status_tag(status, classes) + end end diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index 5d0f429b2..7641bbd48 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -54,7 +54,7 @@ end), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: location.name) %> <% row.cell(text: location.id) %> - <% row.cell(text: status_tag(location)) %> + <% row.cell(text: status_tag_from_resource(location)) %> <% end %> <% end %> <% end %> diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index a865364e6..fcee0a175 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -15,7 +15,7 @@ <% display_location_attributes(@location).each do |attr| %> <%= summary_list.row do |row| %> <% row.key { attr[:name] } %> - <% row.value { attr[:attribute].eql?("status") ? status_tag(@location) : details_html(attr) } %> + <% row.value { attr[:attribute].eql?("status") ? status_tag_from_resource(@location) : details_html(attr) } %> <% if LocationPolicy.new(current_user, @location).update? %> <% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %> <% end %> diff --git a/app/views/schemes/_scheme_list.html.erb b/app/views/schemes/_scheme_list.html.erb index a3fb82013..43e03cd65 100644 --- a/app/views/schemes/_scheme_list.html.erb +++ b/app/views/schemes/_scheme_list.html.erb @@ -17,7 +17,7 @@ <% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: scheme.id_to_display) %> <% row.cell(text: scheme.locations&.count) %> - <% row.cell(text: status_tag(scheme)) %> + <% row.cell(text: status_tag_from_resource(scheme)) %> <% end %> <% end %> <% end %>