diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index d4168e355..8eb46884d 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -21,6 +21,10 @@ class SchemesController < ApplicationController render_not_found and return unless @scheme end + def deactivate + render "toggle_active", locals: { action: "deactivate" } + end + def new @scheme = Scheme.new end diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb new file mode 100644 index 000000000..3bd188343 --- /dev/null +++ b/app/helpers/schemes_helper.rb @@ -0,0 +1,37 @@ +module SchemesHelper + def display_attributes(scheme) + base_attributes = [ + { name: "Scheme code", value: scheme.id_to_display }, + { name: "Name", value: scheme.service_name, edit: true }, + { name: "Confidential information", value: scheme.sensitive, edit: true }, + { name: "Type of scheme", value: scheme.scheme_type }, + { name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act }, + { name: "Housing stock owned by", value: scheme.owning_organisation.name, edit: true }, + { name: "Support services provided by", value: scheme.arrangement_type }, + { name: "Organisation providing support", value: scheme.managing_organisation&.name }, + { name: "Primary client group", value: scheme.primary_client_group }, + { name: "Has another client group", value: scheme.has_other_client_group }, + { name: "Secondary client group", value: scheme.secondary_client_group }, + { name: "Level of support given", value: scheme.support_type }, + { name: "Intended length of stay", value: scheme.intended_stay }, + { name: "Availability", value: "Available from #{scheme.available_from.to_formatted_s(:govuk_date)} \nDeactivation date #{scheme.deactivation_date.to_formatted_s(:govuk_date)}" }, + { name: "Status", value: status_tag(scheme_status(scheme)) }, + ] + + if scheme.arrangement_type_same? + base_attributes.delete({ name: "Organisation providing support", value: scheme.managing_organisation&.name }) + end + base_attributes + end + + def scheme_status(scheme) + now = Time.zone.now + if scheme.deactivation_date.nil? + "active" + elsif scheme.deactivation_date < now + "deactivated" + elsif now < scheme.deactivation_date + "deactivates_soon" + end + end +end diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb index 08b6180b3..9283d94db 100644 --- a/app/helpers/tag_helper.rb +++ b/app/helpers/tag_helper.rb @@ -7,6 +7,10 @@ module TagHelper in_progress: "In progress", completed: "Completed", active: "Active", + incomplete: "Incomplete", + deactivates_soon: "Deactivates soon", + reactivates_soon: "Reactivates soon", + deactivated: "Deactivated", }.freeze COLOUR = { @@ -15,6 +19,10 @@ module TagHelper in_progress: "blue", completed: "green", active: "green", + incomplete: "red", + deactivates_soon: "yellow", + reactivates_soon: "blue", + deactivated: "grey", }.freeze def status_tag(status, classes = []) diff --git a/app/models/scheme.rb b/app/models/scheme.rb index f25b22df1..b8a242a70 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -153,31 +153,6 @@ class Scheme < ApplicationRecord ] end - def display_attributes - base_attributes = [ - { name: "Scheme code", value: id_to_display }, - { name: "Name", value: service_name, edit: true }, - { name: "Confidential information", value: sensitive, edit: true }, - { name: "Type of scheme", value: scheme_type }, - { name: "Registered under Care Standards Act 2000", value: registered_under_care_act }, - { name: "Housing stock owned by", value: owning_organisation.name, edit: true }, - { name: "Support services provided by", value: arrangement_type }, - { name: "Organisation providing support", value: managing_organisation&.name }, - { name: "Primary client group", value: primary_client_group }, - { name: "Has another client group", value: has_other_client_group }, - { name: "Secondary client group", value: secondary_client_group }, - { name: "Level of support given", value: support_type }, - { name: "Intended length of stay", value: intended_stay }, - { name: "Availability", value: "Available from #{available_from.to_formatted_s(:govuk_date)}" }, - { name: "Status", value: "" }, - ] - - if arrangement_type_same? - base_attributes.delete({ name: "Organisation providing support", value: managing_organisation&.name }) - end - base_attributes - end - def synonyms locations.map(&:postcode).join(",") end diff --git a/app/views/schemes/show.html.erb b/app/views/schemes/show.html.erb index 75cb533f7..7bf7d84a2 100644 --- a/app/views/schemes/show.html.erb +++ b/app/views/schemes/show.html.erb @@ -15,7 +15,7 @@