-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move about this course section to its own page
- Loading branch information
Showing
16 changed files
with
297 additions
and
67 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
app/controllers/publish/courses/about_this_course_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.