From e898a2694455f9bb731f7bc6627459fd07a0c261 Mon Sep 17 00:00:00 2001 From: Edwin Kruglov Date: Mon, 16 Oct 2023 13:40:32 +0100 Subject: [PATCH] feat(cms): add school picker to case creation Jira: PWNN-1659 --- .../school_pickers_controller.rb | 32 +++++++++++++++++++ .../support/case_requests_controller.rb | 2 +- .../school_pickers/edit.html.erb | 9 ++++++ app/views/support/case_requests/show.html.erb | 14 ++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 app/controllers/support/case_requests/school_pickers_controller.rb create mode 100644 app/views/support/case_requests/school_pickers/edit.html.erb diff --git a/app/controllers/support/case_requests/school_pickers_controller.rb b/app/controllers/support/case_requests/school_pickers_controller.rb new file mode 100644 index 000000000..b69abda84 --- /dev/null +++ b/app/controllers/support/case_requests/school_pickers_controller.rb @@ -0,0 +1,32 @@ +module Support + module CaseRequests + class SchoolPickersController < ApplicationController + before_action :case_request, only: %i[edit update] + + def edit + @back_url = params[:source] == "change_link" ? support_case_request_path(@case_request) : edit_support_case_request_path(@case_request) + @school_picker = @case_request.school_picker + @group = @case_request.organisation + @all_schools = @group.organisations.order(:name) + @filters = @all_schools.filtering(form_params[:filters] || {}) + @filtered_schools = @filters.results.map { |s| Support::OrganisationPresenter.new(s) } + end + + def update + @school_picker = @case_request.school_picker(school_urns: form_params[:school_urns].compact_blank.excluding("all")) + @school_picker.save! + redirect_to support_case_request_path(@case_request) + end + + private + + def case_request + @case_request = CaseRequest.find_by(id: params[:id]) + end + + def form_params + params.fetch(:case_request, {}).permit(filters: params.key?(:clear) ? nil : { local_authorities: [], phases: [] }, school_urns: []) + end + end + end +end diff --git a/app/controllers/support/case_requests_controller.rb b/app/controllers/support/case_requests_controller.rb index e92281e2e..93f4eda40 100644 --- a/app/controllers/support/case_requests_controller.rb +++ b/app/controllers/support/case_requests_controller.rb @@ -20,7 +20,7 @@ def update if @case_request.valid? @case_request.save! - redirect_to support_case_request_path(@case_request) + redirect_to(@case_request.eligible_for_school_picker? && @case_request.school_urns.empty? ? edit_support_case_request_school_picker_path(@case_request) : support_case_request_path(@case_request)) else render :edit end diff --git a/app/views/support/case_requests/school_pickers/edit.html.erb b/app/views/support/case_requests/school_pickers/edit.html.erb new file mode 100644 index 000000000..1eab73a7d --- /dev/null +++ b/app/views/support/case_requests/school_pickers/edit.html.erb @@ -0,0 +1,9 @@ +

<%= I18n.t("support.case_hub_migration.school_picker.title") %>

+ +<%= render "components/school_picker/school_picker", + results_model: @school_picker, + filters_model: @filters, + scope: :case_request, + update_url: support_case_request_school_picker_path(@case_request), + filters_url: edit_support_case_request_school_picker_path(@case_request), + method: :patch %> diff --git a/app/views/support/case_requests/show.html.erb b/app/views/support/case_requests/show.html.erb index 6c61800e6..3d853584f 100644 --- a/app/views/support/case_requests/show.html.erb +++ b/app/views/support/case_requests/show.html.erb @@ -72,6 +72,20 @@ <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %> + + <% if @case_request.multischool? %> +
+
+ <%= I18n.t("support.case_hub_migration.label.participating_schools") %> +
+
+ <%= I18n.t("support.case_hub_migration.label.school_number", selected: @case_request.school_urns.count, total: @case_request.organisation.organisations.length ) %> +
+
+ <%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_school_picker_path(source: :change_link), class: "govuk-link govuk-link--no-visited-state" %> +
+
+ <% end %>