From df55a5b0a8b04847c241535a11aa3fd9382ec875 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 10:37:40 +1300 Subject: [PATCH 01/15] Add marker for leaflet maps, and use asset pipeline to serve file --- app/assets/images/spade-marker.svg | 9 +++++ app/assets/javascripts/places.js.erb | 39 ++++++++++++------- app/assets/stylesheets/leaflet_overrides.scss | 12 +++--- app/views/places/index.html.haml | 3 ++ 4 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 app/assets/images/spade-marker.svg diff --git a/app/assets/images/spade-marker.svg b/app/assets/images/spade-marker.svg new file mode 100644 index 000000000..791a3709e --- /dev/null +++ b/app/assets/images/spade-marker.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/assets/javascripts/places.js.erb b/app/assets/javascripts/places.js.erb index f0322b38b..949563252 100644 --- a/app/assets/javascripts/places.js.erb +++ b/app/assets/javascripts/places.js.erb @@ -1,20 +1,23 @@ if (document.getElementById("placesmap") !== null) { - places_base_path = "/places"; - mapbox_map_id = "<%= Rails.env == 'test' ? 0 : Rails.application.config.mapbox_map_id %>"; - mapbox_access_token = "<%= Rails.env == 'test' ? 0 : Rails.application.config.mapbox_access_token %>"; - mapbox_base_url = "https://a.tiles.mapbox.com/v4/" + mapbox_map_id + "/{z}/{x}/{y}.png?access_token=" + mapbox_access_token; - nominatim_base_url = 'https://nominatim.openstreetmap.org/search/'; - nominatim_user_agent_email = "<%= Rails.env == 'test' ? 0 : Rails.application.config.user_agent_email %>"; + var places_base_path = "/places"; + var mapbox_map_id = "<%= Rails.env == 'test' ? 0 : Rails.application.config.mapbox_map_id %>"; + var mapbox_access_token = "<%= Rails.env == 'test' ? 0 : Rails.application.config.mapbox_access_token %>"; + var mapbox_base_url = "https://a.tiles.mapbox.com/v4/" + mapbox_map_id + "/{z}/{x}/{y}.png?access_token=" + mapbox_access_token; + var nominatim_base_url = 'https://nominatim.openstreetmap.org/search/'; + var nominatim_user_agent_email = "<%= Rails.env == 'test' ? 0 : Rails.application.config.user_agent_email %>"; L.Icon.Default.imagePath = '/assets' + var placesmap; + if (location.pathname === places_base_path) { //places index page placesmap = L.map('placesmap').setView([0.0, -0.0], 2); showMap(placesmap); - } else { // specific place page - place = location.pathname.replace(places_base_path + "/", ''); - nominatim_query_url = nominatim_base_url + place; - nominatim_options = { + } + else { // specific place page + var place = location.pathname.replace(places_base_path + "/", ''); + var nominatim_query_url = nominatim_base_url + place; + var nominatim_options = { format: "json", callback: "placeholder", limit: 1, @@ -32,15 +35,21 @@ function showMap(placesmap) { attribution: 'Map data © OpenStreetMap contributors under ODbL | Map imagery © Mapbox', maxZoom: 18 }).addTo(placesmap); - markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 20 }); + var markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 20 }); - things_to_map = location.pathname + '.json'; + var things_to_map = location.pathname + '.json'; + var default_marker_icon = L.icon({ + iconUrl: "<%=image_url('spade-marker.svg')%>", + iconSize: [48, 48], + iconAnchor: [24, 48], + popupAnchor: [0, -46], + }); $.getJSON(things_to_map, function(members) { $.each(members, function(i, m) { if (m.latitude && m.longitude) { - marker = new L.Marker(new L.LatLng(m.latitude, m.longitude)); - link = "

" + m.login_name + "

"; - where = "

" + m.location + "

"; + var marker = new L.Marker(new L.LatLng(m.latitude, m.longitude), {icon: default_marker_icon}); + var link = "

" + m.login_name + "

"; + var where = "

" + m.location + "

"; marker.bindPopup(link + where).openPopup(); markers.addLayer(marker); } diff --git a/app/assets/stylesheets/leaflet_overrides.scss b/app/assets/stylesheets/leaflet_overrides.scss index aa69bb297..c89f27303 100644 --- a/app/assets/stylesheets/leaflet_overrides.scss +++ b/app/assets/stylesheets/leaflet_overrides.scss @@ -1,13 +1,13 @@ .leaflet-popup-content-wrapper, .leaflet-popup-tip { - border: none; + border: 0; } .thumbnail { - background: #fff !important; - border: solid 1px whitesmoke; -} + background: $white; + border: solid 1px $white; -.thumbnail .crop-thumbnail .cropinfo { - padding-top: 14px; + .crop-thumbnail .cropinfo { + padding-top: 14px; + } } diff --git a/app/views/places/index.html.haml b/app/views/places/index.html.haml index ebc180a81..f915e67db 100644 --- a/app/views/places/index.html.haml +++ b/app/views/places/index.html.haml @@ -1,3 +1,6 @@ - content_for :title, t(".title", site_name: ENV['GROWSTUFF_SITE_NAME']) + +%h2=t(".title", site_name: ENV['GROWSTUFF_SITE_NAME']) + = render partial: 'search_form' #placesmap.map From f27cf0caf6e3b2fbf3c6eb4bff6b935a5654bf19 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 11:11:41 +1300 Subject: [PATCH 02/15] Added link to icon documentation --- app/assets/javascripts/places.js.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/places.js.erb b/app/assets/javascripts/places.js.erb index 949563252..a65cb5ec3 100644 --- a/app/assets/javascripts/places.js.erb +++ b/app/assets/javascripts/places.js.erb @@ -38,6 +38,7 @@ function showMap(placesmap) { var markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 20 }); var things_to_map = location.pathname + '.json'; + // Icon documentation: https://leafletjs.com/reference-1.5.0.html#icon var default_marker_icon = L.icon({ iconUrl: "<%=image_url('spade-marker.svg')%>", iconSize: [48, 48], From 2b7c21bf2e85864d69dec22d969b49929d5d0922 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 11:16:53 +1300 Subject: [PATCH 03/15] Fix marker on member map too --- app/assets/javascripts/members.js.erb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/members.js.erb b/app/assets/javascripts/members.js.erb index 51a662758..42fafe6b5 100644 --- a/app/assets/javascripts/members.js.erb +++ b/app/assets/javascripts/members.js.erb @@ -7,6 +7,13 @@ if (document.getElementById("membermap") !== null) { L.Icon.Default.imagePath = '/assets'; + var default_marker_icon = L.icon({ + iconUrl: "<%=image_url('spade-marker.svg')%>", + iconSize: [48, 48], + iconAnchor: [24, 48], + popupAnchor: [0, -46], + }); + $.getJSON(location.pathname + '.json', function(member) { if (member.latitude && member.longitude) { var membermap = L.map('membermap').setView([member.latitude, member.longitude], 4); @@ -15,7 +22,8 @@ if (document.getElementById("membermap") !== null) { attribution: 'Map data © OpenStreetMap contributors under ODbL | Map imagery © Mapbox', maxZoom: 18 }).addTo(membermap); - var marker = new L.Marker(new L.LatLng(member.latitude, member.longitude)); + var marker = new L.Marker(new L.LatLng(member.latitude, member.longitude), + {'icon': default_marker_icon}); var member_url = "/members/" + member.slug; var member_link = "" + member.login_name + ""; From 66fae333a94e4f006e93531f6637b6685be16365 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 11:21:40 +1300 Subject: [PATCH 04/15] Rename crops js file so it gets included correctly this crops.js.erb file was being ignored because a crops.coffee exists --- app/assets/javascripts/{crops.js.erb => cropmap.js.erb} | 1 - 1 file changed, 1 deletion(-) rename app/assets/javascripts/{crops.js.erb => cropmap.js.erb} (99%) diff --git a/app/assets/javascripts/crops.js.erb b/app/assets/javascripts/cropmap.js.erb similarity index 99% rename from app/assets/javascripts/crops.js.erb rename to app/assets/javascripts/cropmap.js.erb index 78a3a2222..a524fdcb6 100644 --- a/app/assets/javascripts/crops.js.erb +++ b/app/assets/javascripts/cropmap.js.erb @@ -44,7 +44,6 @@ function showCropMap(cropmap) { $(document).ready(function() { if (document.getElementById("cropmap") !== null) { - L.Icon.Default.imagePath = '/assets'; var cropmap = L.map('cropmap').setView([0.0, -0.0], 2); From a4373389610e8a7fb1c0c0702fb6d88dd59c4538 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 11:35:45 +1300 Subject: [PATCH 05/15] Fix markers on crops#show map --- app/assets/javascripts/cropmap.js.erb | 10 +++++++++- app/controllers/crops_controller.rb | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/cropmap.js.erb b/app/assets/javascripts/cropmap.js.erb index a524fdcb6..756530666 100644 --- a/app/assets/javascripts/cropmap.js.erb +++ b/app/assets/javascripts/cropmap.js.erb @@ -9,12 +9,20 @@ function showCropMap(cropmap) { }).addTo(cropmap); var markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 20 }); + var crop_icon = L.icon({ + iconUrl: location.pathname + '.svg', + iconSize: [24, 24], + iconAnchor: [12, 12], + popupAnchor: [0, -12], + }); + var things_to_map = location.pathname + '.json'; $.getJSON(things_to_map, function(crop) { $.each(crop.plantings, function(i, planting) { var owner = planting.owner; if (owner.latitude && owner.longitude) { - var marker = new L.Marker(new L.LatLng(owner.latitude, owner.longitude)); + var marker = new L.Marker(new L.LatLng(owner.latitude, owner.longitude), + {'icon': crop_icon}); var planting_url = "/plantings/" + planting.id; var planting_link = "" + owner.login_name + "'s " + crop.name + ""; diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 2dd6a948c..7aefd98af 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -66,7 +66,10 @@ class CropsController < ApplicationController respond_to do |format| format.html - format.svg { send_data(@crop.svg_icon, type: "image/svg+xml", disposition: "inline") } + format.svg do + icon_data = @crop.svg_icon.presence || File.read(Rails.root.join('app', 'assets', 'images', 'icons', 'sprout.svg')) + send_data(icon_data, type: "image/svg+xml", disposition: "inline") + end format.json { render json: @crop.to_json(crop_json_fields) } end end From 535ddcdcffc1f3412061d20ec6c14fc1d077b8e8 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 12:16:18 +1300 Subject: [PATCH 06/15] Added plantings to places map --- app/assets/javascripts/places.js.erb | 34 +++++++++++++++++++++-- app/models/concerns/open_farm_data.rb | 5 +++- app/models/planting.rb | 6 ++-- app/resources/api/v1/planting_resource.rb | 7 +++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/places.js.erb b/app/assets/javascripts/places.js.erb index a65cb5ec3..8e947b4be 100644 --- a/app/assets/javascripts/places.js.erb +++ b/app/assets/javascripts/places.js.erb @@ -35,9 +35,11 @@ function showMap(placesmap) { attribution: 'Map data © OpenStreetMap contributors under ODbL | Map imagery © Mapbox', maxZoom: 18 }).addTo(placesmap); + var markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 20 }); - var things_to_map = location.pathname + '.json'; + var members_url = location.pathname + '.json'; + // Icon documentation: https://leafletjs.com/reference-1.5.0.html#icon var default_marker_icon = L.icon({ iconUrl: "<%=image_url('spade-marker.svg')%>", @@ -45,7 +47,8 @@ function showMap(placesmap) { iconAnchor: [24, 48], popupAnchor: [0, -46], }); - $.getJSON(things_to_map, function(members) { + + $.getJSON(members_url, function(members) { $.each(members, function(i, m) { if (m.latitude && m.longitude) { var marker = new L.Marker(new L.LatLng(m.latitude, m.longitude), {icon: default_marker_icon}); @@ -57,5 +60,32 @@ function showMap(placesmap) { }); }); + function fetchCropsForMap(url) { + console.log('Fetching crops'); + $.getJSON(url, function(crop_data) { + $.each(crop_data['data'], function(i, p) { + if (p.attributes.latitude && p.attributes.longitude) { + console.log(p); + var crop_marker = L.icon({ + iconUrl: "/crops/" + p.attributes['crop-slug'] + '.svg', + iconSize: [48, 48], + iconAnchor: [24, 48], + popupAnchor: [0, -46], + }); + var marker = new L.Marker(new L.LatLng(p.attributes.latitude, p.attributes.longitude), + {icon: crop_marker}); + var link = "

" + p.attributes['crop-name'] + "

"; + var where = "

" + p.attributes.location + "

"; + marker.bindPopup(link + where).openPopup(); + markers.addLayer(marker); + } + }); + if (crop_data['links']['next']) { + fetchCropsForMap(crop_data['links']['next']) + } + return crop_data; + }); + } + fetchCropsForMap('/api/v1/plantings.json?filter[finished]=false'); placesmap.addLayer(markers); } diff --git a/app/models/concerns/open_farm_data.rb b/app/models/concerns/open_farm_data.rb index f56c0fa66..077971574 100644 --- a/app/models/concerns/open_farm_data.rb +++ b/app/models/concerns/open_farm_data.rb @@ -19,7 +19,10 @@ module OpenFarmData end def svg_icon - fetch_attr('svg_icon') + icon = fetch_attr('svg_icon') + return icon if icon.present? + + parent.svg_icon if parent.present? end def tags_array diff --git a/app/models/planting.rb b/app/models/planting.rb index 868f36735..bd18da6e0 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -45,10 +45,12 @@ class Planting < ApplicationRecord ## ## Delegations - delegate :name, :en_wikipedia_url, :default_scientific_name, :plantings_count, + delegate :name, :slug, :en_wikipedia_url, :default_scientific_name, :plantings_count, to: :crop, prefix: true - delegate :annual?, to: :crop + delegate :annual?, :svg_icon, to: :crop + delegate :longitude, :latitude, to: :garden + ## ## Validations validates :garden, presence: true diff --git a/app/resources/api/v1/planting_resource.rb b/app/resources/api/v1/planting_resource.rb index 18f8f23a1..e2c0b18bd 100644 --- a/app/resources/api/v1/planting_resource.rb +++ b/app/resources/api/v1/planting_resource.rb @@ -24,6 +24,9 @@ module Api attribute :first_harvest_date attribute :last_harvest_date + attribute :location + attributes :longitude, :latitude + filter :slug filter :crop filter :planted_from @@ -37,9 +40,7 @@ module Api end attribute :crop_name - def crop_name - @model.crop.name - end + attribute :crop_slug attribute :thumbnail def thumbnail From df5b0499e461b23067c7e3ad9668617b911605da Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 13:05:40 +1300 Subject: [PATCH 07/15] Update spec for api resource --- app/models/planting.rb | 7 +------ app/resources/api/v1/planting_resource.rb | 3 +-- spec/requests/api/v1/plantings_request_spec.rb | 10 ++++++++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index bd18da6e0..686153b64 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -49,7 +49,7 @@ class Planting < ApplicationRecord to: :crop, prefix: true delegate :annual?, :svg_icon, to: :crop - delegate :longitude, :latitude, to: :garden + delegate :location, :longitude, :latitude, to: :garden ## ## Validations @@ -79,11 +79,6 @@ class Planting < ApplicationRecord ].join('-').tr(' ', '-').downcase end - # location = garden owner + garden name, i.e. "Skud's backyard" - def location - I18n.t("gardens.location", garden: garden.name, owner: garden.owner.login_name) - end - # stringify as "beet in Skud's backyard" or similar def to_s I18n.t('plantings.string', crop: crop.name, garden: garden.name, owner: owner) diff --git a/app/resources/api/v1/planting_resource.rb b/app/resources/api/v1/planting_resource.rb index e2c0b18bd..1e41078fb 100644 --- a/app/resources/api/v1/planting_resource.rb +++ b/app/resources/api/v1/planting_resource.rb @@ -24,8 +24,7 @@ module Api attribute :first_harvest_date attribute :last_harvest_date - attribute :location - attributes :longitude, :latitude + attributes :longitude, :latitude, :location filter :slug filter :crop diff --git a/spec/requests/api/v1/plantings_request_spec.rb b/spec/requests/api/v1/plantings_request_spec.rb index cfd60fcf7..705c23c6f 100644 --- a/spec/requests/api/v1/plantings_request_spec.rb +++ b/spec/requests/api/v1/plantings_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Plantings', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:planting) { FactoryBot.create :planting } + let!(:planting) { FactoryBot.create :planting } let(:planting_encoded_as_json_api) do { "id" => planting.id.to_s, "type" => "plantings", @@ -60,6 +60,7 @@ RSpec.describe 'Plantings', type: :request do "quantity" => 33, "description" => planting.description, "crop-name" => planting.crop.name, + "crop-slug" => planting.crop.slug, "sunniness" => nil, "planted-from" => nil, "expected-lifespan" => nil, @@ -67,12 +68,17 @@ RSpec.describe 'Plantings', type: :request do "percentage-grown" => nil, "first-harvest-date" => nil, "last-harvest-date" => nil, - "thumbnail" => nil + "thumbnail" => nil, + "location" => planting.garden.location, + "longitude" => planting.garden.longitude, + "latitude" => planting.garden.latitude } end it '#index' do get '/api/v1/plantings', params: {}, headers: headers + expect(subject['data'][0].keys).to eq(planting_encoded_as_json_api.keys) + expect(subject['data'][0]['attributes'].keys.sort!).to eq(planting_encoded_as_json_api['attributes'].keys.sort!) expect(subject['data']).to include(planting_encoded_as_json_api) end From 1697f3e758f2b332a93d404991b00eb196bd3d8f Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 13:07:38 +1300 Subject: [PATCH 08/15] Update model spec for location --- spec/models/planting_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 56e477f4f..3bbd0a255 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -212,7 +212,7 @@ describe Planting do end it "generates a location" do - planting.location.should eq "#{garden_owner.login_name}'s #{garden.name}" + planting.location.should eq garden.location end it "has a slug" do From c87ae7be29a0cc1279a1340129196a8d3940456f Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 13:20:38 +1300 Subject: [PATCH 09/15] add photo to the map, if we have one --- app/assets/javascripts/places.js.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/assets/javascripts/places.js.erb b/app/assets/javascripts/places.js.erb index 8e947b4be..b3fb2ef66 100644 --- a/app/assets/javascripts/places.js.erb +++ b/app/assets/javascripts/places.js.erb @@ -76,6 +76,9 @@ function showMap(placesmap) { {icon: crop_marker}); var link = "

" + p.attributes['crop-name'] + "

"; var where = "

" + p.attributes.location + "

"; + if (p.attributes['thumbnail']) { + where += ''; + } marker.bindPopup(link + where).openPopup(); markers.addLayer(marker); } From 24f970f4f4f7efa39dd4a3be8794f601a3cedaad Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 13:21:42 +1300 Subject: [PATCH 10/15] Added alt tag --- app/assets/javascripts/places.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/places.js.erb b/app/assets/javascripts/places.js.erb index b3fb2ef66..f5f58f50b 100644 --- a/app/assets/javascripts/places.js.erb +++ b/app/assets/javascripts/places.js.erb @@ -77,7 +77,7 @@ function showMap(placesmap) { var link = "

" + p.attributes['crop-name'] + "

"; var where = "

" + p.attributes.location + "

"; if (p.attributes['thumbnail']) { - where += ''; + where += ''; } marker.bindPopup(link + where).openPopup(); markers.addLayer(marker); From 4c82adc61266b1503ca9f0c8d7343d05c8c0f8db Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 20:38:15 +1300 Subject: [PATCH 11/15] Added new api items to controller spec --- spec/controllers/api/v1/plantings_controller_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/controllers/api/v1/plantings_controller_spec.rb b/spec/controllers/api/v1/plantings_controller_spec.rb index c187e1213..de2f829af 100644 --- a/spec/controllers/api/v1/plantings_controller_spec.rb +++ b/spec/controllers/api/v1/plantings_controller_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do let(:expected_attributes) do { 'crop-name' => my_planting.crop.name, + 'crop-slug' => my_planting.crop.slug, 'description' => my_planting.description, 'expected-lifespan' => nil, 'finish-predicted-at' => nil, @@ -23,6 +24,9 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do 'finished-at' => my_planting.finished_at, 'first-harvest-date' => nil, 'last-harvest-date' => nil, + 'latitude' => my_planting.garden.latitude, + 'longitude' => my_planting.garden.longitude, + 'location' => my_planting.garden.location, 'percentage-grown' => nil, 'planted-at' => '2000-01-01', 'planted-from' => my_planting.planted_from, From 8d87f3c98274205970c5d76c60ad26acabf607f3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 20:38:43 +1300 Subject: [PATCH 12/15] Remove console debug statement --- app/assets/javascripts/places.js.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/javascripts/places.js.erb b/app/assets/javascripts/places.js.erb index f5f58f50b..6d85a7658 100644 --- a/app/assets/javascripts/places.js.erb +++ b/app/assets/javascripts/places.js.erb @@ -61,11 +61,9 @@ function showMap(placesmap) { }); function fetchCropsForMap(url) { - console.log('Fetching crops'); $.getJSON(url, function(crop_data) { $.each(crop_data['data'], function(i, p) { if (p.attributes.latitude && p.attributes.longitude) { - console.log(p); var crop_marker = L.icon({ iconUrl: "/crops/" + p.attributes['crop-slug'] + '.svg', iconSize: [48, 48], From 7ea14bccfe0c65204a58d51bea258821ba3a3627 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 22:32:45 +1300 Subject: [PATCH 13/15] Fix alt on img tag --- app/assets/javascripts/places.js.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/places.js.erb b/app/assets/javascripts/places.js.erb index 6d85a7658..b5917f614 100644 --- a/app/assets/javascripts/places.js.erb +++ b/app/assets/javascripts/places.js.erb @@ -10,7 +10,7 @@ if (document.getElementById("placesmap") !== null) { var placesmap; - if (location.pathname === places_base_path) { //places index page + if (location.pathname === places_base_path || location.pathname === '/') { //places index page placesmap = L.map('placesmap').setView([0.0, -0.0], 2); showMap(placesmap); } @@ -75,7 +75,7 @@ function showMap(placesmap) { var link = "

" + p.attributes['crop-name'] + "

"; var where = "

" + p.attributes.location + "

"; if (p.attributes['thumbnail']) { - where += ''; + where += 'photo of planting'; } marker.bindPopup(link + where).openPopup(); markers.addLayer(marker); @@ -87,6 +87,6 @@ function showMap(placesmap) { return crop_data; }); } - fetchCropsForMap('/api/v1/plantings.json?filter[finished]=false'); + fetchCropsForMap('/api/v1/plantings.json?filter[finished]=false&sort=-planted-at'); placesmap.addLayer(markers); } From 140f625c488b075a161675b5b255f856397b6cb9 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 16 Nov 2019 22:40:06 +1300 Subject: [PATCH 14/15] Add new planting api attributes to test --- spec/controllers/api/v1/plantings_controller_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/controllers/api/v1/plantings_controller_spec.rb b/spec/controllers/api/v1/plantings_controller_spec.rb index de2f829af..b807c724e 100644 --- a/spec/controllers/api/v1/plantings_controller_spec.rb +++ b/spec/controllers/api/v1/plantings_controller_spec.rb @@ -50,6 +50,7 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do let(:expected_attributes) do { 'crop-name' => my_planting.crop.name, + 'crop-slug' => my_planting.crop.slug, 'description' => my_planting.description, 'expected-lifespan' => nil, 'finish-predicted-at' => nil, @@ -57,6 +58,9 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do 'finished-at' => my_planting.finished_at, 'first-harvest-date' => nil, 'last-harvest-date' => nil, + 'latitude' => my_planting.garden.latitude, + 'longitude' => my_planting.garden.longitude, + 'location' => my_planting.garden.location, 'percentage-grown' => nil, 'planted-at' => '2000-01-01', 'planted-from' => my_planting.planted_from, From 0e8a085ccef749ec982f69a3c791624fd9ca7d03 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2019 07:18:43 +0000 Subject: [PATCH 15/15] Bump scout_apm from 2.6.3 to 2.6.4 Bumps [scout_apm](https://github.com/scoutapp/scout_apm_ruby) from 2.6.3 to 2.6.4. - [Release notes](https://github.com/scoutapp/scout_apm_ruby/releases) - [Changelog](https://github.com/scoutapp/scout_apm_ruby/blob/master/CHANGELOG.markdown) - [Commits](https://github.com/scoutapp/scout_apm_ruby/compare/v2.6.3...v2.6.4) Signed-off-by: dependabot-preview[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index e85b300ce..28207b053 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -477,7 +477,7 @@ GEM sprockets (> 3.0) sprockets-rails tilt - scout_apm (2.6.3) + scout_apm (2.6.4) parser searchkick (4.1.0) activemodel (>= 5)