Browse Source

WIP change update paths

pull/671/head
Kat 3 years ago committed by JG
parent
commit
00aac08f2c
  1. 96
      app/controllers/schemes_controller.rb
  2. 4
      app/views/schemes/check_answers.html.erb
  3. 4
      app/views/schemes/confirm_secondary.html.erb
  4. 5
      app/views/schemes/new.html.erb
  5. 5
      app/views/schemes/primary_client_group.html.erb
  6. 4
      app/views/schemes/secondary_client_group.html.erb
  7. 4
      app/views/schemes/support.html.erb
  8. 8
      config/routes.rb

96
app/controllers/schemes_controller.rb

@ -4,7 +4,6 @@ class SchemesController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :find_resource, except: %i[index] before_action :find_resource, except: %i[index]
before_action :find_by_scheme_id, only: %i[edit]
before_action :authenticate_scope! before_action :authenticate_scope!
def index def index
@ -31,108 +30,63 @@ class SchemesController < ApplicationController
end end
def create def create
@scheme = Scheme.create!(clean_params) @scheme = Scheme.create!(scheme_params)
@path = scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id)
render "schemes/primary_client_group" render "schemes/primary_client_group"
end end
def primary_client_group def update
@scheme = Scheme.find_by(id: params[:scheme_id]) if @scheme.update(scheme_params)
schemes_path = case params[:scheme][:page]
@path = if params[:check_answers] when "primary-client-group"
scheme_check_your_answers_path(scheme_id: @scheme.id) scheme_confirm_secondary_client_group_path(@scheme)
else when "confirm-secondary"
scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id) @scheme.has_other_client_group == "Yes" ? scheme_secondary_client_group_path(@scheme) : scheme_support_path(@scheme)
end when "secondary-client-group"
scheme_support_path(@scheme)
if params[:scheme] when "support"
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) scheme_check_answers_path(@scheme)
required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] end
@scheme.update!(required_params)
redirect_to schemes_path
else
render request.current_url, status: :unprocessable_entity
end end
end
def edit; end
def primary_client_group
render "schemes/primary_client_group" render "schemes/primary_client_group"
end end
def confirm_secondary_client_group def confirm_secondary_client_group
@scheme = Scheme.find_by(id: params[:scheme_id])
@path = params[:check_answers] ? scheme_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true) : scheme_secondary_client_group_path(scheme_id: @scheme.id)
if params[:scheme]
required_params = params.require(:scheme).permit(:primary_client_group) if params
@scheme.update!(required_params) if required_params
end
render "schemes/confirm_secondary" render "schemes/confirm_secondary"
end end
def secondary_client_group def secondary_client_group
@scheme = Scheme.find_by(id: params[:scheme_id]) render "schemes/secondary_client_group"
@path = params[:check_answers] ? scheme_check_your_answers_path(scheme_id: @scheme.id) : scheme_support_path(scheme_id: @scheme.id)
if params[:scheme]
required_params = params.require(:scheme).permit(:has_other_client_group) if params
@scheme.update!(required_params) if required_params
if @scheme.has_other_client_group == "Yes"
render("schemes/secondary_client_group")
elsif params[:check_answers]
redirect_to(scheme_check_your_answers_path(sheme_id: @scheme.id))
else
redirect_to(scheme_support_path(scheme_id: @scheme.id))
end
else
render "schemes/secondary_client_group"
end
end end
def support def support
@scheme = Scheme.find_by(id: params[:scheme_id])
if params[:scheme]
required_params = params.require(:scheme).permit(:secondary_client_group)
@scheme.update!(required_params) if required_params
end
render "schemes/support" render "schemes/support"
end end
def check_answers 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, :secondary_client_group, :primary_client_group)
required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
@scheme.update!(required_params)
end
render "schemes/check_answers" render "schemes/check_answers"
end end
def update
@scheme = Scheme.find_by(id: params[:scheme_id])
flash[:notice] = "#{@scheme.service_name} has been created."
redirect_to schemes_path
end
def edit; end
private private
def clean_params def scheme_params
required_params = params.require(:scheme).permit(:service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed) params.require(:scheme).permit(:service_name, :sensitive, :organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :confirmed, :has_other_client_group)
required_params[:sensitive] = required_params[:sensitive].to_i
required_params
end end
def search_term def search_term
params["search"] params["search"]
end end
def find_by_scheme_id
@scheme = Scheme.find_by(id: params[:scheme_id])
end
def find_resource def find_resource
@scheme = Scheme.find_by(id: params[:id]) @scheme = Scheme.find_by(id: params[:id]) || Scheme.find_by(id: params[:scheme_id])
end end
def authenticate_scope! def authenticate_scope!

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

@ -19,7 +19,7 @@
<% row.value { details_html(attr) } %> <% row.value { details_html(attr) } %>
<% row.action( <% row.action(
text: "Change", text: "Change",
href: scheme_details_path(scheme_id: @scheme.id, check_answers: true), href: schemes_path(scheme_id: @scheme.id, check_answers: true),
) %> ) %>
<% end %> <% end %>
<% end %> <% end %>
@ -67,4 +67,4 @@
<% end %> <% end %>
<% end %> <% end %>
<%= govuk_button_link_to "Create scheme", scheme_update_path, html: { method: :get } %> <%= govuk_button_link_to "Create scheme", schemes_path, html: { method: :get } %>

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

@ -9,7 +9,7 @@
<%= render partial: "organisations/headings", locals: { main: "Does this scheme provide for another client group?", sub: @scheme.service_name } %> <%= render partial: "organisations/headings", locals: { main: "Does this scheme provide for another client group?", sub: @scheme.service_name } %>
<%= form_for(@scheme, method: :patch, url: @path) do |f| %> <%= form_for(@scheme, method: :patch) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
@ -22,6 +22,8 @@
legend: nil legend: nil
%> %>
<%= f.hidden_field :page, value: "confirm-secondary" %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
</div> </div>
</div> </div>

5
app/views/schemes/new.html.erb

@ -7,7 +7,7 @@
) %> ) %>
<% end %> <% end %>
<%= form_for(@scheme, as: :scheme, method: :post, url: schemes_path(scheme: @scheme)) do |f| %> <%= form_for(@scheme, as: :scheme, method: :post) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -22,8 +22,7 @@
<%= f.govuk_check_box :sensitive, <%= f.govuk_check_box :sensitive,
1, "Yes",
0,
checked: @scheme.sensitive?, checked: @scheme.sensitive?,
multiple: false, multiple: false,
label: { text: "This scheme contains confidential information" } %> label: { text: "This scheme contains confidential information" } %>

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

@ -9,7 +9,8 @@
<%= render partial: "organisations/headings", locals: { main: "What client group is this scheme intended for?", sub: @scheme.service_name } %> <%= render partial: "organisations/headings", locals: { main: "What client group is this scheme intended for?", sub: @scheme.service_name } %>
<%= form_for(@scheme, method: :patch, url: @path) do |f| %>
<%= form_for(@scheme, method: :patch) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -24,6 +25,8 @@
:name, :name,
legend: nil %> legend: nil %>
<%= f.hidden_field :page, value: "primary-client-group" %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
</div> </div>
</div> </div>

4
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 } %> <%= render partial: "organisations/headings", locals: { main: "What is the other client group?", sub: @scheme.service_name } %>
<%= form_for(@scheme, method: :patch, url: @path) do |f| %> <%= form_for(@scheme, method: :patch) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -24,6 +24,8 @@
:name, :name,
legend: nil %> legend: nil %>
<%= f.hidden_field :page, value: "secondary-client-group" %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
</div> </div>
</div> </div>

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

@ -9,7 +9,7 @@
<%= render partial: "organisations/headings", locals: { main: "What support does this scheme provide?", sub: @scheme.service_name } %> <%= render partial: "organisations/headings", locals: { main: "What support does this scheme provide?", sub: @scheme.service_name } %>
<%= form_for(@scheme, method: :patch, url: scheme_check_your_answers_path(scheme_id: @scheme.id)) do |f| %> <%= form_for(@scheme, method: :patch) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -31,6 +31,8 @@
:name, :name,
legend: { text: "Intended length of stay", size: "m" } %> legend: { text: "Intended length of stay", size: "m" } %>
<%= f.hidden_field :page, value: "support" %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
</div> </div>
</div> </div>

8
config/routes.rb

@ -36,17 +36,11 @@ Rails.application.routes.draw do
end end
resources :schemes do resources :schemes do
patch "primary-client-group", to: "schemes#primary_client_group"
get "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_client_group"
get "confirm-secondary-client-group", to: "schemes#confirm_secondary_client_group" get "confirm-secondary-client-group", to: "schemes#confirm_secondary_client_group"
patch "secondary-client-group", to: "schemes#secondary_client_group"
get "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 "support", to: "schemes#support"
patch "check-your-answers", to: "schemes#check_answers" get "check-answers", to: "schemes#check_answers"
get "check-your-answers", to: "schemes#check_answers"
get "update", to: "schemes#update"
member do member do
get "locations", to: "schemes#locations" get "locations", to: "schemes#locations"

Loading…
Cancel
Save