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:
zaziemo 2015-08-04 11:55:45 +02:00 committed by realtin
parent 298e195a8f
commit f92a2ee0dd
9 changed files with 36 additions and 34 deletions

View file

@ -39,8 +39,8 @@ app.views.Content = app.views.Base.extend({
},
location: function(){
var address = this.model.get('address')? this.model.get('address') : '';
return address;
var location = this.model.get("location")? this.model.get("location") : "";
return location;
},
collapseOversized : function() {

View file

@ -4,12 +4,12 @@ app.views.LocationMap = app.views.Content.extend({
templateName: "status-message-map",
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.lat) {
if (location.lat) {
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 &copy; <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors, " +
"<a href='http://creativecommons.org/licenses/by-sa/2.0/''>CC-BY-SA</a>, " +
"Imagery © <a href='http://mapbox.com'>Mapbox</a>";
@ -21,7 +21,7 @@ app.views.LocationMap = app.views.Content.extend({
accessToken: "pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA"
}).addTo(map);
var markerOnMap = L.marker(coordinates).addTo(map);
var markerOnMap = L.marker(location).addTo(map);
return map;
}

View file

@ -1,5 +1,5 @@
{{#if location}}
{{#if location.address}}
<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>
{{/if}}

View file

@ -1,4 +1,4 @@
{{#if location}}
{{#if location.lat}}
<div id="map">
</div>
{{/if}}

View file

@ -44,12 +44,12 @@ class Reshare < Post
absolute_root.try(:photos) || super
end
def address
absolute_root.try(:location).try(:address)
end
def coordinates
{lat: absolute_root.try(:location).try(:lat), lng: absolute_root.try(:location).try(:lng)}
def post_location
{
address: absolute_root.try(:location).try(:address),
lat: absolute_root.try(:location).try(:lat),
lng: absolute_root.try(:location).try(:lng)
}
end
def poll

View file

@ -158,12 +158,12 @@ class StatusMessage < Post
self.open_graph_url = self.message.urls[0]
end
def address
location.try(:address)
end
def coordinates
{lat: location.try(:lat), lng: location.try(:lng)}
def post_location
{
address: location.try(:address),
lat: location.try(:lat),
lng: location.try(:lng)
}
end
protected

View file

@ -53,7 +53,7 @@
"punycode",
"qq",
"blueimp",
"L",
"loginAs",
"logout",
"spec",

View file

@ -291,23 +291,24 @@ describe Reshare, type: :model do
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(:reshare) { create(:reshare, root: status_message) }
context "with location" do
let(:location) { build(:location) }
it "should deliver coordinates" do
it "should deliver address and coordinates" do
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
context "without location" do
it "should deliver empty coordinates" do
expect(reshare.coordinates[:lat]).to be_nil
expect(reshare.coordinates[:lng]).to be_nil
it "should deliver empty address and coordinates" do
expect(reshare.post_location[:address]).to be_nil
expect(reshare.post_location[:lat]).to be_nil
expect(reshare.post_location[:lng]).to be_nil
end
end
end

View file

@ -444,22 +444,23 @@ describe StatusMessage, type: :model do
end
end
describe ".coordinates" do
describe "#coordinates" do
let(:status_message) { build(:status_message, text: @message_text) }
context "with location" do
let(:location) { build(:location) }
it "should deliver coordinates" do
it "should deliver address and coordinates" do
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
context "without location" do
it "should deliver empty coordinates" do
expect(status_message.coordinates[:lat]).to be_nil
expect(status_message.coordinates[:lng]).to be_nil
it "should deliver empty address and coordinates" do
expect(status_message.post_location[:address]).to be_nil
expect(status_message.post_location[:lat]).to be_nil
expect(status_message.post_location[:lng]).to be_nil
end
end
end