Browse Source
* List in alphabetical order using second line of address (.i.e. hint/name)pull/2521/head
Manny Dinssa
5 months ago
committed by
GitHub
15 changed files with 218 additions and 11 deletions
@ -0,0 +1,20 @@ |
|||||||
|
class Form::Lettings::Pages::LocationSearch < ::Form::Page |
||||||
|
def initialize(_id, hsh, subsection) |
||||||
|
super("location_search", hsh, subsection) |
||||||
|
@depends_on = [ |
||||||
|
{ |
||||||
|
"needstype" => 2, |
||||||
|
"scheme_has_multiple_locations?" => true, |
||||||
|
"scheme_has_large_number_of_locations?" => true, |
||||||
|
}, |
||||||
|
] |
||||||
|
@header = "Location" |
||||||
|
@next_unresolved_page_id = :check_answers |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [ |
||||||
|
Form::Lettings::Questions::LocationIdSearch.new(nil, nil, self), |
||||||
|
] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,64 @@ |
|||||||
|
class Form::Lettings::Questions::LocationIdSearch < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "location_id" |
||||||
|
@check_answer_label = "Location" |
||||||
|
@header = header_text |
||||||
|
@hint_text = '<div class="govuk-inset-text">This scheme has 20 or more locations.</div>Enter postcode or address.' |
||||||
|
@type = "select" |
||||||
|
@answer_options = answer_options |
||||||
|
@inferred_answers = { |
||||||
|
"location.name": { |
||||||
|
"needstype": 2, |
||||||
|
}, |
||||||
|
} |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] if form.start_date.present? |
||||||
|
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||||
|
@top_guidance_partial = "finding_location" |
||||||
|
end |
||||||
|
|
||||||
|
def answer_options |
||||||
|
answer_opts = {} |
||||||
|
return answer_opts unless ActiveRecord::Base.connected? |
||||||
|
|
||||||
|
Location.visible.started_in_2_weeks.select(:id, :postcode, :name).each_with_object(answer_opts) do |location, hsh| |
||||||
|
hsh[location.id.to_s] = location |
||||||
|
hsh |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def displayed_answer_options(lettings_log, _user = nil) |
||||||
|
return {} unless lettings_log.scheme |
||||||
|
|
||||||
|
scheme_location_ids = lettings_log.scheme.locations.visible.confirmed.pluck(:id) |
||||||
|
answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) }.to_h |
||||||
|
end |
||||||
|
|
||||||
|
def hidden_in_check_answers?(lettings_log, _current_user = nil) |
||||||
|
!supported_housing_selected?(lettings_log) |
||||||
|
end |
||||||
|
|
||||||
|
def get_extra_check_answer_value(lettings_log) |
||||||
|
lettings_log.form.get_question("la", nil).label_from_value(lettings_log.la) |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def supported_housing_selected?(lettings_log) |
||||||
|
lettings_log.needstype == 2 |
||||||
|
end |
||||||
|
|
||||||
|
def selected_answer_option_is_derived?(_lettings_log) |
||||||
|
false |
||||||
|
end |
||||||
|
|
||||||
|
def header_text |
||||||
|
if form.start_date && form.start_date.year >= 2023 |
||||||
|
"Which location is this letting for?" |
||||||
|
else |
||||||
|
"Which location is this log for?" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2023 => 10, 2024 => 5 }.freeze |
||||||
|
end |
@ -0,0 +1,19 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Form::Lettings::Pages::LocationSearch, type: :model do |
||||||
|
subject(:page) { described_class.new(page_id, page_definition, subsection) } |
||||||
|
|
||||||
|
let(:page_id) { nil } |
||||||
|
let(:page_definition) { nil } |
||||||
|
let(:subsection) { instance_double(Form::Subsection) } |
||||||
|
|
||||||
|
it "has the correct depends_on" do |
||||||
|
expect(page.depends_on).to eq([ |
||||||
|
{ |
||||||
|
"needstype" => 2, |
||||||
|
"scheme_has_multiple_locations?" => true, |
||||||
|
"scheme_has_large_number_of_locations?" => true, |
||||||
|
}, |
||||||
|
]) |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue