outsource map credentials

and allow podmin to enable and disable the feature
(#5813)
This commit is contained in:
zaziemo 2015-08-20 12:00:21 +02:00 committed by realtin
parent 6716b4c175
commit e5cc8dff0e
5 changed files with 57 additions and 36 deletions

View file

@ -7,35 +7,37 @@ app.views.LocationStream = app.views.Content.extend({
templateName: "status-message-location", templateName: "status-message-location",
toggleMap: function () { toggleMap: function () {
var mapContainer = this.$el.find(".mapContainer"); if (gon.appConfig.map.enabled){
var mapContainer = this.$el.find(".mapContainer");
if (mapContainer.hasClass("empty")) { if (mapContainer.hasClass("empty")) {
var location = this.model.get("location"); var location = this.model.get("location");
mapContainer.css("height", "150px"); mapContainer.css("height", "150px");
if (location.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(mapContainer[0]).setView([location.lat, location.lng], 16); var map = L.map(mapContainer[0]).setView([location.lat, location.lng], 16);
var attribution = "Map data &copy; <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors, " + 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>, " + "<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>";
L.tileLayer(tileLayerSource, { L.tileLayer(tileLayerSource, {
attribution: attribution, attribution: attribution,
maxZoom: 18, maxZoom: 18,
id: "zaziemo.mpn66kn8", id: gon.appConfig.map.mapbox.id,
accessToken: "pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA" accessToken: gon.appConfig.map.mapbox.accessToken
}).addTo(map); }).addTo(map);
var markerOnMap = L.marker(location).addTo(map); var markerOnMap = L.marker(location).addTo(map);
mapContainer.removeClass("empty"); mapContainer.removeClass("empty");
return map; return map;
} }
} else { } else {
if (mapContainer.css("display") === "none") { if (mapContainer.css("display") === "none") {
mapContainer.css("display", "block"); mapContainer.css("display", "block");
} else { } else {
mapContainer.css("display", "none"); mapContainer.css("display", "none");
}
} }
} }
} }

View file

@ -27,7 +27,7 @@ app.views.SinglePostContent = app.views.Base.extend({
}, },
map : function(){ map : function(){
if (this.$el.find(".mapContainer")){ if (this.$el.find(".mapContainer")&&gon.appConfig.map.enabled){
// find and set height of mapContainer to max size of the container // find and set height of mapContainer to max size of the container
// which is necessary to have all necessary tiles prerendered // which is necessary to have all necessary tiles prerendered
@ -45,8 +45,8 @@ app.views.SinglePostContent = app.views.Base.extend({
L.tileLayer(tileLayerSource, { L.tileLayer(tileLayerSource, {
attribution: attribution, attribution: attribution,
maxZoom: 18, maxZoom: 18,
id: "zaziemo.mpn66kn8", id: gon.appConfig.map.mapbox.id,
accessToken: "pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA" accessToken: gon.appConfig.map.mapbox.accessToken
}).addTo(map); }).addTo(map);
// set mapContainer size to a smaller preview size // set mapContainer size to a smaller preview size
@ -56,16 +56,18 @@ app.views.SinglePostContent = app.views.Base.extend({
// put marker on map // put marker on map
var markerOnMap = L.marker(location).addTo(map); var markerOnMap = L.marker(location).addTo(map);
return map; return map;
}; };
}, },
toggleMap: function () { toggleMap: function () {
if (this.$el.find(".mapContainer").css("height") === "75px") { if (gon.appConfig.map.enabled){
this.$el.find(".mapContainer").css("height", "200px"); if (this.$el.find(".mapContainer").css("height") === "75px") {
this.$el.find(".leaflet-control-zoom").css("display", "block"); this.$el.find(".mapContainer").css("height", "200px");
} else { this.$el.find(".leaflet-control-zoom").css("display", "block");
this.$el.find(".mapContainer").css("height", "75px"); } else {
this.$el.find(".leaflet-control-zoom").css("display", "none"); this.$el.find(".mapContainer").css("height", "75px");
this.$el.find(".leaflet-control-zoom").css("display", "none");
}
} }
}, },

View file

@ -145,7 +145,8 @@ class ApplicationController < ActionController::Base
def gon_set_appconfig def gon_set_appconfig
gon.push(appConfig: { gon.push(appConfig: {
chat: {enabled: AppConfig.chat.enabled?}, chat: {enabled: AppConfig.chat.enabled?},
settings: {podname: AppConfig.settings.pod_name} settings: {podname: AppConfig.settings.pod_name},
map: {enabled: AppConfig.map.enabled?, mapbox: AppConfig.map.mapbox}
}) })
end end

View file

@ -75,6 +75,11 @@ defaults:
log: log:
file: 'log/vines.log' file: 'log/vines.log'
level: 'info' level: 'info'
map:
enabled: true
mapbox:
id: 'zaziemo.mpn66kn8'
accessToken: 'pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA'
privacy: privacy:
jquery_cdn: false jquery_cdn: false
google_analytics_key: google_analytics_key:

View file

@ -324,6 +324,17 @@ configuration: ## Section
## The debug level logs all XML sent and received by the server. ## The debug level logs all XML sent and received by the server.
#level: 'info' #level: 'info'
## Displaying location of posts in a map. We are using the map tiles of
## https://www.mapbox.com. There you have to create a account to get and ID
## and an access token. If you want to use this feature you can write an email
## to team@diasporafoundation.org and you'll get an unlimited and free account.
map: ##Section
# enable: true
# mapbox:
# id: 'your.id'
# accessToken: 'youraccesstoken'
## Settings potentially affecting the privacy of your users. ## Settings potentially affecting the privacy of your users.
privacy: ## Section privacy: ## Section