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 @@

Scheme

<%= govuk_summary_list do |summary_list| %> - <% @scheme.display_attributes.each do |attr| %> + <% display_attributes(@scheme).each do |attr| %> <% next if current_user.data_coordinator? && attr[:name] == ("Housing stock owned by") %> <%= summary_list.row do |row| %> <% row.key { attr[:name].eql?("Registered under Care Standards Act 2000") ? "Registered under Care Standards Act 2000" : attr[:name].to_s.humanize } %> @@ -24,3 +24,7 @@ <% end %> <% end %> <% end %> + +<% if FeatureToggle.scheme_toggle_enabled? %> + <%= govuk_button_link_to "Deactivate this scheme", scheme_deactivate_path(@scheme), warning: true %> +<% end %> diff --git a/app/views/schemes/toggle_active.html.erb b/app/views/schemes/toggle_active.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/initializers/feature_toggle.rb b/config/initializers/feature_toggle.rb index ca4315e9e..b9315c577 100644 --- a/config/initializers/feature_toggle.rb +++ b/config/initializers/feature_toggle.rb @@ -14,4 +14,10 @@ class FeatureToggle false end + + def self.scheme_toggle_enabled? + return true unless Rails.env.production? + + false + end end diff --git a/config/routes.rb b/config/routes.rb index 9d5083e1f..7f3d36cac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -49,6 +49,7 @@ Rails.application.routes.draw do get "check-answers", to: "schemes#check_answers" get "edit-name", to: "schemes#edit_name" get "support-services-provider", to: "schemes#support_services_provider" + get "deactivate", to: "schemes#deactivate" member do resources :locations do diff --git a/db/migrate/20221109095650_add_deactivation_date_to_schemes.rb b/db/migrate/20221109095650_add_deactivation_date_to_schemes.rb new file mode 100644 index 000000000..6d717268f --- /dev/null +++ b/db/migrate/20221109095650_add_deactivation_date_to_schemes.rb @@ -0,0 +1,5 @@ +class AddDeactivationDateToSchemes < ActiveRecord::Migration[7.0] + def change + add_column :schemes, :deactivation_date, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 43fc94775..6ea8c4827 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_10_19_082625) do +ActiveRecord::Schema[7.0].define(version: 2022_11_09_095650) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -397,6 +397,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_19_082625) do t.integer "old_visible_id" t.integer "total_units" t.boolean "confirmed" + t.datetime "deactivation_date" t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id" end