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. 43
      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] }
end
answer_opts["divider"] = { "value" => true }
answer_opts
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] }
end
answer_opts["divider"] = { "value" => true }
answer_opts
end

43
app/models/log.rb

@ -126,28 +126,37 @@ class Log < ApplicationRecord
end
def address_options
search_query = address_search.presence || address_string
return @address_options if @address_options && @last_searched_address_string == search_query
if address_search.present?
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
return if search_query.blank?
presenter = AddressDataPresenter.new(service.result)
@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.call
if service.result.blank? || service.error.present?
@address_options = []
return @answer_options
end
service = AddressClient.new(address_string)
service.call
if service.result.blank? || service.error.present?
@address_options = []
return @address_options
end
address_opts = []
service.result.first(10).each do |result|
presenter = AddressDataPresenter.new(result)
address_opts.append({ address: presenter.address, uprn: presenter.uprn })
end
address_opts = []
service.result.first(10).each do |result|
presenter = AddressDataPresenter.new(result)
address_opts.append({ address: presenter.address, uprn: presenter.uprn })
end
@address_options = address_opts
@address_options = address_opts
end
end
def collection_start_year

Loading…
Cancel
Save