Skip to content

Commit

Permalink
Merge pull request #4358 from DFE-Digital/cv/couse-training-with-diss…
Browse files Browse the repository at this point in the history
…abilities

Training with disabilities view on courses
  • Loading branch information
CatalinVoineag authored Jul 11, 2024
2 parents 04713c0 + d30f7bf commit 87ba27f
Show file tree
Hide file tree
Showing 25 changed files with 396 additions and 114 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<% end %>
<li><%= govuk_link_to "International candidates", "#section-international-students" %></li>
<% if provider.train_with_disability.present? || preview? %>
<li><%= govuk_link_to "Training with disabilities and other needs", "#section-train-with-disabilities" %></li>
<li><%= govuk_link_to "Training with disabilities", "#section-train-with-disabilities" %></li>
<% end %>
<li><%= govuk_link_to "Support and advice", "#section-advice" %></li>
<% if course.application_status_open? %> <li><%= govuk_link_to "Apply", "#section-apply" %></li> <% end %>
Expand Down
1 change: 0 additions & 1 deletion app/controllers/concerns/goto_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ def param_form_key
end

def goto_preview? = params.dig(param_form_key, :goto_preview) == 'true'
def goto_provider? = params.dig(param_form_key, :goto_provider) == 'true'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

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.blank? }

def show
@course = provider.courses.includes(
:enrichments,
subjects: [:financial_incentive],
site_statuses: [:site]
).find_by!(course_code: params[:course_code]&.upcase).decorate
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Publish
module Courses
class TrainingWithDisabilitiesController < PublishController
include CourseBasicDetailConcern
before_action :build_course, only: %i[show]

def show; end

private

def build_course
super
authorize @course
end
end
end
end
39 changes: 22 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,21 @@ 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 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
42 changes: 42 additions & 0 deletions app/forms/publish/about_your_organisation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Publish
class AboutYourOrganisationForm < BaseProviderForm
include Rails.application.routes.url_helpers

validates :train_with_us, presence: { message: 'Enter details about training with you' }, if: :train_with_us_changed?
validates :train_with_disability, presence: { message: 'Enter details about training with a disability' }, if: :train_with_disability_changed?

Expand All @@ -10,20 +12,56 @@ class AboutYourOrganisationForm < BaseProviderForm

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
train_with_disability
accrediting_provider_enrichments
].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 +119,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
4 changes: 2 additions & 2 deletions app/helpers/find/goto_preview_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def goto_provider_value(param_form_key:, params:)
params[:goto_provider] || params.dig(param_form_key, :goto_provider)
end

def goto_provider?(param_form_key:, params:)
goto_provider_value(param_form_key:, params:) == 'true'
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 back_link_path(param_form_key:, params:, 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
19 changes: 10 additions & 9 deletions app/views/find/courses/_train_with_disabilities.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<div class="govuk-!-margin-bottom-8">
<h2 class="govuk-heading-l" id="section-train-with-disabilities">Training with disabilities and other needs</h2>
<div data-qa="course__train_with_disabilities">
<% 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: preview?(params)) %>
<% end %>
</div>
<h1 class="govuk-heading-xl" id="section-train-with-disabilities">
<%= t(".heading", provider_name: course.provider_name) %>
</h1>

<div data-qa="course__train_with_disabilities">
<% 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: preview?(params)) %>
<% end %>
</div>
14 changes: 13 additions & 1 deletion app/views/find/courses/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@
<%= render Find::Courses::InternationalStudentsComponent::View.new(course: @course) %>

<% if @provider.train_with_disability.present? %>
<%= render partial: "find/courses/train_with_disabilities", locals: { course: @course } %>
<h2 class="govuk-heading-l" id="section-train-with-disabilities">
<%= t(".training_with_disabilities") %>
</h2>

<p class="govuk-body">
<%= govuk_link_to(
t(".training_with_disabilities_link", provider_name: @course.provider_name),
find_training_with_disabilities_path(
@course.provider_code,
@course.course_code
)
) %>
</p>
<% end %>

<%= render partial: "find/courses/advice", locals: { course: @course } %>
Expand Down
29 changes: 29 additions & 0 deletions app/views/find/courses/training_with_disabilities/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%= content_for :page_title do %>
<%= t(".heading", provider_name: @course.provider_name) %>
<% end %>
<% content_for :before_content do %>
<%= govuk_back_link(
href: search_ui_course_page_url(
provider_code: @course.provider_code,
course_code: @course.course_code
),
text: t(
".back",
course_name: @course.name,
course_code: @course.course_code
)
) %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render partial: "find/courses/train_with_disabilities", locals: { course: @course } %>

<p class="govuk-body">
<%= govuk_link_to(
t(".contact", provider_name: @course.provider_name),
find_provider_path(@course.provider_code, @course.course_code)
) %>
</p>
</div>
</div>
15 changes: 14 additions & 1 deletion app/views/publish/courses/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,20 @@

<%= render Find::Courses::InternationalStudentsComponent::View.new(course:) %>

<%= render partial: "find/courses/train_with_disabilities", locals: { course: } %>
<h2 class="govuk-heading-l" id="section-train-with-disabilities">
<%= t(".training_with_disabilities") %>
</h2>

<p class="govuk-body">
<%= govuk_link_to(
t(".training_with_disabilities_link", provider_name: course.provider_name),
training_with_disabilities_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
) %>
</p>

<%= render partial: "find/courses/advice", locals: { course: } %>

Expand Down
34 changes: 34 additions & 0 deletions app/views/publish/courses/training_with_disabilities/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%= content_for :page_title do %>
<%= t(".heading", provider_name: @course.provider_name) %>
<% end %>
<% content_for :before_content do %>
<%= govuk_back_link(
href: preview_publish_provider_recruitment_cycle_course_path(
@course.provider_code,
@course.recruitment_cycle_year,
@course.course_code
),
text: t(
".back",
course_name: @course.name,
course_code: @course.course_code
)
) %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render partial: "find/courses/train_with_disabilities", locals: { course: } %>

<p class="govuk-body">
<%= govuk_link_to(
t(".contact", provider_name: @course.provider_name),
provider_publish_provider_recruitment_cycle_course_path(
@course.provider_code,
@course.recruitment_cycle_year,
@course.course_code
)
) %>
</p>
</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
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ en:
add: "Add user"
update: "Update user"
publish:
courses:
training_with_disabilities:
show:
heading: Training with disabilities and other needs at %{provider_name}
back: Back to %{course_name} (%{course_code})
contact: Contact %{provider_name}
preview:
training_with_disabilities: Training with disabilities
training_with_disabilities_link: Find out about training with disabilities and other needs at %{provider_name}.
providers:
courses:
accredited_provider:
Expand Down
Loading

0 comments on commit 87ba27f

Please sign in to comment.