Browse Source

working spike

pull/671/head
JG 3 years ago
parent
commit
82e2b859b4
  1. 9
      app/controllers/schemes_controller.rb
  2. 37
      app/models/scheme.rb
  3. 36
      app/views/schemes/check_answers.html.erb
  4. 2
      app/views/schemes/primary_client_group.html.erb
  5. 2
      app/views/schemes/secondary_client_group.html.erb
  6. 6
      config/routes.rb

9
app/controllers/schemes_controller.rb

@ -33,12 +33,18 @@ class SchemesController < ApplicationController
def create
@scheme = Scheme.new(clean_params)
@scheme.save
@path = scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id)
render "schemes/primary_client_group"
end
def primary_client_group
@scheme = Scheme.find_by(id: params[:scheme_id])
if params[:check_answers]
@path = scheme_check_your_answers_path(scheme_id: @scheme.id)
else
@path = scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id)
end
render "schemes/primary_client_group"
end
@ -53,6 +59,7 @@ class SchemesController < ApplicationController
def secondary_client_group
@scheme = Scheme.find_by(id: params[:scheme_id])
@path = params[:check_answers] ? scheme_check_your_answers_path(scheme_id: @scheme.id) : scheme_support_path(scheme_id: @scheme.id)
if params[:confirmed]
params[:confirmed][:selection] == "Yes" ? render("schemes/secondary_client_group") : render("schemes/support")
else
@ -77,7 +84,7 @@ class SchemesController < ApplicationController
def check_answers
@scheme = Scheme.find_by(id: params[:scheme_id])
if params[:scheme]
required_params = params.require(:scheme).permit(:intended_stay, :support_type, :service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed)
required_params = params.require(:scheme).permit(:intended_stay, :support_type, :service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed, :secondary_client_group, :primary_client_group)
required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
@scheme.update(required_params)
end

37
app/models/scheme.rb

@ -8,7 +8,12 @@ class Scheme < ApplicationRecord
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(search_by_code(param)).distinct }
enum sensitive: [:no, :yes]
SENSITIVE= {
No: 0,
Yes: 1,
}.freeze
enum sensitive: SENSITIVE, _suffix: true
REGISTERED_UNDER_CARE_ACT = {
"No": 0,
@ -74,6 +79,36 @@ class Scheme < ApplicationRecord
enum intended_stay: INTENDED_STAY, _suffix: true
def check_details_attributes
[
{ name: "Service code", value: code },
{ name: "Name", value: service_name },
{ name: "Confidential information", value: sensitive },
{ name: "Managed by", value: organisation.name },
{ name: "Type of scheme", value: scheme_type },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act },
{ name: "Total number of units", value: total_units },
]
end
def check_primary_client_attributes
[
{ name: "Primary client group", value: primary_client_group },
]
end
def check_secondary_client_attributes
[
{ name: "Secondary client group", value: secondary_client_group },
]
end
def check_support_attributes
[
{ name: "Level of support given", value: support_type },
{ name: "Intended length of stay", value: intended_stay },
]
end
def display_attributes
[

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

@ -12,13 +12,43 @@
<%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %>
<% component.tab(label: 'Scheme') do %>
<%= govuk_summary_list do |summary_list| %>
<% @scheme.display_attributes.each do |attr| %>
<% @scheme.check_details_attributes.each do |attr| %>
<%= 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].to_s } %>
<% row.value { details_html(attr) } %>
<% row.action(
text: "Change",
href: scheme_details_path(scheme_id: @scheme.id),
href: scheme_details_path(scheme_id: @scheme.id, check_answers: true),
) %>
<% end %>
<% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %>
<% row.value { details_html(attr) } %>
<% row.action(
text: "Change",
href: scheme_primary_client_group_path(scheme_id: @scheme.id, check_answers: true),
) %>
<% end %>
<% end %>
<% @scheme.check_secondary_client_attributes.each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s } %>
<% row.value { details_html(attr) } %>
<% row.action(
text: "Change",
href: scheme_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true),
) %>
<% 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) } %>
<% row.action(
text: "Change",
href: scheme_support_path(scheme_id: @scheme.id, check_answers: true),
) %>
<% end %>
<% end %>

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

@ -9,7 +9,7 @@
<%= render partial: "organisations/headings", locals: { main: "What client group is this scheme intended for?", sub: @scheme.service_name } %>
<%= form_for(@scheme, method: :patch, url: scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id)) do |f| %>
<%= form_for(@scheme, method: :patch, url: @path) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>

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

@ -9,7 +9,7 @@
<%= render partial: "organisations/headings", locals: { main: "What is the other client group?", sub: @scheme.service_name } %>
<%= form_for(@scheme, method: :patch, url: scheme_support_path(scheme_id: @scheme.id)) do |f| %>
<%= form_for(@scheme, method: :patch, url: @path) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>

6
config/routes.rb

@ -38,16 +38,16 @@ Rails.application.routes.draw do
resources :schemes do
patch "primary-client-group", to: "schemes#primary_client_group"
get "primary-client-group", to: "schemes#primary_client_group"
patch "confirm-secondary-client-group", to: "schemes#confirm_secondary_group"
get "confirm-secondary-client-group", to: "schemes#confirm_secondary_group"
patch "secondary-client-group", to: "schemes#secondary_client_group"
get "secondary-client-group", to: "schemes#secondary_client_group"
patch "support", to: "schemes#support"
get "support", to: "schemes#support"
get "update", to: "schemes#update"
get "details", to: "schemes#details"
patch "check-your-answers", to: "schemes#check_answers"
get "check-your-answers", to: "schemes#check_answers"
patch "confirm-secondary-client-group", to: "schemes#confirm_secondary_group"
get "confirm-secondary-client-group", to: "schemes#confirm_secondary_group"
get "update", to: "schemes#update"
member do
get "locations", to: "schemes#locations"

Loading…
Cancel
Save