Browse Source

feat: copy behaviour for scheme reactivation 2 (wip)

CLDC-1672-reactivate-scheme
natdeanlewissoftwire 2 years ago
parent
commit
9d3a18166d
  1. 2
      app/controllers/schemes_controller.rb
  2. 10
      app/models/scheme.rb
  3. 2
      app/views/schemes/show.html.erb
  4. 4
      app/views/schemes/toggle_active.html.erb
  5. 4
      config/locales/en.yml

2
app/controllers/schemes_controller.rb

@ -59,7 +59,7 @@ class SchemesController < ApplicationController
@scheme.reactivation_date = reactivation_date @scheme.reactivation_date = reactivation_date
@scheme.reactivation_date_type = params[:scheme][:reactivation_date_type] @scheme.reactivation_date_type = params[:scheme][:reactivation_date_type]
if @scheme.valid? && @scheme.location_deactivation_periods.deactivations_without_reactivation.update!(reactivation_date:) if @scheme.valid? && @scheme.scheme_deactivation_periods.deactivations_without_reactivation.update!(reactivation_date:)
flash[:notice] = reactivate_success_notice flash[:notice] = reactivate_success_notice
redirect_to scheme_details_path(@scheme) redirect_to scheme_details_path(@scheme)
else else

10
app/models/scheme.rb

@ -218,11 +218,13 @@ class Scheme < ApplicationRecord
end end
def status def status
recent_deactivation = scheme_deactivation_periods.deactivations_without_reactivation.first open_deactivation = scheme_deactivation_periods.deactivations_without_reactivation.first
return :active if recent_deactivation.blank? recent_deactivation = scheme_deactivation_periods.order("created_at").last
return :deactivating_soon if Time.zone.now < recent_deactivation.deactivation_date return :deactivated if open_deactivation&.deactivation_date.present? && Time.zone.now >= open_deactivation.deactivation_date
return :deactivating_soon if open_deactivation&.deactivation_date.present? && Time.zone.now < open_deactivation.deactivation_date
return :reactivating_soon if recent_deactivation&.reactivation_date.present? && Time.zone.now < recent_deactivation.reactivation_date
:deactivated :active
end end
def active? def active?

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

@ -29,6 +29,6 @@
<% if @scheme.active? %> <% if @scheme.active? %>
<%= govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(@scheme), warning: true %> <%= govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(@scheme), warning: true %>
<% else %> <% else %>
<%= govuk_button_link_to "Reactivate this scheme", scheme_reactivate_path(@scheme) %> <%= govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(@scheme) %>
<% end %> <% end %>
<% end %> <% end %>

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

@ -12,9 +12,9 @@
<% collection_start_date = FormHandler.instance.current_collection_start_date %> <% collection_start_date = FormHandler.instance.current_collection_start_date %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset date_type_question(action), <%= f.govuk_radio_buttons_fieldset date_type_question(action),
legend: { text: I18n.t("questions.scheme.deactivate.apply_from") }, legend: { text: I18n.t("questions.scheme.toggle_active.apply_from") },
caption: { text: title }, caption: { text: title },
hint: { text: I18n.t("hints.scheme.deactivate", date: collection_start_date.to_formatted_s(:govuk_date)) } do %> hint: { text: I18n.t("hints.scheme.toggle_active", date: collection_start_date.to_formatted_s(:govuk_date)) } do %>
<%= govuk_warning_text text: I18n.t("warnings.scheme.#{action}.existing_logs") %> <%= govuk_warning_text text: I18n.t("warnings.scheme.#{action}.existing_logs") %>
<%= f.govuk_radio_button date_type_question(action), <%= f.govuk_radio_button date_type_question(action),
"default", "default",

4
config/locales/en.yml

@ -377,7 +377,7 @@ en:
deactivation: deactivation:
apply_from: "When should this change apply?" apply_from: "When should this change apply?"
scheme: scheme:
deactivate: toggle_active:
apply_from: "When should this change apply?" apply_from: "When should this change apply?"
descriptions: descriptions:
location: location:
@ -393,7 +393,7 @@ en:
units: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff." units: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff."
deactivation: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed." deactivation: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed."
scheme: scheme:
deactivate: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed." toggle_active: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed."
warnings: warnings:
location: location:

Loading…
Cancel
Save