Skip to content

Commit

Permalink
Move about this course section to its own page
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed May 23, 2024
1 parent a6fd084 commit c52f041
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 70 deletions.
53 changes: 53 additions & 0 deletions app/controllers/publish/courses/about_this_course_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

module Publish
module Courses
class AboutThisCourseController < PublishController
before_action :authorise_with_pundit

def edit
@about_this_course_form = CourseAboutThisCourseForm.new(course_enrichment)

@about_this_course_form.valid? if show_errors_on_publish?
end

def update
@about_this_course_form = CourseAboutThisCourseForm.new(course_enrichment, params: about_params)

if @about_this_course_form.save!
course_updated_message I18n.t('publish.providers.about_course.edit.about_this_course')

redirect_to redirect_path
else
render :edit
end
end

private

def authorise_with_pundit
authorize provider
end

def about_params
params.require(:publish_course_about_this_course_form).permit(*CourseAboutThisCourseForm::FIELDS)
end

def course
@course ||= CourseDecorator.new(provider.courses.find_by!(course_code: params[:code]))
end

def course_enrichment
@course_enrichment ||= course.enrichments.find_or_initialize_draft
end

def redirect_path
publish_provider_recruitment_cycle_course_path(
provider.provider_code,
recruitment_cycle.year,
course.course_code
)
end
end
end
end
32 changes: 32 additions & 0 deletions app/forms/publish/course_about_this_course_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module Publish
class CourseAboutThisCourseForm < BaseProviderForm
alias course_enrichment model

FIELDS = %i[about_course].freeze

attr_accessor(*FIELDS)

delegate :recruitment_cycle_year, :provider_code, :name, to: :course

validates :about_course, presence: true
validates :about_course, words_count: { maximum: 400, message: :too_long }

def save!
if valid?
assign_attributes_to_model
course_enrichment.status = :draft if course_enrichment.rolled_over?
course_enrichment.save!
else
false
end
end

private

def compute_fields
course_enrichment.attributes.symbolize_keys.slice(*FIELDS).merge(new_attributes)
end
end
end
4 changes: 0 additions & 4 deletions app/forms/publish/course_information_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class CourseInformationForm < BaseProviderForm
alias course_enrichment model

FIELDS = %i[
about_course
interview_process
how_school_placements_work
].freeze
Expand All @@ -14,9 +13,6 @@ class CourseInformationForm < BaseProviderForm

delegate :recruitment_cycle_year, :provider_code, :name, to: :course

validates :about_course, presence: true
validates :about_course, words_count: { maximum: 400, message: :too_long }

validates :interview_process, words_count: { maximum: 250, message: :too_long }

validates :how_school_placements_work, presence: true
Expand Down
1 change: 0 additions & 1 deletion app/services/courses/copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Copy
].freeze

ABOUT_FIELDS = [
['About the course', 'about_course'],
['Interview process', 'interview_process'],
['How school placements work', 'how_school_placements_work']
].freeze
Expand Down
4 changes: 2 additions & 2 deletions app/views/publish/courses/_description_content.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"About this course",
value_provided?(course.about_course),
%w[about_course],
action_path: course.is_withdrawn? ? nil : about_publish_provider_recruitment_cycle_course_path(@provider.provider_code, course.recruitment_cycle_year, course.course_code),
action_path: course.is_withdrawn? ? nil : about_this_course_publish_provider_recruitment_cycle_course_path(@provider.provider_code, course.recruitment_cycle_year, course.course_code),
action_visually_hidden_text: "details about this course"
) %>

Expand All @@ -17,7 +17,7 @@
"Interview process",
value_provided?(course.interview_process),
%w[interview_process],
action_path: course.is_withdrawn? ? nil : "#{about_publish_provider_recruitment_cycle_course_path(@provider.provider_code, course.recruitment_cycle_year, course.course_code)}#interview-process",
action_path: course.is_withdrawn? ? nil : about_publish_provider_recruitment_cycle_course_path(@provider.provider_code, course.recruitment_cycle_year, course.course_code),
action_visually_hidden_text: "details about the interview process"
) %>

Expand Down
79 changes: 79 additions & 0 deletions app/views/publish/courses/about_this_course/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<% content_for :page_title, title_with_error_prefix(
t("publish.providers.about_course.edit.page_title", course_name_and_code: @course.name_and_code),
@about_this_course_form.errors.any?
) %>

<% if params[:copy_from].present? %>
<%= render partial: "publish/courses/copy_content_warning", locals: { copied_fields: @copied_fields } %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with(
model: @about_this_course_form,
url: about_this_course_publish_provider_recruitment_cycle_course_path(
@provider.provider_code,
@course.recruitment_cycle_year,
@course.course_code
),
data: { qa: "enrichment-form", module: "form-check-leave" },
method: :patch,
local: true
) do |f| %>

<% content_for :before_content do %>
<%= govuk_back_link_to(
back_link_path(param_form_key: f.object_name.to_sym,
params:,
provider_code: @provider.provider_code,
recruitment_cycle_year: @course.recruitment_cycle_year,
course_code: @course.course_code)
) %>
<% end %>

<%= f.govuk_error_summary %>

<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @course.name_and_code %></span>
<%= t("publish.providers.about_course.edit.about_this_course") %>
</h1>

<p class="govuk-body"><%= t("publish.providers.about_course.edit.description") %></p>

<p class="govuk-body"><%= t("publish.providers.about_course.edit.candidates_say") %></p>

<ul class="govuk-list govuk-list--bullet">
<li><%= t("publish.providers.about_course.edit.candidate_say_li_1") %></li>
<li><%= t("publish.providers.about_course.edit.candidate_say_li_2") %></li>
<li><%= t("publish.providers.about_course.edit.candidate_say_li_3") %></li>
<li><%= t("publish.providers.about_course.edit.candidate_say_li_4") %></li>
</ul>

<p class="govuk-body"><%= t("publish.providers.about_course.edit.remember_to") %></p>

<ul class="govuk-list govuk-list--bullet">
<li><%= t("publish.providers.about_course.edit.remember_to_li_1") %></li>
<li><%= t("publish.providers.about_course.edit.remember_to_li_2") %></li>
<li><%= t("publish.providers.about_course.edit.remember_to_li_3") %></li>
<li><%= t("publish.providers.about_course.edit.remember_to_li_4") %></li>
</ul>

<p class="govuk-body">
<%= govuk_link_to t("publish.providers.about_course.edit.view_examples"), course_summary_examples_path %>
</p>

<%= f.govuk_text_area(:about_course,
value: @copied_fields_values&.dig("about_course") || @about_this_course_form.about_course,
label: { text: t("publish.providers.about_course.edit.about_this_course"), size: "s" },
max_words: 400,
rows: 20) %>
<%= f.govuk_submit t("publish.providers.about_course.edit.submit_button") %>
<% end %>
</div>
</div>

<p class="govuk-body">
<%= govuk_link_to(t("cancel"), publish_provider_recruitment_cycle_course_path(@provider.provider_code,
@provider.recruitment_cycle.year,
@course.course_code)) %>
</p>
30 changes: 0 additions & 30 deletions app/views/publish/courses/course_information/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,6 @@
<%= page_title %>
</h1>

<p class="govuk-body">The course summary appears at the top of the page on Find, so it's important that candidates can quickly learn why this course is different from another.</p>

<p class="govuk-body">Tell candidates:</p>

<ul class="govuk-list govuk-list--bullet">
<li>where they’ll spend their time</li>
<li>how the course is structured</li>
<li>how they’ll be supported - for example, tutors and mentoring</li>
</ul>

<p class="govuk-body">Remember to:</p>

<ul class="govuk-list govuk-list--bullet">
<li>avoid too much detail - you can use the other sections to elaborate</li>
<li>use bullet points and paragraphs to make your content easy to read</li>
<li>spell out acronyms the first time you use them, for example, ITT, NQT, SCITT</li>
</ul>

<p class="govuk-body">
<%= govuk_link_to "View more guidance and course summary examples", course_summary_examples_path %>
</p>

<%= f.govuk_text_area(:about_course,
value: @copied_fields_values&.dig("about_course") || @course.about_course,
label: { text: "About this course", size: "s" },
max_words: 400,
rows: 20) %>

<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--l">

<h3 class="govuk-heading-m" id="interview-process">Interview process</h3>

<p class="govuk-body">
Expand Down
30 changes: 26 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ en:
course_fees:
edit:
course_fees: Course fees
about_course:
edit:
about_this_course: About this course
page_title: About this course - %{course_name_and_code}
submit_button: Update about this course
description: >
The course summary appears at the top of the page on Find. Use it to show how this course is different from
others, this helps candidates understand whether it is right for them.
candidates_say: "Candidates say the most important information is:"
candidate_say_li_1: how and where they'll spend their time
candidate_say_li_2: how the course is structured, for example which specific modules or areas are taught
candidate_say_li_3: how they'll be supported - for example, tutors and mentoring
candidate_say_li_4: the qualification and experience they will have at the end of the course.
remember_to: "Remember to:"
remember_to_li_1: keep it brief and to the point, people struggle with long blocks of writing online
remember_to_li_2: use bullet points, headings and paragraphs to make your writing easy to read
remember_to_li_3: spell out acronyms the first time you use them, for example, ITT, NQT, SCITT
remember_to_li_4: >
link to your organisation's website for people who want more detail about who you are and what you do.
view_examples: View more guidance and course summary examples
study_mode:
form:
select_all_that_apply: Select all that apply
Expand Down Expand Up @@ -564,7 +584,7 @@ en:
less_than_or_equal_to: "must be less than or equal to £100,000"
not_an_integer: "must not include pence, like 1000 or 1500"
about_course:
blank: "^Enter details about this course"
blank: "^Enter information about this course"
how_school_placements_work:
blank: "^Enter details about school placements"
required_qualifications:
Expand Down Expand Up @@ -802,11 +822,13 @@ en:
invalid: "Enter a real postcode"
urn:
format: "URN must be 5 or 6 numbers"
publish/course_information_form:
publish/course_about_this_course_form:
attributes:
about_course:
blank: "Enter details about this course"
too_long: "Reduce the word count for about course"
blank: Enter information about this course
too_long: Reduce the word count for about course
publish/course_information_form:
attributes:
interview_process:
too_long: "Reduce the word count for interview process"
how_school_placements_work:
Expand Down
2 changes: 2 additions & 0 deletions config/routes/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
get '/age_range', on: :member, to: 'courses/age_range#edit'
put '/age_range', on: :member, to: 'courses/age_range#update'

get '/about_this_course', on: :member, to: 'courses/about_this_course#edit'
patch '/about_this_course', on: :member, to: 'courses/about_this_course#update'
get '/about', on: :member, to: 'courses/course_information#edit'
patch '/about', on: :member, to: 'courses/course_information#update'
get '/requirements', on: :member, to: 'courses/requirements#edit'
Expand Down
2 changes: 0 additions & 2 deletions spec/features/publish/courses/copy_from_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def when_i_visit_the_publish_course_information_edit_page
end

def then_i_see_the_current_course_information
expect(page).to have_content(course.enrichments.first.about_course)
expect(page).to have_content(course.enrichments.first.interview_process)
expect(page).to have_content(course.enrichments.first.how_school_placements_work)
end
Expand Down Expand Up @@ -94,7 +93,6 @@ def then_i_see_an_alert_that_the_changes_are_not_saved_yet
def and_i_can_see_the_new_content
copied_course_code = @course_to_copy.match(/\((.*?)\)/)[1]
@copied_course = Course.find_by(course_code: copied_course_code)
expect(page).to have_content(@copied_course.enrichments.first.about_course)
expect(page).to have_content(@copied_course.enrichments.first.interview_process)
expect(page).to have_content(@copied_course.enrichments.first.how_school_placements_work)
end
Expand Down
Loading

0 comments on commit c52f041

Please sign in to comment.