Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CatalinVoineag committed Jul 10, 2024
1 parent 88cd189 commit 3c1684e
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/goto_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
49 changes: 32 additions & 17 deletions app/controllers/publish/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -124,13 +121,31 @@ 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]
)
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
39 changes: 39 additions & 0 deletions app/forms/publish/about_your_organisation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,13 +22,43 @@ class AboutYourOrganisationForm < BaseProviderForm
].freeze

attr_accessor(*FIELDS)
attr_reader :redirect_params, :course_code

def accredited_bodies
@accredited_bodies ||= provider.accredited_bodies.map do |ab|
accredited_provider(**ab)
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?
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions app/helpers/find/goto_preview_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/preview_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/views/find/courses/_train_with_disabilities.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
</div>
</div>
15 changes: 2 additions & 13 deletions app/views/publish/providers/about.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down Expand Up @@ -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" %>
Expand Down

0 comments on commit 3c1684e

Please sign in to comment.