From 49b3acb2c319820bd95da7c672f1fa233020b25a Mon Sep 17 00:00:00 2001 From: Derek Ekins Date: Sun, 22 Dec 2019 23:04:40 +0000 Subject: [PATCH] change location/locality to postcode and add fields to store parish/ward etc. --- app/controllers/initiatives_controller.rb | 3 +- app/models/initiative.rb | 16 +++- app/views/initiatives/_form.html.erb | 11 +-- ...91222211340_add_location_to_initiatives.rb | 15 ++++ db/schema.rb | 10 ++- frontend/packs/initiative_solution_picker.js | 58 +++++++++---- .../components/initiative-solution-picker.css | 5 ++ run_tests | 6 ++ test/application_system_test_case.rb | 2 + .../initiatives_controller_test.rb | 4 - test/fixtures/initiatives.yml | 9 +- test/models/initiative_test.rb | 8 +- test/system/initiatives_test.rb | 82 ++++++++++--------- 13 files changed, 150 insertions(+), 79 deletions(-) create mode 100644 db/migrate/20191222211340_add_location_to_initiatives.rb create mode 100755 run_tests diff --git a/app/controllers/initiatives_controller.rb b/app/controllers/initiatives_controller.rb index 1d9a09c..04851af 100644 --- a/app/controllers/initiatives_controller.rb +++ b/app/controllers/initiatives_controller.rb @@ -136,8 +136,7 @@ def initiative_params :name, :summary, :anticipated_carbon_saving, - :locality, - :location, + :postcode, :latitude, :longitude, :lead_group_id, diff --git a/app/models/initiative.rb b/app/models/initiative.rb index c057754..8cdef60 100644 --- a/app/models/initiative.rb +++ b/app/models/initiative.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Metrics/ClassLength class Initiative < ApplicationRecord belongs_to :lead_group, class_name: 'Group' belongs_to :status, class_name: 'InitiativeStatus' @@ -104,10 +105,19 @@ def self.create_solution(mapped_solution) } end + def location + [parish, ward, district, county, region].join(', ') + end + + # rubocop:disable Metrics/MethodLength def location_attributes { - name: locality, - address: location, + parish: parish, + ward: ward, + district: district, + county: county, + region: region, + postcode: postcode, latlng: { # "Down to Earth Stroud, PO Box 427, Stonehouse, Gloucestershire, GL6 1JG", lat: latitude, @@ -115,4 +125,6 @@ def location_attributes } } end + # rubocop:enable Metrics/MethodLength end +# rubocop:enable Metrics/ClassLength diff --git a/app/views/initiatives/_form.html.erb b/app/views/initiatives/_form.html.erb index 3dd08c0..cf3e238 100644 --- a/app/views/initiatives/_form.html.erb +++ b/app/views/initiatives/_form.html.erb @@ -44,14 +44,9 @@

Location

- <%= f.form_field :locality do %> - <%= f.label :locality %> - <%= f.text_field :locality %> - <% end %> - - <%= f.form_field :location do %> - <%= f.label :location %> - <%= f.text_field :location %> + <%= f.form_field :postcode do %> + <%= f.label :postcode %> + <%= f.text_field :postcode %> <% end %>