merge address & coordinates in one location object
to provide a clear arrangement of all location data - add 'L' to predefs for pronto because it is part of the leaflet library - fix: show address template only with an address present with merging the location objects into one, only the objects within the location object can be empty (#5813)
This commit is contained in:
parent
298e195a8f
commit
f92a2ee0dd
9 changed files with 36 additions and 34 deletions
|
|
@ -39,8 +39,8 @@ app.views.Content = app.views.Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
location: function(){
|
location: function(){
|
||||||
var address = this.model.get('address')? this.model.get('address') : '';
|
var location = this.model.get("location")? this.model.get("location") : "";
|
||||||
return address;
|
return location;
|
||||||
},
|
},
|
||||||
|
|
||||||
collapseOversized : function() {
|
collapseOversized : function() {
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ app.views.LocationMap = app.views.Content.extend({
|
||||||
templateName: "status-message-map",
|
templateName: "status-message-map",
|
||||||
|
|
||||||
map: function() {
|
map: function() {
|
||||||
var coordinates = this.model.get("coordinates");
|
var location = this.model.get("location");
|
||||||
|
|
||||||
// if (coordinates != "" && tileserver.enable) { // for when the tileserver is set via the diaspora.yml
|
// if (coordinates != "" && tileserver.enable) { // for when the tileserver is set via the diaspora.yml
|
||||||
if (coordinates.lat) {
|
if (location.lat) {
|
||||||
var tileLayerSource = "https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}";
|
var tileLayerSource = "https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}";
|
||||||
var map = L.map("map").setView([coordinates.lat, coordinates.lng], 16);
|
var map = L.map("map").setView([location.lat, location.lng], 16);
|
||||||
var attribution = "Map data © <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors, " +
|
var attribution = "Map data © <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors, " +
|
||||||
"<a href='http://creativecommons.org/licenses/by-sa/2.0/''>CC-BY-SA</a>, " +
|
"<a href='http://creativecommons.org/licenses/by-sa/2.0/''>CC-BY-SA</a>, " +
|
||||||
"Imagery © <a href='http://mapbox.com'>Mapbox</a>";
|
"Imagery © <a href='http://mapbox.com'>Mapbox</a>";
|
||||||
|
|
@ -21,7 +21,7 @@ app.views.LocationMap = app.views.Content.extend({
|
||||||
accessToken: "pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA"
|
accessToken: "pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA"
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
var markerOnMap = L.marker(coordinates).addTo(map);
|
var markerOnMap = L.marker(location).addTo(map);
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{{#if location}}
|
{{#if location.address}}
|
||||||
<div class='near-from'>
|
<div class='near-from'>
|
||||||
<a href="/posts/{{id}}">{{ t "publisher.near_from" location=location}}</a>
|
<a href="/posts/{{id}}">{{ t "publisher.near_from" location=location.address}}</a>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{{#if location}}
|
{{#if location.lat}}
|
||||||
<div id="map">
|
<div id="map">
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
||||||
|
|
@ -44,12 +44,12 @@ class Reshare < Post
|
||||||
absolute_root.try(:photos) || super
|
absolute_root.try(:photos) || super
|
||||||
end
|
end
|
||||||
|
|
||||||
def address
|
def post_location
|
||||||
absolute_root.try(:location).try(:address)
|
{
|
||||||
end
|
address: absolute_root.try(:location).try(:address),
|
||||||
|
lat: absolute_root.try(:location).try(:lat),
|
||||||
def coordinates
|
lng: absolute_root.try(:location).try(:lng)
|
||||||
{lat: absolute_root.try(:location).try(:lat), lng: absolute_root.try(:location).try(:lng)}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def poll
|
def poll
|
||||||
|
|
|
||||||
|
|
@ -158,12 +158,12 @@ class StatusMessage < Post
|
||||||
self.open_graph_url = self.message.urls[0]
|
self.open_graph_url = self.message.urls[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
def address
|
def post_location
|
||||||
location.try(:address)
|
{
|
||||||
end
|
address: location.try(:address),
|
||||||
|
lat: location.try(:lat),
|
||||||
def coordinates
|
lng: location.try(:lng)
|
||||||
{lat: location.try(:lat), lng: location.try(:lng)}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
"punycode",
|
"punycode",
|
||||||
"qq",
|
"qq",
|
||||||
"blueimp",
|
"blueimp",
|
||||||
|
"L",
|
||||||
"loginAs",
|
"loginAs",
|
||||||
"logout",
|
"logout",
|
||||||
"spec",
|
"spec",
|
||||||
|
|
|
||||||
|
|
@ -291,23 +291,24 @@ describe Reshare, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".coordinates" do
|
describe "#post_location" do
|
||||||
let(:status_message) { build(:status_message, text: "This is a status_message", author: bob.person, public: true) }
|
let(:status_message) { build(:status_message, text: "This is a status_message", author: bob.person, public: true) }
|
||||||
let(:reshare) { create(:reshare, root: status_message) }
|
let(:reshare) { create(:reshare, root: status_message) }
|
||||||
|
|
||||||
context "with location" do
|
context "with location" do
|
||||||
let(:location) { build(:location) }
|
let(:location) { build(:location) }
|
||||||
|
|
||||||
it "should deliver coordinates" do
|
it "should deliver address and coordinates" do
|
||||||
status_message.location = location
|
status_message.location = location
|
||||||
expect(reshare.coordinates).to include(lat: location.lat, lng: location.lng)
|
expect(reshare.post_location).to include(address: location.address, lat: location.lat, lng: location.lng)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "without location" do
|
context "without location" do
|
||||||
it "should deliver empty coordinates" do
|
it "should deliver empty address and coordinates" do
|
||||||
expect(reshare.coordinates[:lat]).to be_nil
|
expect(reshare.post_location[:address]).to be_nil
|
||||||
expect(reshare.coordinates[:lng]).to be_nil
|
expect(reshare.post_location[:lat]).to be_nil
|
||||||
|
expect(reshare.post_location[:lng]).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -444,22 +444,23 @@ describe StatusMessage, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".coordinates" do
|
describe "#coordinates" do
|
||||||
let(:status_message) { build(:status_message, text: @message_text) }
|
let(:status_message) { build(:status_message, text: @message_text) }
|
||||||
|
|
||||||
context "with location" do
|
context "with location" do
|
||||||
let(:location) { build(:location) }
|
let(:location) { build(:location) }
|
||||||
|
|
||||||
it "should deliver coordinates" do
|
it "should deliver address and coordinates" do
|
||||||
status_message.location = location
|
status_message.location = location
|
||||||
expect(status_message.coordinates).to include(lat: location.lat, lng: location.lng)
|
expect(status_message.post_location).to include(address: location.address, lat: location.lat, lng: location.lng)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "without location" do
|
context "without location" do
|
||||||
it "should deliver empty coordinates" do
|
it "should deliver empty address and coordinates" do
|
||||||
expect(status_message.coordinates[:lat]).to be_nil
|
expect(status_message.post_location[:address]).to be_nil
|
||||||
expect(status_message.coordinates[:lng]).to be_nil
|
expect(status_message.post_location[:lat]).to be_nil
|
||||||
|
expect(status_message.post_location[:lng]).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue