Browse Source

Fix address options for address search question

CLDC-3787-Autocomplete-address-search
Manny Dinssa 4 days ago
parent
commit
ad45f17ab4
  1. 1
      app/models/form/lettings/questions/address_search.rb
  2. 1
      app/models/form/sales/questions/address_search.rb
  3. 21
      app/models/log.rb

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

@ -19,7 +19,6 @@ class Form::Lettings::Questions::AddressSearch < ::Form::Question
answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] } answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] }
end end
answer_opts["divider"] = { "value" => true }
answer_opts answer_opts
end end

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

@ -19,7 +19,6 @@ class Form::Sales::Questions::AddressSearch < ::Form::Question
answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] } answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] }
end end
answer_opts["divider"] = { "value" => true }
answer_opts answer_opts
end end

21
app/models/log.rb

@ -126,19 +126,27 @@ class Log < ApplicationRecord
end end
def address_options def address_options
search_query = address_search.presence || address_string if address_search.present?
return @address_options if @address_options && @last_searched_address_string == search_query service = UprnClient.new(address_search)
service.call
if service.result.blank? || service.error.present?
@address_options = []
return @address_options
end
search_query = address_search.presence || address_string presenter = AddressDataPresenter.new(service.result)
return if search_query.blank? @address_options = [{ address: presenter.address, uprn: presenter.uprn }]
else
return @address_options if @address_options && @last_searched_address_string == address_string
return if address_string.blank?
@last_searched_address_string = search_query @last_searched_address_string = address_string
service = AddressClient.new(address_string) service = AddressClient.new(address_string)
service.call service.call
if service.result.blank? || service.error.present? if service.result.blank? || service.error.present?
@address_options = [] @address_options = []
return @answer_options return @address_options
end end
address_opts = [] address_opts = []
@ -149,6 +157,7 @@ class Log < ApplicationRecord
@address_options = address_opts @address_options = address_opts
end end
end
def collection_start_year def collection_start_year
return @start_year if @start_year return @start_year if @start_year

Loading…
Cancel
Save