Browse Source

validate all the required scheme questions are answered

pull/775/head
Kat 3 years ago
parent
commit
2bbecb0b9e
  1. 2
      app/controllers/schemes_controller.rb
  2. 10
      app/models/scheme.rb
  3. 200
      app/views/schemes/check_answers.html.erb
  4. 1
      spec/factories/scheme.rb

2
app/controllers/schemes_controller.rb

@ -128,6 +128,8 @@ private
"schemes/details" "schemes/details"
elsif page.include?("edit") elsif page.include?("edit")
"schemes/edit_name" "schemes/edit_name"
elsif page.include?("check-answers")
"schemes/check_answers"
end end
end end

10
app/models/scheme.rb

@ -9,6 +9,8 @@ class Scheme < ApplicationRecord
scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct } scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct }
validate :validate_confirmed
SENSITIVE = { SENSITIVE = {
No: 0, No: 0,
Yes: 1, Yes: 1,
@ -205,4 +207,12 @@ class Scheme < ApplicationRecord
def arrangement_type_same? def arrangement_type_same?
arrangement_type.present? && ARRANGEMENT_TYPE[arrangement_type.to_sym] == "D" arrangement_type.present? && ARRANGEMENT_TYPE[arrangement_type.to_sym] == "D"
end end
def validate_confirmed
required_attributes = attribute_names - %w[id created_at updated_at old_id old_visible_id confirmed end_date sensitive secondary_client_group total_units has_other_client_group]
if confirmed == true && required_attributes.any? { |attribute| self[attribute].blank? }
errors.add :base, "Please answer all the required questions"
end
end
end end

200
app/views/schemes/check_answers.html.erb

@ -1,137 +1,137 @@
<% content_for :title, "Check your answers before creating this scheme" %> <% content_for :title, "Check your answers before creating this scheme" %>
<%= render partial: "organisations/headings", locals: { main: "Check your changes before creating this scheme", sub: @scheme.service_name } %> <%= render partial: "organisations/headings", locals: { main: "Check your changes before creating this scheme", sub: @scheme.service_name } %>
<div class="govuk-grid-row"> <%= form_for(@scheme, as: :scheme, method: :patch) do |f| %>
<div class="govuk-grid-column-three-quarters-from-desktop"> <%= f.govuk_error_summary %>
<%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %> <div class="govuk-grid-row">
<% component.tab(label: "Scheme") do %> <div class="govuk-grid-column-three-quarters-from-desktop">
<%= govuk_summary_list do |summary_list| %> <%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %>
<% @scheme.check_details_attributes.each do |attr| %> <% component.tab(label: "Scheme") do %>
<% next if current_user.data_coordinator? && attr[:name] == ("owned by") %> <%= govuk_summary_list do |summary_list| %>
<%= summary_list.row do |row| %> <% @scheme.check_details_attributes.each do |attr| %>
<% row.key { attr[:name].to_s } %> <% next if current_user.data_coordinator? && attr[:name] == ("owned by") %>
<% row.value { details_html(attr) } %> <%= summary_list.row do |row| %>
<% unless @scheme.confirmed? && attr[:name] != "Name" %> <% row.key { attr[:name].to_s } %>
<% row.action( <% row.value { details_html(attr) } %>
text: "Change", <% unless @scheme.confirmed? && attr[:name] != "Name" %>
href: scheme_details_path(@scheme, check_answers: true), <% row.action(
) %> text: "Change",
href: scheme_details_path(@scheme, check_answers: true),
) %>
<% end %>
<% end %>
<% end %>
<% if !@scheme.arrangement_type_same? %>
<% @scheme.check_support_services_provider_attributes.each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %>
<% row.value { details_html(attr) } %>
<% unless @scheme.confirmed? %>
<% row.action(
text: "Change",
href: scheme_support_services_provider_path(@scheme, check_answers: true),
) %>
<% end %>
<% end %> <% end %>
<% end %>
<% end %> <% end %>
<% end %> <% @scheme.check_primary_client_attributes.each do |attr| %>
<% if !@scheme.arrangement_type_same? %>
<% @scheme.check_support_services_provider_attributes.each do |attr| %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %> <% row.key { attr[:name].to_s } %>
<% row.value { details_html(attr) } %> <% row.value { details_html(attr) } %>
<% unless @scheme.confirmed? %> <% unless @scheme.confirmed? %>
<% row.action( <% row.action(
text: "Change", text: "Change",
href: scheme_support_services_provider_path(@scheme, check_answers: true), href: scheme_primary_client_group_path(@scheme, check_answers: true),
) %> ) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %>
<% @scheme.check_primary_client_attributes.each do |attr| %> <%= summary_list.row do |row| %>
<%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %>
<% row.key { attr[:name].to_s } %> <% row.value { details_html(attr) } %>
<% row.value { details_html(attr) } %> <% unless @scheme.confirmed? %>
<% unless @scheme.confirmed? %> <% row.action(
<% row.action( text: "Change",
text: "Change", href: scheme_confirm_secondary_client_group_path(@scheme, check_answers: true),
href: scheme_primary_client_group_path(@scheme, check_answers: true), ) %>
) %>
<% end %> <% end %>
<% end %>
<% end %> <% end %>
<% end %> <% if @scheme.has_other_client_group == "Yes" %>
<% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %> <% @scheme.check_secondary_client_attributes.each do |attr| %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %> <% row.key { attr[:name].to_s } %>
<% row.value { details_html(attr) } %> <% row.value { details_html(attr) } %>
<% unless @scheme.confirmed? %> <% unless @scheme.confirmed? %>
<% row.action( <% row.action(
text: "Change", text: "Change",
href: scheme_confirm_secondary_client_group_path(@scheme, check_answers: true), href: scheme_secondary_client_group_path(@scheme, check_answers: true),
) %> ) %>
<% end %>
<% end %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% @scheme.check_support_attributes.each do |attr| %>
<% if @scheme.has_other_client_group == "Yes" %>
<% @scheme.check_secondary_client_attributes.each do |attr| %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %> <% row.key { attr[:name].to_s } %>
<% row.value { details_html(attr) } %> <% row.value { details_html(attr) } %>
<% unless @scheme.confirmed? %> <% unless @scheme.confirmed? %>
<% row.action( <% row.action(
text: "Change", text: "Change",
href: scheme_secondary_client_group_path(@scheme, check_answers: true), href: scheme_support_path(@scheme, check_answers: true),
) %> ) %>
<% end %> <% end %>
<% end %>
<% end %>
<% end %>
<% @scheme.check_support_attributes.each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %>
<% row.value { details_html(attr) } %>
<% unless @scheme.confirmed? %>
<% row.action(
text: "Change",
href: scheme_support_path(@scheme, check_answers: true),
) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% component.tab(label: "Locations") do %>
<% component.tab(label: "Locations") do %> <%= govuk_table do |table| %>
<%= govuk_table do |table| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <strong><%= @scheme.locations.count %></strong> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>
<strong><%= @scheme.locations.count %></strong> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>
<% row.cell(header: true, text: "Code", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Postcode", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Units", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Common unit type", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Mobility type", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Local authority", html_attributes: {
scope: "col",
}) %>
<% end %> <% end %>
<% end %> <%= table.head do |head| %>
<% @scheme.locations.each do |location| %> <%= head.row do |row| %>
<%= table.body do |body| %> <% row.cell(header: true, text: "Code", html_attributes: {
<%= body.row do |row| %> scope: "col",
<% row.cell(text: location.id) %> }) %>
<% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(header: true, text: "Postcode", html_attributes: {
<% row.cell(text: location.units) %> scope: "col",
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %> }) %>
<% row.cell(text: location.mobility_type) %> <% row.cell(header: true, text: "Units", html_attributes: {
<% row.cell(text: location.location_admin_district) %> scope: "col",
<% end %> }) %>
<% row.cell(header: true, text: "Common unit type", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Mobility type", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Local authority", html_attributes: {
scope: "col",
}) %>
<% end %>
<% end %>
<% @scheme.locations.each do |location| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %>
<% row.cell(text: location.location_admin_district) %>
<% end %>
<% end %>
<% end %> <% end %>
<% end %> <% end %>
<%= govuk_button_link_to "Add a location", new_location_path(id: @scheme.id), secondary: true %>
<% end %> <% end %>
<%= govuk_button_link_to "Add a location", new_location_path(id: @scheme.id), secondary: true %>
<% end %> <% end %>
<% end %> </div>
</div> </div>
</div>
<%= form_for(@scheme, as: :scheme, method: :patch) do |f| %>
<%= f.hidden_field :page, value: "check-answers" %> <%= f.hidden_field :page, value: "check-answers" %>
<%= f.hidden_field :confirmed, value: "true" %> <%= f.hidden_field :confirmed, value: "true" %>
<% button_label = @scheme.confirmed? ? "Save" : "Create scheme" %> <% button_label = @scheme.confirmed? ? "Save" : "Create scheme" %>

1
spec/factories/scheme.rb

@ -10,6 +10,7 @@ FactoryBot.define do
primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
owning_organisation { FactoryBot.create(:organisation) } owning_organisation { FactoryBot.create(:organisation) }
managing_organisation { FactoryBot.create(:organisation) }
confirmed { true } confirmed { true }
created_at { Time.zone.now } created_at { Time.zone.now }
trait :export do trait :export do

Loading…
Cancel
Save