Skip to content

Commit

Permalink
Merge pull request #4428 from DFE-Digital/2084-tda-find-update-initia…
Browse files Browse the repository at this point in the history
…l-questions-and-filters-on-find

TDA find - Add undergraduate courses to find (for 2025 cycle)
  • Loading branch information
tomas-stefano authored Aug 15, 2024
2 parents c4fa0db + 3d865c1 commit ec7ddf0
Show file tree
Hide file tree
Showing 24 changed files with 921 additions and 35 deletions.
1 change: 1 addition & 0 deletions app/controllers/concerns/filter_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def form_params
:engineers_teach_physics,
:funding,
:has_vacancies,
:university_degree_status,
:applications_open,
:l,
:latitude,
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/find/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@ def render_feedback_component
@render_feedback_component = true
end

def backlink_query_parameters
ResultsView.new(
query_parameters: request.query_parameters[form_name].presence || request.query_parameters
)
.query_parameters_with_defaults
.except(form_name)
end

# DFE Analytics namespace
def current_namespace
'find'
end

def teacher_degree_apprenticeship_active?
Settings.current_recruitment_cycle_year.to_i > 2024 && FeatureService.enabled?(:teacher_degree_apprenticeship)
end

private

def provider
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Find
module Search
class NoDegreeAndRequiresVisaSponsorshipController < Find::ApplicationController
def back_path
find_visa_status_path(backlink_query_parameters)
end
helper_method :back_path

# this controller is an exit page, so returning the latest form
def form_name = :find_visa_status_form
end
end
end
10 changes: 9 additions & 1 deletion app/controllers/find/search/subjects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ def create
@subjects_form = SubjectsForm.new(subjects: sanitised_subject_codes, age_group: form_params[:age_group])

if @subjects_form.valid?
redirect_to find_visa_status_path(filter_params[:find_subjects_form])
redirect_to next_page
else
render :new
end
end

private

def next_page
if teacher_degree_apprenticeship_active?
find_university_degree_status_path(filter_params[:find_subjects_form])
else
find_visa_status_path(filter_params[:find_subjects_form])
end
end

def sanitised_subject_codes
form_params['subjects'].compact_blank!
end
Expand Down
34 changes: 34 additions & 0 deletions app/controllers/find/search/university_degree_status_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Find
module Search
class UniversityDegreeStatusController < Find::ApplicationController
include FilterParameters

def new
@university_degree_status_form = UniversityDegreeStatusForm.new(
university_degree_status: params[:university_degree_status]
)
end

def create
@university_degree_status_form = UniversityDegreeStatusForm.new(
university_degree_status: form_params[:university_degree_status]
)

if @university_degree_status_form.valid?
redirect_to find_visa_status_path(filter_params[:find_university_degree_status_form])
else
render :new
end
end

def form_name = :find_university_degree_status_form

def back_path
find_subjects_path(backlink_query_parameters)
end
helper_method :back_path
end
end
end
52 changes: 33 additions & 19 deletions app/controllers/find/search/visa_status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,63 @@ class VisaStatusController < Find::ApplicationController
include DefaultVacancies
include DefaultApplicationsOpen

before_action :build_backlink_query_parameters
helper_method :back_path

def new
@visa_status_form = VisaStatusForm.new(visa_status: params[:visa_status])
end

def create
@visa_status_form = VisaStatusForm.new(visa_status: form_params[:visa_status])
@visa_status_form = VisaStatusForm.new(
visa_status: form_params[:visa_status]
)

if @visa_status_form.valid?
redirect_to find_results_path(form_params.merge(
subjects: sanitised_subject_codes,
has_vacancies: default_vacancies,
applications_open: default_applications_open,
can_sponsor_visa: form_params[:visa_status]
))
redirect_to next_step_path
else
render :new
end
end

private

def next_step_path
if course_type_answer_determiner.show_exit_page?
find_no_degree_and_requires_visa_sponsorship_path(filter_params[:find_visa_status_form])
else
find_results_path(
form_params.merge(
subjects: sanitised_subject_codes,
has_vacancies: default_vacancies,
applications_open: default_applications_open,
can_sponsor_visa: form_params[:visa_status]
)
)
end
end

def course_type_answer_determiner
@course_type_answer_determiner ||= CourseTypeAnswerDeterminer.new(
university_degree_status: form_params[:university_degree_status],
age_group: form_params[:age_group],
visa_status: form_params[:visa_status]
)
end

def sanitised_subject_codes
form_params['subjects'].compact_blank!
end

def form_name = :find_visa_status_form

def back_path(backlink_params)
def back_path
return find_university_degree_status_path(backlink_query_parameters) if teacher_degree_apprenticeship_active?

if params[:age_group] == 'further_education' || (params[:find_visa_status_form] && params[:find_visa_status_form][:age_group] == 'further_education')
find_age_groups_path(backlink_params)
find_age_groups_path(backlink_query_parameters)
else
find_subjects_path(backlink_params)
find_subjects_path(backlink_query_parameters)
end
end

def build_backlink_query_parameters
@backlink_query_parameters = ResultsView.new(query_parameters: request.query_parameters[:find_visa_status_form].presence || request.query_parameters)
.query_parameters_with_defaults
.except(:find_visa_status_form)
end
helper_method :back_path
end
end
end
10 changes: 10 additions & 0 deletions app/forms/find/university_degree_status_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Find
class UniversityDegreeStatusForm
include ActiveModel::Model
attr_accessor :university_degree_status

validates :university_degree_status, presence: true
end
end
8 changes: 8 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ def new_draft_attributes
)
}

scope :with_course_type, lambda { |course_type|
if course_type == :undergraduate
where(program_type: Course.program_types[:teacher_degree_apprenticeship])
else
where.not(program_type: Course.program_types[:teacher_degree_apprenticeship])
end
}

def self.entry_requirement_options_without_nil_choice
ENTRY_REQUIREMENT_OPTIONS.reject { |option| option == :not_set }.keys.map(&:to_s)
end
Expand Down
17 changes: 15 additions & 2 deletions app/services/course_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ class CourseSearchService
def initialize(
filter:,
sort: nil,
course_scope: Course
course_scope: Course,
course_type_answer_determiner: Find::CourseTypeAnswerDeterminer
)
@filter = filter || {}
@course_scope = course_scope
@sort = sort
@course_type_answer_determiner = course_type_answer_determiner.new(
university_degree_status: @filter['university_degree_status'],
age_group: @filter['age_group'],
visa_status: @filter['visa_status']
)
end

def call
scope = course_scope
scope = scope.with_course_type(course_type)
scope = scope.with_salary if funding_filter_salary?
scope = scope.with_qualifications(qualifications) if qualifications.any?
scope = scope.application_status_open if applications_open?
Expand Down Expand Up @@ -76,6 +83,12 @@ def call

private

def course_type
return :undergraduate if @course_type_answer_determiner.show_undergraduate_courses?

:postgraduate
end

def expand_university?
filter[:expand_university].to_s.downcase == 'true'
end
Expand Down Expand Up @@ -197,7 +210,7 @@ def funding_filter_salary?
end

def qualifications
return [] if filter[:qualification].blank?
return [] if filter[:qualification].blank? || course_type == :undergraduate

filter[:qualification] = filter[:qualification].values if filter[:qualification].is_a?(Hash)
filter[:qualification] = filter[:qualification].split(',') if filter[:qualification].is_a?(String)
Expand Down
47 changes: 47 additions & 0 deletions app/services/find/course_type_answer_determiner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

module Find
class CourseTypeAnswerDeterminer
attr_reader :age_group, :visa_status, :university_degree_status

def initialize(age_group:, visa_status:, university_degree_status:)
@age_group = age_group
@visa_status = visa_status
@university_degree_status = university_degree_status
end

def show_undergraduate_courses?
!further_education? && university_degree_question_answered? && no_degrees? && does_not_require_visa_sponsorship?
end

def show_exit_page?
!further_education? && university_degree_question_answered? && no_degrees? && require_visa_sponsorship?
end

private

def university_degree_question_answered?
university_degree_status.present?
end

def further_education?
age_group == 'further_education'
end

def require_visa_sponsorship?
ActiveModel::Type::Boolean.new.cast(visa_status)
end

def does_not_require_visa_sponsorship?
!require_visa_sponsorship?
end

def no_degrees?
!degrees?
end

def degrees?
ActiveModel::Type::Boolean.new.cast(university_degree_status)
end
end
end
8 changes: 8 additions & 0 deletions app/view_objects/find/result_filters/filters_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def qualification_params_nil?
params[:qualification].nil?
end

def show_undergraduate_courses?
CourseTypeAnswerDeterminer.new(
age_group: params[:age_group],
university_degree_status: params[:university_degree_status],
visa_status: params[:visa_status]
).show_undergraduate_courses?
end

def location_query?
params[:l] == '1'
end
Expand Down
26 changes: 16 additions & 10 deletions app/views/find/result_filters/_all.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@

<div class="app-filter__content">
<%= form.submit "Apply filters", name: nil, class: "govuk-button", data: { qa: "apply-filters" } %>
<%= render "find/result_filters/radius", form: %>
<%= render "find/result_filters/visa_filter", form: %>
<%= render "find/result_filters/engineers_teach_physics_filter", form: %>
<%= render "find/result_filters/study_type_filter", form: %>
<%= render "find/result_filters/qualifications_filter", form: %>
<%= render "find/result_filters/degree_required_filter", form: %>
<%= render "find/result_filters/send_filter", form: %>
<%= render "find/result_filters/salary_filter", form: %>
<%= render "find/result_filters/applications_open_filter", form: %>
<%= render "find/result_filters/hidden_fields", form: %>
<% if @filters_view.show_undergraduate_courses? %>
<%= render "find/result_filters/send_filter", form: %>
<%= render "find/result_filters/applications_open_filter", form: %>
<%= render "find/result_filters/hidden_fields", form: %>
<% else %>
<%= render "find/result_filters/radius", form: %>
<%= render "find/result_filters/visa_filter", form: %>
<%= render "find/result_filters/engineers_teach_physics_filter", form: %>
<%= render "find/result_filters/study_type_filter", form: %>
<%= render "find/result_filters/qualifications_filter", form: %>
<%= render "find/result_filters/degree_required_filter", form: %>
<%= render "find/result_filters/send_filter", form: %>
<%= render "find/result_filters/salary_filter", form: %>
<%= render "find/result_filters/applications_open_filter", form: %>
<%= render "find/result_filters/hidden_fields", form: %>
<% end %>
</div>
<% end %>
4 changes: 4 additions & 0 deletions app/views/find/result_filters/_hidden_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
<%= form.hidden_field(:subject_codes, multiple: true, value: subject_code) %>
<% end %>
<% end %>

<% if params[:university_degree_status] %>
<%= form.hidden_field(:university_degree_status, value: params[:university_degree_status]) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= content_for :page_title, t("find.no_degree_and_requires_visa_sponsorship_page.title") %>

<% content_for :before_content do %>
<%= govuk_back_link(
text: "Back",
href: back_path,
html_attributes: {
data: { qa: "page-back" }
}
) %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
<%= t("find.no_degree_and_requires_visa_sponsorship_page.title") %>.
</h1>

<p class="govuk-body">
<%= t("find.no_degree_and_requires_visa_sponsorship_page.content") %>
</p>

<p class="govuk-body">
<%= t(
"find.no_degree_and_requires_visa_sponsorship_page.explanation",
link: govuk_link_to(
t("find.get_into_teaching.undergraduate_degree_courses"),
t("find.get_into_teaching.url_ways_to_train_no_degree")
)
).html_safe %>
</p>
</div>
</div>
Loading

0 comments on commit ec7ddf0

Please sign in to comment.