From 3c1684e78ea636896a3cb96c62171dc0df88a813 Mon Sep 17 00:00:00 2001 From: CatalinVoineag <11318084+CatalinVoineag@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:58:00 +0100 Subject: [PATCH] Wip --- .../missing_information_component.rb | 2 +- app/controllers/concerns/goto_preview.rb | 1 + .../training_with_disabilities_controller.rb | 2 +- .../publish/providers_controller.rb | 49 ++++++++++++------- .../publish/about_your_organisation_form.rb | 39 +++++++++++++++ app/helpers/find/goto_preview_helper.rb | 8 +++ app/helpers/preview_helper.rb | 3 +- .../courses/_train_with_disabilities.html.erb | 2 +- app/views/publish/providers/about.html.erb | 15 +----- 9 files changed, 87 insertions(+), 34 deletions(-) diff --git a/app/components/course_preview/missing_information_component.rb b/app/components/course_preview/missing_information_component.rb index 5dcd692b6c..777073ff1f 100644 --- a/app/components/course_preview/missing_information_component.rb +++ b/app/components/course_preview/missing_information_component.rb @@ -36,7 +36,7 @@ def degree_link = degrees_start_publish_provider_recruitment_cycle_course_path(p def fee_uk_eu_link = fees_publish_provider_recruitment_cycle_course_path(provider_code, recruitment_cycle_year, course_code, goto_preview: true) def gcse_link = gcses_pending_or_equivalency_tests_publish_provider_recruitment_cycle_course_path(provider_code, recruitment_cycle_year, course_code, goto_preview: true) def how_school_placements_work_link = school_placements_publish_provider_recruitment_cycle_course_path(provider_code, recruitment_cycle_year, course_code, goto_preview: true) - def train_with_disability_link = about_publish_provider_recruitment_cycle_path(provider_code, recruitment_cycle_year, course_code:, goto_preview: true, anchor: 'train-with-disability') + def train_with_disability_link = about_publish_provider_recruitment_cycle_path(provider_code, recruitment_cycle_year, course_code:, goto_training_with_disabilities: true, anchor: 'train-with-disability') def train_with_us_link = about_publish_provider_recruitment_cycle_path(provider_code, recruitment_cycle_year, course_code:, goto_provider: true, anchor: 'train-with-us') def about_accrediting_provider_link diff --git a/app/controllers/concerns/goto_preview.rb b/app/controllers/concerns/goto_preview.rb index e4e8cd5166..6b6e26d793 100644 --- a/app/controllers/concerns/goto_preview.rb +++ b/app/controllers/concerns/goto_preview.rb @@ -9,4 +9,5 @@ def param_form_key def goto_preview? = params.dig(param_form_key, :goto_preview) == 'true' def goto_provider? = params.dig(param_form_key, :goto_provider) == 'true' + def goto_training_with_disabilities? = params.dig(param_form_key, :goto_training_with_disabilities) == 'true' end diff --git a/app/controllers/find/courses/training_with_disabilities_controller.rb b/app/controllers/find/courses/training_with_disabilities_controller.rb index 7134616190..5d8911c1d8 100644 --- a/app/controllers/find/courses/training_with_disabilities_controller.rb +++ b/app/controllers/find/courses/training_with_disabilities_controller.rb @@ -4,7 +4,7 @@ module Find module Courses class TrainingWithDisabilitiesController < Find::ApplicationController before_action -> { render_not_found if provider.nil? } - before_action -> { render_not_found if provider.train_with_disability.nil? } + before_action -> { render_not_found if provider.train_with_disability.blank? } def show @course = provider.courses.includes( diff --git a/app/controllers/publish/providers_controller.rb b/app/controllers/publish/providers_controller.rb index f1d8438794..653d50eed7 100644 --- a/app/controllers/publish/providers_controller.rb +++ b/app/controllers/publish/providers_controller.rb @@ -54,29 +54,26 @@ def details def about authorize provider, :show? - @about_form = AboutYourOrganisationForm.new(provider) + @about_form = AboutYourOrganisationForm.new( + provider, + redirect_params:, + course_code: params[:course_code] + ) end def update authorize provider, :update? - @about_form = AboutYourOrganisationForm.new(provider, params: provider_params) + @about_form = AboutYourOrganisationForm.new( + provider, + params: provider_params, + redirect_params:, + course_code: params.dig(param_form_key, :course_code) + ) if @about_form.save! - if goto_provider? - redirect_to( - provider_publish_provider_recruitment_cycle_course_path( - provider.provider_code, - provider.recruitment_cycle_year, - params[:course_code] || params.dig(param_form_key, :course_code) - ) - ) - elsif goto_preview? - redirect_to preview_publish_provider_recruitment_cycle_course_path(provider.provider_code, provider.recruitment_cycle_year, (params[:course_code] || params.dig(param_form_key, :course_code))) - else - flash[:success] = I18n.t('success.published') - redirect_to(details_publish_provider_recruitment_cycle_path(provider.provider_code, provider.recruitment_cycle_year)) - end + redirect_to @about_form.update_success_path + flash[:success] = I18n.t('success.published') if redirect_params.all? { |_k, v| v.blank? } else @errors = @about_form.errors.messages render :about @@ -124,7 +121,17 @@ def redirect_to_contact_page_with_ukprn_error def provider_params params .require(param_form_key) - .except(:goto_preview, :course_code, :goto_provider) + .except(:goto_preview, :course_code, :goto_provider, :goto_training_with_disabilities) + .permit( + *AboutYourOrganisationForm::FIELDS, + accredited_bodies: %i[provider_name provider_code description] + ) + end + + def provider_params + params + .require(param_form_key) + .except(:goto_preview, :course_code, :goto_provider, :goto_training_with_disabilities) .permit( *AboutYourOrganisationForm::FIELDS, accredited_bodies: %i[provider_name provider_code description] @@ -132,5 +139,13 @@ def provider_params end def param_form_key = :publish_about_your_organisation_form + + def redirect_params + params.fetch(param_form_key, params).slice( + :goto_preview, + :goto_provider, + :goto_training_with_disabilities + ).permit!.to_h + end end end diff --git a/app/forms/publish/about_your_organisation_form.rb b/app/forms/publish/about_your_organisation_form.rb index 669a504a85..f678eb233e 100644 --- a/app/forms/publish/about_your_organisation_form.rb +++ b/app/forms/publish/about_your_organisation_form.rb @@ -9,6 +9,11 @@ class AboutYourOrganisationForm < BaseProviderForm # validates :train_with_disability, words_count: { maximum: 250, message: 'Reduce the word count for training with disabilities and other needs' } # validate :add_enrichment_errors + def initialize(model, params: {}, redirect_params: {}, course_code: nil) + super(model, params:) + @redirect_params = redirect_params + @course_code = course_code + end FIELDS = %i[ train_with_us @@ -17,6 +22,7 @@ class AboutYourOrganisationForm < BaseProviderForm ].freeze attr_accessor(*FIELDS) + attr_reader :redirect_params, :course_code def accredited_bodies @accredited_bodies ||= provider.accredited_bodies.map do |ab| @@ -24,6 +30,35 @@ def accredited_bodies end end + def update_success_path + case redirection_key + when 'goto_preview' + preview_publish_provider_recruitment_cycle_course_path( + provider.provider_code, + provider.recruitment_cycle_year, + course_code + ) + when 'goto_provider' + provider_publish_provider_recruitment_cycle_course_path( + provider.provider_code, + provider.recruitment_cycle_year, + course_code + ) + when 'goto_training_with_disabilities' + training_with_disabilities_publish_provider_recruitment_cycle_course_path( + provider.provider_code, + provider.recruitment_cycle_year, + course_code + ) + else + details_publish_provider_recruitment_cycle_path( + provider.provider_code, + provider.recruitment_cycle_year + ) + end + end + alias back_path update_success_path + private def train_with_us_changed? @@ -81,5 +116,9 @@ class AccreditedProvider attr_accessor :provider_name, :provider_code, :description end + + def redirection_key + redirect_params.select { |_k, v| v == 'true' }&.keys&.first + end end end diff --git a/app/helpers/find/goto_preview_helper.rb b/app/helpers/find/goto_preview_helper.rb index fe136a07b0..38e0696dd7 100644 --- a/app/helpers/find/goto_preview_helper.rb +++ b/app/helpers/find/goto_preview_helper.rb @@ -18,6 +18,14 @@ def goto_provider?(param_form_key:, params:) goto_provider_value(param_form_key:, params:) == 'true' end + def goto_training_with_disabilities_value(param_form_key:, params:) + params[:goto_training_with_disabilities] || params.dig(param_form_key, :goto_training_with_disabilities) + end + + def goto_training_with_disabilities?(param_form_key:, params:) + goto_training_with_disabilities_value(param_form_key:, params:) == 'true' + end + def back_link_path(param_form_key:, params:, provider_code:, recruitment_cycle_year:, course_code:) if goto_preview?(param_form_key:, params:) preview_publish_provider_recruitment_cycle_course_path(provider_code, recruitment_cycle_year, course_code) diff --git a/app/helpers/preview_helper.rb b/app/helpers/preview_helper.rb index e38c033fc1..1cc9f5baac 100644 --- a/app/helpers/preview_helper.rb +++ b/app/helpers/preview_helper.rb @@ -4,6 +4,7 @@ module PreviewHelper def preview?(params) params[:action] == 'preview' || params[:action].nil? || - (params[:controller] == 'publish/courses/providers' && params[:action] == 'show') + (params[:controller] == 'publish/courses/providers' && params[:action] == 'show') || + (params[:controller] == 'publish/courses/training_with_disabilities' && params[:action] == 'show') end end diff --git a/app/views/find/courses/_train_with_disabilities.html.erb b/app/views/find/courses/_train_with_disabilities.html.erb index f3e02b136b..b120ab60f4 100644 --- a/app/views/find/courses/_train_with_disabilities.html.erb +++ b/app/views/find/courses/_train_with_disabilities.html.erb @@ -4,7 +4,7 @@ <% if course.provider.train_with_disability.present? %> <%= markdown(course.provider.train_with_disability) %> <% else %> - <%= render CoursePreview::MissingInformationComponent.new(course:, information_type: :train_with_disability, is_preview: true)%>#preview?(params)) %> + <%= render CoursePreview::MissingInformationComponent.new(course:, information_type: :train_with_disability, is_preview: preview?(params)) %> <% end %> diff --git a/app/views/publish/providers/about.html.erb b/app/views/publish/providers/about.html.erb index e71285c913..9bda4a59be 100644 --- a/app/views/publish/providers/about.html.erb +++ b/app/views/publish/providers/about.html.erb @@ -10,19 +10,7 @@ ) do |f| %> <% content_for :before_content do %> - <% if goto_provider?(param_form_key: f.object_name.to_sym, params:) %> - <%= govuk_back_link_to( - provider_publish_provider_recruitment_cycle_course_path( - @provider.provider_code, - @provider.recruitment_cycle_year, - params[:course_code] || params.dig(f.object_name.to_sym, :course_code) - ) - ) %> - <% elsif goto_preview?(param_form_key: f.object_name.to_sym, params:) %> - <%= govuk_back_link_to(preview_publish_provider_recruitment_cycle_course_path(@provider.provider_code, @provider.recruitment_cycle_year, (params[:course_code] || params.dig(f.object_name.to_sym, :course_code)))) %> - <% else %> - <%= govuk_back_link_to(details_publish_provider_recruitment_cycle_path(@provider.provider_code, @provider.recruitment_cycle_year)) %> - <% end %> + <%= govuk_back_link_to(@about_form.back_path) %> <% end %> <%= f.govuk_error_summary %> @@ -75,6 +63,7 @@ rows: 15) %> <%= f.hidden_field(:goto_preview, value: goto_preview_value(param_form_key: f.object_name.to_sym, params:)) %> <%= f.hidden_field(:goto_provider, value: goto_provider_value(param_form_key: f.object_name.to_sym, params:)) %> + <%= f.hidden_field(:goto_training_with_disabilities, value: goto_training_with_disabilities_value(param_form_key: f.object_name.to_sym, params:)) %> <%= f.hidden_field(:course_code, value: params[:course_code] || params.dig(f.object_name.to_sym, :course_code)) %> <%= f.govuk_submit "Save and publish" %>