Skip to content

Commit

Permalink
LUPEYALPHA-786 - add courses to check your answers part one
Browse files Browse the repository at this point in the history
  • Loading branch information
kenfodder committed Jul 31, 2024
1 parent 4dc7151 commit c100c3b
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 19 deletions.
83 changes: 68 additions & 15 deletions app/models/journeys/further_education_payments/answers_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Journeys
module FurtherEducationPayments
class AnswersPresenter < BaseAnswersPresenter
include ActionView::Helpers::TranslationHelper
include CoursesHelper

# Formats the eligibility as a list of questions and answers, each
# accompanied by a slug for changing the answer. Suitable for playback to
Expand All @@ -20,6 +21,13 @@ def eligibility_answers
a << teaching_hours_per_week
a << further_education_teaching_start_year
a << subjects_taught
a << building_construction_courses
a << chemistry_courses
a << computing_courses
a << early_years_courses
a << engineering_manufacturing_courses
a << maths_courses
a << physics_courses
a << hours_teaching_eligible_subjects
a << half_teaching_hours
a << teaching_qualification
Expand All @@ -41,49 +49,49 @@ def payroll_gender
def teaching_responsibilities
[
t("further_education_payments.forms.teaching_responsibilities.question"),
(journey_session.answers.teaching_responsibilities? ? "Yes" : "No"),
(answers.teaching_responsibilities? ? "Yes" : "No"),
"teaching-responsibilities"
]
end

def school
[
t("further_education_payments.forms.further_education_provision_search.question"),
journey_session.answers.school.name,
answers.school.name,
"further-education-provision-search"
]
end

def contract_type
[
t("further_education_payments.forms.contract_type.question", school_name: journey_session.answers.school.name),
t(journey_session.answers.contract_type, scope: "further_education_payments.forms.contract_type.options"),
t("further_education_payments.forms.contract_type.question", school_name: answers.school.name),
t(answers.contract_type, scope: "further_education_payments.forms.contract_type.options"),
"contract-type"
]
end

def teaching_hours_per_week
[
t("further_education_payments.forms.teaching_hours_per_week.question", school_name: journey_session.answers.school.name),
t(journey_session.answers.teaching_hours_per_week, scope: "further_education_payments.forms.teaching_hours_per_week.options"),
t("further_education_payments.forms.teaching_hours_per_week.question", school_name: answers.school.name),
t(answers.teaching_hours_per_week, scope: "further_education_payments.forms.teaching_hours_per_week.options"),
"teaching-hours-per-week"
]
end

def hours_teaching_eligible_subjects
[
t("further_education_payments.forms.hours_teaching_eligible_subjects.question"),
(journey_session.answers.hours_teaching_eligible_subjects? ? "Yes" : "No"),
(answers.hours_teaching_eligible_subjects? ? "Yes" : "No"),
"hours-teaching-eligible-subjects"
]
end

def further_education_teaching_start_year
# TODO: pre-xxxx is an ineligible state so this conditional can be removed when the eligility checking is added, it won't be used
answer = if journey_session.answers.further_education_teaching_start_year =~ /pre-(\d{4})/
answer = if answers.further_education_teaching_start_year =~ /pre-(\d{4})/
t("further_education_payments.forms.further_education_teaching_start_year.options.before_date", year: $1)
else
start_year = journey_session.answers.further_education_teaching_start_year.to_i
start_year = answers.further_education_teaching_start_year.to_i
end_year = start_year + 1

t("further_education_payments.forms.further_education_teaching_start_year.options.between_dates", start_year: start_year, end_year: end_year)
Expand All @@ -97,48 +105,93 @@ def further_education_teaching_start_year
end

def subjects_taught
answers = journey_session.answers.subjects_taught.map { |subject_taught|
subjects_list = answers.subjects_taught.map { |subject_taught|
content_tag(:p, t(subject_taught, scope: "further_education_payments.forms.subjects_taught.options"), class: "govuk-body")
}.join("").html_safe

[
t("further_education_payments.forms.subjects_taught.question"),
answers,
subjects_list,
"subjects-taught"
]
end

def half_teaching_hours
[
t("further_education_payments.forms.half_teaching_hours.question"),
(journey_session.answers.half_teaching_hours? ? "Yes" : "No"),
(answers.half_teaching_hours? ? "Yes" : "No"),
"half-teaching-hours"
]
end

def teaching_qualification
[
t("further_education_payments.forms.teaching_qualification.question"),
t(journey_session.answers.teaching_qualification, scope: "further_education_payments.forms.teaching_qualification.options"),
t(answers.teaching_qualification, scope: "further_education_payments.forms.teaching_qualification.options"),
"teaching-qualification"
]
end

def subject_to_formal_performance_action
[
t("further_education_payments.forms.poor_performance.questions.performance.question"),
(journey_session.answers.subject_to_formal_performance_action? ? "Yes" : "No"),
(answers.subject_to_formal_performance_action? ? "Yes" : "No"),
"poor-performance"
]
end

def subject_to_disciplinary_action
[
t("further_education_payments.forms.poor_performance.questions.disciplinary.question"),
(journey_session.answers.subject_to_disciplinary_action? ? "Yes" : "No"),
(answers.subject_to_disciplinary_action? ? "Yes" : "No"),
"poor-performance"
]
end

def building_construction_courses
courses_for_course_field(:building_construction_courses)
end

def chemistry_courses
courses_for_course_field(:chemistry_courses)
end

def computing_courses
courses_for_course_field(:computing_courses)
end

def early_years_courses
courses_for_course_field(:early_years_courses)
end

def engineering_manufacturing_courses
courses_for_course_field(:engineering_manufacturing_courses)
end

def maths_courses
courses_for_course_field(:maths_courses)
end

def physics_courses
courses_for_course_field(:physics_courses)
end

def courses_for_course_field(course_field)
scope = "further_education_payments.forms.#{course_field}"

courses_list = answers.public_send(course_field).map { |course|
body = t("options.#{course}", scope: scope, link: link_for_course(course_field, course, link: false))
content_tag(:p, body, class: "govuk-body")
}.join("").html_safe

return nil if courses_list.empty?

[
t("further_education_payments.forms.#{course_field}.question_check_your_answers"),
courses_list,
course_field.to_s.tr("_", "-")
]
end
end
end
end
20 changes: 17 additions & 3 deletions app/models/journeys/further_education_payments/courses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,29 @@ module CoursesHelper
}
}.freeze

# Some radio button options have a link in the description
def course_option_description(course, opts = {})
course_field = opts.key?(:i18n_form_namespace) ? opts[:i18n_form_namespace] : i18n_form_namespace
args = {i18n_form_namespace: course_field}

text, url = COURSE_DESCRIPTIONS_WITH_INLINE_LINKS.dig(course_field.to_sym, course.to_sym)
args[:link] = govuk_link_to(text, url, new_tab: true) if text.present? && url.present?
args = {
i18n_form_namespace: course_field,
link: link_for_course(course_field, course)
}

# NOTE: This is expecting FormHelpers mixin if used for a specific `t()`
t("options.#{course}", args)
end

# If there is a link for course - generate one
# Pass in {link: false} to return just the text and not a link
def link_for_course(course_field, course, opts = {})
dont_link = opts[:link] == false

text, url = COURSE_DESCRIPTIONS_WITH_INLINE_LINKS.dig(course_field.to_sym, course.to_sym)
if text.present? && url.present?
dont_link ? text : govuk_link_to(text, url, new_tab: true)
end
end
end
end
end
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ en:
building_construction_courses:
<<: *courses
question: Which building and construction courses do you teach?
question_check_your_answers: Building and construction courses
options:
esfa_buildingconstruction: ESFA-funded qualifications at level 3 and below in the %{link} sector subject area
tlevel_building: T Level in building services engineering for construction
Expand All @@ -924,6 +925,7 @@ en:
chemistry_courses:
<<: *courses
question: Which chemistry courses do you teach?
question_check_your_answers: Chemistry courses
options:
alevel_chemistry: A or AS level chemistry
gcse_chemistry: GCSE chemistry
Expand All @@ -932,6 +934,7 @@ en:
computing_courses:
<<: *courses
question: Which computing courses do you teach?
question_check_your_answers: Computing courses
options:
esfa_digitalpractitioners: ESFA-funded qualifications at level 3 and below in the %{link} sector subject area
esfa_digitalusers: ESFA-funded qualifications at level 3 and below in the %{link} sector subject area
Expand All @@ -945,6 +948,7 @@ en:
early_years_courses:
<<: *courses
question: Which early years courses do you teach?
question_check_your_answers: Early years courses
options:
eylevel2: Early years practitioner (level 2) apprenticeship
eylevel3: Early years educator (level 3) apprenticeship
Expand All @@ -955,6 +959,7 @@ en:
engineering_manufacturing_courses:
<<: *courses
question: Which engineering and manufacturing courses do you teach?
question_check_your_answers: Engineering and manufacturing courses
options:
esfa_engineering: ESFA-funded qualifications at level 3 and below in the %{link} sector subject area
esfa_manufacturing: ESFA-funded qualifications at level 3 and below in the %{link} sector subject area
Expand All @@ -967,6 +972,7 @@ en:
maths_courses:
<<: *courses
question: Which maths courses do you teach?
question_check_your_answers: Maths courses
options:
esfa: ESFA-funded qualifications at level 3 and below in the %{link} sector subject area
gcse_maths:
Expand All @@ -976,6 +982,7 @@ en:
physics_courses:
<<: *courses
question: Which physics courses do you teach?
question_check_your_answers: Physics courses
options:
alevel_physics: A or AS level physics
gcse_physics: GCSE physics
Expand Down
Loading

0 comments on commit c100c3b

Please sign in to comment.