Browse Source

feat: wip deactivate scheme schemes page

pull/980/head
natdeanlewissoftwire 2 years ago
parent
commit
b3ebb29d46
  1. 4
      app/controllers/schemes_controller.rb
  2. 37
      app/helpers/schemes_helper.rb
  3. 8
      app/helpers/tag_helper.rb
  4. 25
      app/models/scheme.rb
  5. 6
      app/views/schemes/show.html.erb
  6. 0
      app/views/schemes/toggle_active.html.erb
  7. 6
      config/initializers/feature_toggle.rb
  8. 1
      config/routes.rb
  9. 5
      db/migrate/20221109095650_add_deactivation_date_to_schemes.rb
  10. 3
      db/schema.rb

4
app/controllers/schemes_controller.rb

@ -21,6 +21,10 @@ class SchemesController < ApplicationController
render_not_found and return unless @scheme render_not_found and return unless @scheme
end end
def deactivate
render "toggle_active", locals: { action: "deactivate" }
end
def new def new
@scheme = Scheme.new @scheme = Scheme.new
end end

37
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

8
app/helpers/tag_helper.rb

@ -7,6 +7,10 @@ module TagHelper
in_progress: "In progress", in_progress: "In progress",
completed: "Completed", completed: "Completed",
active: "Active", active: "Active",
incomplete: "Incomplete",
deactivates_soon: "Deactivates soon",
reactivates_soon: "Reactivates soon",
deactivated: "Deactivated",
}.freeze }.freeze
COLOUR = { COLOUR = {
@ -15,6 +19,10 @@ module TagHelper
in_progress: "blue", in_progress: "blue",
completed: "green", completed: "green",
active: "green", active: "green",
incomplete: "red",
deactivates_soon: "yellow",
reactivates_soon: "blue",
deactivated: "grey",
}.freeze }.freeze
def status_tag(status, classes = []) def status_tag(status, classes = [])

25
app/models/scheme.rb

@ -153,31 +153,6 @@ class Scheme < ApplicationRecord
] ]
end 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 def synonyms
locations.map(&:postcode).join(",") locations.map(&:postcode).join(",")
end end

6
app/views/schemes/show.html.erb

@ -15,7 +15,7 @@
<h2 class="govuk-visually-hidden">Scheme</h2> <h2 class="govuk-visually-hidden">Scheme</h2>
<%= govuk_summary_list do |summary_list| %> <%= 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") %> <% next if current_user.data_coordinator? && attr[:name] == ("Housing stock owned by") %>
<%= summary_list.row do |row| %> <%= 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 } %> <% 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 %> <% end %>
<% end %> <% end %>
<% if FeatureToggle.scheme_toggle_enabled? %>
<%= govuk_button_link_to "Deactivate this scheme", scheme_deactivate_path(@scheme), warning: true %>
<% end %>

0
app/views/schemes/toggle_active.html.erb

6
config/initializers/feature_toggle.rb

@ -14,4 +14,10 @@ class FeatureToggle
false false
end end
def self.scheme_toggle_enabled?
return true unless Rails.env.production?
false
end
end end

1
config/routes.rb

@ -49,6 +49,7 @@ Rails.application.routes.draw do
get "check-answers", to: "schemes#check_answers" get "check-answers", to: "schemes#check_answers"
get "edit-name", to: "schemes#edit_name" get "edit-name", to: "schemes#edit_name"
get "support-services-provider", to: "schemes#support_services_provider" get "support-services-provider", to: "schemes#support_services_provider"
get "deactivate", to: "schemes#deactivate"
member do member do
resources :locations do resources :locations do

5
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

3
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" 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 "old_visible_id"
t.integer "total_units" t.integer "total_units"
t.boolean "confirmed" t.boolean "confirmed"
t.datetime "deactivation_date"
t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id"
end end

Loading…
Cancel
Save