Browse Source

Updates with lettings logs

pull/2922/head
Manny Dinssa 6 days ago
parent
commit
3fb4b591ad
  1. 54
      app/frontend/controllers/address_autocomplete_controller.js
  2. 23
      app/models/form/lettings/pages/address_search.rb
  3. 30
      app/models/form/lettings/questions/address_search.rb
  4. 2
      app/models/form/lettings/questions/uprn_confirmation.rb
  5. 1
      app/models/form/lettings/subsections/property_information.rb
  6. 1
      app/models/form/sales/pages/address_search.rb
  7. 2
      app/models/form/sales/questions/address_search.rb
  8. 7
      config/locales/forms/2024/lettings/property_information.en.yml
  9. 7
      config/locales/forms/2024/sales/property_information.en.yml
  10. 7
      config/locales/forms/2025/lettings/property_information.en.yml
  11. 7
      config/locales/forms/2025/sales/property_information.en.yml

54
app/frontend/controllers/address_autocomplete_controller.js

@ -18,7 +18,6 @@ const fetchAndPopulateSearchResults = async (query, populateResults, populateOpt
console.log(results) // address and uprn keys returned per result console.log(results) // address and uprn keys returned per result
populateOptions(results, selectEl) populateOptions(results, selectEl)
populateResults(Object.values(results).map((o) => o.address)) populateResults(Object.values(results).map((o) => o.address))
// populateResults(results)
} }
} }
@ -35,36 +34,10 @@ const populateOptions = (results, selectEl) => {
}) })
} }
// const populateOptions = (results, selectEl) => {
// selectEl.innerHTML = ''
//
// Object.keys(results).forEach((key) => {
// const option = document.createElement('option')
// option.value = key
// option.innerHTML = results[key].value
// if (results[key].hint) { option.setAttribute('data-hint', results[key].hint) }
// option.setAttribute('text', searchableName(results[key]))
// selectEl.appendChild(option)
// options.push(option)
// })
// }
export default class extends Controller { export default class extends Controller {
connect () { connect () {
const selectEl = this.element const selectEl = this.element
const currentValue = this.getCurrentValue()
console.log(selectEl)
if (currentValue && currentValue.stored_value) {
console.log(currentValue)
const option = document.createElement('option')
option.value = currentValue.stored_value.uprn
option.innerHTML = currentValue.stored_value.address
option.selected = true
selectEl.appendChild(option)
}
accessibleAutocomplete.enhanceSelectElement({ accessibleAutocomplete.enhanceSelectElement({
defaultValue: '', defaultValue: '',
selectElement: selectEl, selectElement: selectEl,
@ -74,7 +47,7 @@ export default class extends Controller {
}, },
autoselect: true, autoselect: true,
showNoOptionsFound: true, showNoOptionsFound: true,
placeholder: currentValue?.stored_value?.address || 'Start typing to search', placeholder: 'Start typing to search',
templates: { suggestion: (value) => value }, templates: { suggestion: (value) => value },
onConfirm: (val) => { onConfirm: (val) => {
const selectedResult = Array.from(selectEl.options).find(option => option.address === val) const selectedResult = Array.from(selectEl.options).find(option => option.address === val)
@ -86,30 +59,5 @@ export default class extends Controller {
}) })
} }
fetchOptions(query, populateResults) {
fetch(`/address_options?query=${query}`)
.then(response => response.json())
.then(data => {
console.log(data)
const results = data.map(result => result.uprn)
populateResults(results.slice(0, 10))
})
}
async getCurrentValue() {
const currentPageUrl = window.location.href;
console.log(currentPageUrl);
const match = currentPageUrl.match(/sales-logs\/(\d+)\/address-search/);
const id = match ? match[1] : null;
if (id) {
const response = await fetch(`/address_options/current?log_id=${id}`);
const data = await response.json();
console.log(data);
return data;
}
return null;
}
} }

23
app/models/form/lettings/pages/address_search.rb

@ -0,0 +1,23 @@
class Form::Lettings::Pages::AddressSearch < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "address_search"
@depends_on = [
{ "uprn_known" => nil },
{ "uprn_known" => 0 },
{ "uprn_confirmed" => 0 },
]
end
def questions
@questions ||= [
Form::Lettings::Questions::AddressSearch.new(nil, nil, self),
]
end
def skip_href(log = nil)
return unless log
"/#{log.model_name.param_key.dasherize}s/#{log.id}/property-unit-type"
end
end

30
app/models/form/lettings/questions/address_search.rb

@ -0,0 +1,30 @@
class Form::Lettings::Questions::AddressSearch < ::Form::Question
def initialize(id, hsh, page)
super
@id = "address_search"
@type = "address_autocomplete"
@plain_label = true
end
def answer_options(log = nil, _user = nil)
return {} unless ActiveRecord::Base.connected?
return {} unless log&.address_options
answer_opts = {}
(0...[log.address_options.count, 10].min).each do |i|
answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] }
end
answer_opts["divider"] = { "value" => true }
answer_opts
end
def displayed_answer_options(log, user = nil)
answer_options(log, user).transform_values { |value| value["value"] } || {}
end
def hidden_in_check_answers?(log, _current_user = nil)
(log.uprn_known == 1 || log.uprn_confirmed == 1)
end
end

2
app/models/form/lettings/questions/uprn_confirmation.rb

@ -37,6 +37,6 @@ class Form::Lettings::Questions::UprnConfirmation < ::Form::Question
end end
def hidden_in_check_answers?(log, _current_user = nil) def hidden_in_check_answers?(log, _current_user = nil)
log.uprn_known != 1 || log.uprn_confirmed.present? log.uprn_known != 1 || log.uprn_confirmed.present? || log.address_search.present?
end end
end end

1
app/models/form/lettings/subsections/property_information.rb

@ -34,6 +34,7 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection
[ [
Form::Lettings::Pages::Uprn.new(nil, nil, self), Form::Lettings::Pages::Uprn.new(nil, nil, self),
Form::Lettings::Pages::UprnConfirmation.new(nil, nil, self), Form::Lettings::Pages::UprnConfirmation.new(nil, nil, self),
Form::Lettings::Pages::AddressSearch.new(nil, nil, self),
Form::Lettings::Pages::AddressMatcher.new(nil, nil, self), Form::Lettings::Pages::AddressMatcher.new(nil, nil, self),
Form::Lettings::Pages::NoAddressFound.new(nil, nil, self), # soft validation Form::Lettings::Pages::NoAddressFound.new(nil, nil, self), # soft validation
Form::Lettings::Pages::UprnSelection.new(nil, nil, self), Form::Lettings::Pages::UprnSelection.new(nil, nil, self),

1
app/models/form/sales/pages/address_search.rb

@ -2,7 +2,6 @@ class Form::Sales::Pages::AddressSearch < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "address_search" @id = "address_search"
@copy_key = "sales.property_information.address_search"
@depends_on = [ @depends_on = [
{ "uprn_known" => nil }, { "uprn_known" => nil },
{ "uprn_known" => 0 }, { "uprn_known" => 0 },

2
app/models/form/sales/questions/address_search.rb

@ -2,8 +2,6 @@ class Form::Sales::Questions::AddressSearch < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "address_search" @id = "address_search"
@copy_key = "sales.property_information.address_search"
@error_label = "Enter search query"
@type = "address_autocomplete" @type = "address_autocomplete"
@plain_label = true @plain_label = true
end end

7
config/locales/forms/2024/lettings/property_information.en.yml

@ -50,6 +50,13 @@ en:
hint_text: "" hint_text: ""
question_text: "Select the correct address" question_text: "Select the correct address"
address_search:
page_header: "Find address"
check_answer_label: "Find address"
check_answer_prompt: "Search for address or UPRN"
hint_text: "Start typing an address to see suggestions and select the correct one. Some properties may not be available yet; you might need to enter them manually in the next question. For UPRN (Unique Property Reference Number), please enter the full value exactly."
question_text: "Enter the address or UPRN to search"
address: address:
page_header: "Q12 - What is the property's address?" page_header: "Q12 - What is the property's address?"
address_line1: address_line1:

7
config/locales/forms/2024/sales/property_information.en.yml

@ -43,6 +43,13 @@ en:
hint_text: "" hint_text: ""
question_text: "Select the correct address" question_text: "Select the correct address"
address_search:
page_header: "Find address"
check_answer_label: "Find address"
check_answer_prompt: "Search for address or UPRN"
hint_text: "Start typing an address to see suggestions and select the correct one. Some properties may not be available yet; you might need to enter them manually in the next question. For UPRN (Unique Property Reference Number), please enter the full value exactly."
question_text: "Enter the address or UPRN to search"
address: address:
page_header: "Q12 - What is the property's address?" page_header: "Q12 - What is the property's address?"
address_line1: address_line1:

7
config/locales/forms/2025/lettings/property_information.en.yml

@ -50,6 +50,13 @@ en:
hint_text: "" hint_text: ""
question_text: "Select the correct address" question_text: "Select the correct address"
address_search:
page_header: "Find address"
check_answer_label: "Find address"
check_answer_prompt: "Search for address or UPRN"
hint_text: "Start typing an address to see suggestions and select the correct one. Some properties may not be available yet; you might need to enter them manually in the next question. For UPRN (Unique Property Reference Number), please enter the full value exactly."
question_text: "Enter the address or UPRN to search"
address: address:
page_header: "Q12 - What is the property's address?" page_header: "Q12 - What is the property's address?"
address_line1: address_line1:

7
config/locales/forms/2025/sales/property_information.en.yml

@ -43,6 +43,13 @@ en:
hint_text: "" hint_text: ""
question_text: "Select the correct address" question_text: "Select the correct address"
address_search:
page_header: "Find address"
check_answer_label: "Find address"
check_answer_prompt: "Search for address or UPRN"
hint_text: "Start typing an address to see suggestions and select the correct one. Some properties may not be available yet; you might need to enter them manually in the next question. For UPRN (Unique Property Reference Number), please enter the full value."
question_text: "Enter the address or UPRN to search"
address: address:
page_header: "Q12 - What is the property's address?" page_header: "Q12 - What is the property's address?"
address_line1: address_line1:

Loading…
Cancel
Save