From 1ba635cd7821eb7a180c64da2ea6083a3481d79f Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 8 Feb 2024 12:29:17 +0000 Subject: [PATCH] feat: prettification --- .../uprn_address_spike_controller.rb | 12 +-- app/views/content/uprn_address_spike.html.erb | 102 +++++++++++------- 2 files changed, 70 insertions(+), 44 deletions(-) diff --git a/app/controllers/uprn_address_spike_controller.rb b/app/controllers/uprn_address_spike_controller.rb index 9876dd8b0..4fd2776b6 100644 --- a/app/controllers/uprn_address_spike_controller.rb +++ b/app/controllers/uprn_address_spike_controller.rb @@ -2,21 +2,21 @@ class UprnAddressSpikeController < ApplicationController def show if params[:uprn] || params[:address] - if params[:uprn] + if params[:uprn].present? uprn = params[:uprn] service = UprnClient.new(uprn) service.call if service.error.present? - @error = "no match" + @error = "No match" else @address_returned = UprnDataPresenter.new(service.result) end - elsif params[:address] - address = params[:address] - service = AddressClient.new(address) + elsif params.values_at(:address_line1, :address_line2, :town_or_city, :postcode).any?(&:present?) + @address_given = params.values_at(:address_line1, :address_line2, :town_or_city, :postcode).reject { |item| item == "" }.join(", ") + service = AddressClient.new(@address_given) service.call if service.error.present? - @error = "no match" + @error = "No matches" else @addresses_returned = service.result&.map { |r| AddressDataPresenter.new(r) } end diff --git a/app/views/content/uprn_address_spike.html.erb b/app/views/content/uprn_address_spike.html.erb index df04d176f..9a76ef6cc 100644 --- a/app/views/content/uprn_address_spike.html.erb +++ b/app/views/content/uprn_address_spike.html.erb @@ -1,39 +1,65 @@ -
- - - -
- -
- - - -
- -<% if params[:uprn] %> -

UPRN given:

-

<%= params[:uprn] %>

- <% if @error.present? %> - <%= @error %> - <% elsif @address_returned.present? %> -

Output:

-

<%= @address_returned.address_line1 %>

-

<%= @address_returned.address_line2 %>

-

<%= @address_returned.town_or_city %>

-

<%= @address_returned.postcode %>

- <% end %> -<% elsif params[:address] %> -

Address given:

-

<%= params[:address] %>

- <% if @error.present? %> - <%= @error %> - <% elsif @addresses_returned.present? %> -

Output:

- <% @addresses_returned.each do |address_returned| %> -

Address: <%= address_returned.address %>

-

UPRN: <%= address_returned.uprn %>

-

Confidence: <%= address_returned.match%> (<%= address_returned.match_description %>)

-
+
+
+
+

User input

+ <%= form_with(url: uprn_address_spike_path, method: 'get', local: true) do |form| %> +
+ <%= form.label :uprn, "Enter a UPRN", class: "govuk-label" %> + <%= form.text_field :uprn, class: "govuk-input", placeholder: "e.g. 100023336956" %> +
+
+

OR enter an address

+
+ <%= form.label :address_line1, "Address line 1", class: "govuk-label" %> + <%= form.text_field :address_line1, class: "govuk-input", placeholder: "e.g. HOME OFFICE" %> +
+
+ <%= form.label :address_line2, "Address line 2", class: "govuk-label" %> + <%= form.text_field :address_line2, class: "govuk-input", placeholder: "e.g. 2, MARSHAM STREET" %> +
+
+ <%= form.label :town_or_city, "Town or city", class: "govuk-label" %> + <%= form.text_field :town_or_city, class: "govuk-input", placeholder: "e.g. LONDON" %> +
+
+ <%= form.label :postcode, "Postcode", class: "govuk-label" %> + <%= form.text_field :postcode, class: "govuk-input", placeholder: "e.g. SW1P 4DF" %> +
+ <%= form.submit "Submit", class: "govuk-button" %> <% end %> - <% end %> -<% end %> +
+
+
+ <%if params[:uprn].present? || @address_given.present? %> +

OS Places API output

+ <%end %> + <% if params[:uprn].present? %> +

UPRN given:

+

<%= params[:uprn] %>

+ <% if @error.present? %> +

<%= @error %>

+ <% elsif @address_returned.present? %> +

Match:

+

<%= @address_returned.address_line1 %>

+

<%= @address_returned.address_line2 %>

+

<%= @address_returned.town_or_city %>

+

<%= @address_returned.postcode %>

+ <% end %> + <% elsif @address_given.present? %> +

Address given:

+

<%= @address_given %>

+ <% if @error.present? %> +

<%= @error %>

+ <% elsif @addresses_returned.present? %> +

Matches:

+ <% @addresses_returned.each do |address_returned| %> +

Address: <%= address_returned.address %>

+

UPRN: <%= address_returned.uprn %>

+

Confidence: <%= address_returned.match%> (<%= address_returned.match_description %>)

+
+ <% end %> + <% end %> + <% end %> +
+
+