Browse Source

Allow editing locations

pull/2084/head
Kat 2 years ago
parent
commit
d119b1a4f3
  1. 8
      app/controllers/locations_controller.rb
  2. 1
      app/models/scheme.rb
  3. 3
      app/views/locations/mobility_standards.html.erb
  4. 3
      app/views/locations/postcode.html.erb
  5. 4
      app/views/locations/show.html.erb
  6. 3
      app/views/locations/type_of_unit.html.erb
  7. 3
      app/views/locations/units.html.erb
  8. 2
      app/views/schemes/check_answers.html.erb
  9. 19
      app/views/schemes/show.html.erb
  10. 18
      spec/features/schemes_spec.rb
  11. 21
      spec/requests/schemes_controller_spec.rb

8
app/controllers/locations_controller.rb

@ -40,6 +40,8 @@ class LocationsController < ApplicationController
redirect_to scheme_location_local_authority_path(@scheme, @location, route: params[:route], referrer: params[:referrer])
elsif return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_name_path(@scheme, @location, route: params[:route])
end
@ -88,6 +90,8 @@ class LocationsController < ApplicationController
if @location.save(context: :units)
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_type_of_unit_path(@scheme, @location, route: params[:route])
end
@ -103,6 +107,8 @@ class LocationsController < ApplicationController
if @location.save(context: :type_of_unit)
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route])
end
@ -118,6 +124,8 @@ class LocationsController < ApplicationController
if @location.save(context: :mobility_type)
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route])
end

1
app/models/scheme.rb

@ -188,6 +188,7 @@ class Scheme < ApplicationRecord
[
{ name: "Scheme code", value: id_to_display, id: "id" },
{ name: "Name", value: service_name, id: "service_name", edit: true },
{ name: "Status", value: status, id: "status" },
{ name: "Confidential information", value: sensitive, id: "sensitive", edit: true },
{ name: "Type of scheme", value: scheme_type, id: "scheme_type", edit: true },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act", edit: true },

3
app/views/locations/mobility_standards.html.erb

@ -24,6 +24,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", scheme_location_availability_path(@scheme, @location), secondary: true %>

3
app/views/locations/postcode.html.erb

@ -26,6 +26,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", scheme_location_name_path(@scheme, @location), secondary: true %>

4
app/views/locations/show.html.erb

@ -19,7 +19,11 @@
<% row.key { attr[:name] } %>
<% row.value { attr[:attribute].eql?("status") ? status_tag_from_resource(@location) : details_html(attr) } %>
<% if LocationPolicy.new(current_user, @location).update? %>
<% row.action(text: "Change", href: scheme_location_postcode_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "postcode" && current_user.support? %>
<% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %>
<% row.action(text: "Change", href: scheme_location_units_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "units" && current_user.support? %>
<% row.action(text: "Change", href: scheme_location_type_of_unit_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "type_of_unit" && current_user.support? %>
<% row.action(text: "Change", href: scheme_location_mobility_standards_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "mobility_standards" && current_user.support? %>
<% end %>
<% end %>
<% end %>

3
app/views/locations/type_of_unit.html.erb

@ -23,6 +23,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", scheme_location_mobility_standards_path(@scheme, @location), secondary: true %>

3
app/views/locations/units.html.erb

@ -23,6 +23,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", scheme_location_type_of_unit_path(@scheme, @location), secondary: true %>

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

@ -9,7 +9,7 @@
<h2 class="govuk-visually-hidden">Scheme</h2>
<dl class="govuk-summary-list">
<% @scheme.check_details_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(@scheme) } %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(@scheme) } unless attr[:name] == "Status" %>
<% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %>

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

@ -21,8 +21,20 @@
<h2 class="govuk-visually-hidden">Scheme</h2>
<dl class="govuk-summary-list">
<% @scheme.check_details_attributes.each do |attr| %>
<% if attr[:name] == "Status" %>
<div class="govuk-summary-list__row govuk-summary-list__row--no-actions">
<dt class="govuk-summary-list__key">Status</dt>
<dd class="govuk-summary-list__value">
<%= details_html({ name: "Status", value: status_tag_from_resource(@scheme), id: "status" }) %>
<% if @scheme.confirmed? && @scheme.locations.confirmed.none? && LocationPolicy.new(current_user, @scheme.locations.new).create? %>
<span class="app-!-colour-muted">Complete this scheme by adding a location using the <%= govuk_link_to("‘locations’ tab", scheme_locations_path(@scheme)) %>.</span>
<% end %>
</dd>
</div>
<% else %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(scheme_id: @scheme.id) } %>
<% end %>
<% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_primary_client_group_path(@scheme, check_answers: true) } %>
@ -41,6 +53,13 @@
<% @scheme.check_support_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_support_path(@scheme, check_answers: true) } %>
<% end %>
<div class="govuk-summary-list__row govuk-summary-list__row--no-actions">
<dt class="govuk-summary-list__key">Availability</dt>
<dd class="govuk-summary-list__value">
<%= details_html({ name: "Availability", value: scheme_availability(@scheme), id: "availability" }) %>
</dd>
</div>
</dl>
</div>
</div>

18
spec/features/schemes_spec.rb

@ -377,9 +377,9 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content("has been added")
end
it "does not let you edit the saved location" do
it "lets you edit the saved location" do
click_link "AA1 2AA"
expect(page).not_to have_link(nil, href: /postcode/)
expect(page).to have_link("Change", href: /postcode/)
end
end
@ -607,7 +607,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays changed location" do
click_link "AA1 2AA"
click_link "Change"
click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first)
fill_in with: "new name"
click_button "Save changes"
expect(page).to have_content "AA1 2AA"
@ -864,10 +864,10 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content("Active")
end
it "only allows to edit the location name" do
assert_selector "a", text: "Change", count: 1
it "only allows to edit the location name, postcode, unit, unit type and mobility standards" do
assert_selector "a", text: "Change", count: 5
click_link("Change")
click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first)
expect(page).to have_content "What is the name of this location?"
end
@ -889,7 +889,7 @@ RSpec.describe "Schemes scheme Features" do
context "and I change the location name" do
before do
click_link("Change")
click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first)
end
it "returns to locations check your answers page and shows the new name" do
@ -1008,9 +1008,9 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content("has been added")
end
it "does not let you edit the saved location" do
it "lets you edit the saved location" do
click_link "AA1 2AA"
expect(page).not_to have_link(nil, href: /postcode/)
expect(page).to have_link("Change", href: /postcode/)
end
end

21
spec/requests/schemes_controller_spec.rb

@ -1832,12 +1832,9 @@ RSpec.describe SchemesController, type: :request do
get "/schemes/#{scheme.id}/primary-client-group"
end
it "redirects to a view scheme page" do
follow_redirect!
it "allows editing the primary client group" do
expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 3
expect(path).to match("/schemes/#{scheme.id}/primary-client-group")
end
end
end
@ -1912,12 +1909,9 @@ RSpec.describe SchemesController, type: :request do
get "/schemes/#{scheme.id}/confirm-secondary-client-group"
end
it "redirects to a view scheme page" do
follow_redirect!
it "allows updating secondary client group" do
expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 3
expect(path).to match("/schemes/#{scheme.id}/confirm-secondary-client-group")
end
end
end
@ -1992,12 +1986,9 @@ RSpec.describe SchemesController, type: :request do
get "/schemes/#{scheme.id}/secondary-client-group"
end
it "redirects to a view scheme page" do
follow_redirect!
it "allows editing secondary client group" do
expect(response).to have_http_status(:ok)
expect(path).to match("/schemes/#{scheme.id}")
expect(page).to have_content(scheme.service_name)
assert_select "a", text: /Change/, count: 3
expect(path).to match("/schemes/#{scheme.id}/secondary-client-group")
end
end

Loading…
Cancel
Save