From b0cc8cf189061ebc221fd418088cf1d2617629bd Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 19 Aug 2018 17:42:48 +0200 Subject: [PATCH] gluon-config-mode-geo-location-osm: add OSM-based location picker gluon-config-mode-geo-location-osm extends the gluon-config-mode-geo-location with a location picker based on OpenStreetMaps. Based-on-patch-by: Jan-Tarek Butt --- docs/user/site.rst | 15 ++++++++ .../Makefile | 20 +++++++++++ .../check_site.lua | 4 +++ .../i18n/de.po | 17 ++++++++++ .../gluon-config-mode-geo-location-osm.pot | 7 ++++ .../gluon/config-mode/geo-location-osm.lua | 34 +++++++++++++++++++ .../gluon-config-mode-geo-location/i18n/de.po | 12 +++---- .../gluon-config-mode-geo-location/i18n/fr.po | 10 +++--- .../i18n/gluon-config-mode-geo-location.pot | 6 ++-- .../config-mode/wizard/0400-geo-location.lua | 23 +++++++++++-- 10 files changed, 130 insertions(+), 18 deletions(-) create mode 100644 package/gluon-config-mode-geo-location-osm/Makefile create mode 100644 package/gluon-config-mode-geo-location-osm/check_site.lua create mode 100644 package/gluon-config-mode-geo-location-osm/i18n/de.po create mode 100644 package/gluon-config-mode-geo-location-osm/i18n/gluon-config-mode-geo-location-osm.pot create mode 100644 package/gluon-config-mode-geo-location-osm/luasrc/usr/lib/lua/gluon/config-mode/geo-location-osm.lua diff --git a/docs/user/site.rst b/docs/user/site.rst index 29ef966cdd3..023ca0051f1 100644 --- a/docs/user/site.rst +++ b/docs/user/site.rst @@ -407,6 +407,13 @@ config_mode \: optional package. Set *geo_location.show_altitude* to *true* if you want the altitude field to be visible. + The *geo_location.osm* section is only relevant when the *gluon-config-mode-geo-location-osm* + package is used. The *center.lon* and *center.lat* values are mandatory in this case and + define the default center of the map when no position has been picked yet. The *zoom* level + defaults to 12 in this case. *openlayers_url* allows to override the base URL of the + *build/ol.js* and *css/ol.css* files (the default is + ``https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.1.3``). + The remote login page only shows SSH key configuration by default. A password form can be displayed by setting *remote_login.show_password_form* to true; in this case, *remote_login.min_password_length* defines the @@ -419,6 +426,14 @@ config_mode \: optional }, geo_location = { show_altitude = true, + osm = { + center = { + lon = 52.951947558, + lat = 7.844238281, + }, + zoom = 13, + openlayers_url = 'http://ffac/ol', + }, }, remote_login = { show_password_form = true, diff --git a/package/gluon-config-mode-geo-location-osm/Makefile b/package/gluon-config-mode-geo-location-osm/Makefile new file mode 100644 index 00000000000..4dbaf9d00b5 --- /dev/null +++ b/package/gluon-config-mode-geo-location-osm/Makefile @@ -0,0 +1,20 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-config-mode-geo-location-osm +PKG_VERSION:=1 + +include ../gluon.mk + +define Package/gluon-config-mode-geo-location-osm + TITLE:=Set geographic location of a node (map support) + DEPENDS:=+gluon-config-mode-geo-location +gluon-web-osm +endef + +define Package/gluon-config-mode-geo-location-osm/install + $(Gluon/Build/Install) + + $(INSTALL_DIR) $(1)/lib/gluon/config-mode/www/static/ + $(LN) /lib/gluon/web/www/static/gluon-web-osm.js $(1)/lib/gluon/config-mode/www/static/ +endef + +$(eval $(call BuildPackageGluon,gluon-config-mode-geo-location-osm)) diff --git a/package/gluon-config-mode-geo-location-osm/check_site.lua b/package/gluon-config-mode-geo-location-osm/check_site.lua new file mode 100644 index 00000000000..8e69ba0a14f --- /dev/null +++ b/package/gluon-config-mode-geo-location-osm/check_site.lua @@ -0,0 +1,4 @@ +need_number(in_site({'config_mode', 'geo_location', 'osm', 'center', 'lon'})) +need_number(in_site({'config_mode', 'geo_location', 'osm', 'center', 'lat'})) +need_number(in_site({'config_mode', 'geo_location', 'osm', 'zoom'}), false) +need_string(in_site({'config_mode', 'geo_location', 'osm', 'openlayers_url'}), false) diff --git a/package/gluon-config-mode-geo-location-osm/i18n/de.po b/package/gluon-config-mode-geo-location-osm/i18n/de.po new file mode 100644 index 00000000000..dc0e23dfd24 --- /dev/null +++ b/package/gluon-config-mode-geo-location-osm/i18n/de.po @@ -0,0 +1,17 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Project-Id-Version: gluon-config-mode-geo-location\n" +"Last-Translator: Matthias Schiffer \n" +"Language-Team: German\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +msgid "" +"You may also select the position on the map displayed below if your computer " +"is connected to the internet at the moment." +msgstr "" +"Wenn dein Computer aktuell mit dem Internet verbunden ist, kann die Position " +"auch auf der hier angezeigten Karte ausgewählt werden." diff --git a/package/gluon-config-mode-geo-location-osm/i18n/gluon-config-mode-geo-location-osm.pot b/package/gluon-config-mode-geo-location-osm/i18n/gluon-config-mode-geo-location-osm.pot new file mode 100644 index 00000000000..0a987630f2f --- /dev/null +++ b/package/gluon-config-mode-geo-location-osm/i18n/gluon-config-mode-geo-location-osm.pot @@ -0,0 +1,7 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +msgid "" +"You may also select the position on the map displayed below if your computer " +"is connected to the internet at the moment." +msgstr "" diff --git a/package/gluon-config-mode-geo-location-osm/luasrc/usr/lib/lua/gluon/config-mode/geo-location-osm.lua b/package/gluon-config-mode-geo-location-osm/luasrc/usr/lib/lua/gluon/config-mode/geo-location-osm.lua new file mode 100644 index 00000000000..3ebec2622d1 --- /dev/null +++ b/package/gluon-config-mode-geo-location-osm/luasrc/usr/lib/lua/gluon/config-mode/geo-location-osm.lua @@ -0,0 +1,34 @@ +local osm = require 'gluon.web.model.osm' +local site = require 'gluon.site' + +local tonumber = tonumber + + +module 'gluon.config-mode.geo-location-osm' + +MapValue = osm.MapValue + +function help(i18n) + local pkg_i18n = i18n 'gluon-config-mode-geo-location-osm' + return pkg_i18n.translate( + 'You may also select the position on the map displayed below if your computer is connected to the internet at the moment.' + ) +end + +function options(lon, lat) + local config = site.config_mode.geo_location.osm + + local map_options = { + openlayers_url = config.openlayers_url(), + zoom = config.zoom(12), + pos = config.center(), + } + + if lon and lat then + map_options.zoom = 18 + map_options.pos = { lon = tonumber(lon), lat = tonumber(lat) } + map_options.set = true + end + + return map_options +end diff --git a/package/gluon-config-mode-geo-location/i18n/de.po b/package/gluon-config-mode-geo-location/i18n/de.po index 70d955c9079..82d475651ec 100644 --- a/package/gluon-config-mode-geo-location/i18n/de.po +++ b/package/gluon-config-mode-geo-location/i18n/de.po @@ -14,11 +14,11 @@ msgid "Altitude" msgstr "Höhe" msgid "" -"If you want the location of your node to be displayed on the map, you can " -"enter its coordinates here." +"If you want the location of your node to be displayed on public maps, you " +"can enter its coordinates here." msgstr "" -"Um deinen Knoten auf der Karte anzeigen zu können, benötigen wir seine " -"Koordinaten. Hier hast du die Möglichkeit, diese zu hinterlegen." +"Um deinen Knoten auf öffentlichen Karten anzeigen zu können, benötigen wir " +"seine Koordinaten. Hier hast du die Möglichkeit, diese zu hinterlegen." msgid "Latitude" msgstr "Breitengrad" @@ -26,8 +26,8 @@ msgstr "Breitengrad" msgid "Longitude" msgstr "Längengrad" -msgid "Show node on the map" -msgstr "Knoten auf der Karte anzeigen" +msgid "Advertise node position" +msgstr "Knotenposition veröffentlichen" msgid "" "Specifying the altitude is optional; it should only be filled in if a " diff --git a/package/gluon-config-mode-geo-location/i18n/fr.po b/package/gluon-config-mode-geo-location/i18n/fr.po index e632d29f74b..22efaa78433 100644 --- a/package/gluon-config-mode-geo-location/i18n/fr.po +++ b/package/gluon-config-mode-geo-location/i18n/fr.po @@ -14,11 +14,9 @@ msgid "Altitude" msgstr "Hauteur" msgid "" -"If you want the location of your node to be displayed on the map, you can " -"enter its coordinates here." +"If you want the location of your node to be displayed on public maps, you " +"can enter its coordinates here." msgstr "" -"Pour Afficher votre nœud sur la Carte nous avons besoin de ses coordonnées. " -"Ici vous pouvez entrer sa position." msgid "Latitude" msgstr "Latitude" @@ -26,8 +24,8 @@ msgstr "Latitude" msgid "Longitude" msgstr "Longitude" -msgid "Show node on the map" -msgstr "Afficher le nœud sur la carte" +msgid "Advertise node position" +msgstr "" msgid "" "Specifying the altitude is optional; it should only be filled in if a " diff --git a/package/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot b/package/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot index 5baa748b7eb..008469ca817 100644 --- a/package/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot +++ b/package/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot @@ -5,8 +5,8 @@ msgid "Altitude" msgstr "" msgid "" -"If you want the location of your node to be displayed on the map, you can " -"enter its coordinates here." +"If you want the location of your node to be displayed on public maps, you " +"can enter its coordinates here." msgstr "" msgid "Latitude" @@ -15,7 +15,7 @@ msgstr "" msgid "Longitude" msgstr "" -msgid "Show node on the map" +msgid "Advertise node position" msgstr "" msgid "" diff --git a/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua b/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua index 0d99bef59a9..1e7dcfc0b1e 100644 --- a/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua +++ b/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua @@ -4,6 +4,9 @@ return function(form, uci) local site = require 'gluon.site' + local osm + pcall(function() osm = require 'gluon.config-mode.geo-location-osm' end) + local location = uci:get_first("gluon-node-info", "location") local show_altitude = site.config_mode.geo_location.show_altitude(false) @@ -14,6 +17,9 @@ return function(form, uci) 'If you want the location of your node to ' .. 'be displayed on the map, you can enter its coordinates here.' ) + if osm then + text = text .. ' ' .. osm.help(i18n) + end if show_altitude then text = text .. ' ' .. pkg_i18n.translate( 'Specifying the altitude is optional; it should only be filled in if a accurate ' .. @@ -26,7 +32,7 @@ return function(form, uci) local o - local share_location = s:option(Flag, "location", pkg_i18n.translate("Show node on the map")) + local share_location = s:option(Flag, "location", pkg_i18n.translate("Advertise node position")) share_location.default = uci:get_bool("gluon-node-info", location, "share_location") function share_location:write(data) uci:set("gluon-node-info", location, "share_location", data) @@ -37,21 +43,32 @@ return function(form, uci) end end + local lat = uci:get("gluon-node-info", location, "latitude") + local lon = uci:get("gluon-node-info", location, "longitude") + + local map = {} + if osm then + map = s:option(osm.MapValue, "map", osm.options(lon, lat)) + map:depends(share_location, true) + end + o = s:option(Value, "latitude", pkg_i18n.translate("Latitude"), pkg_i18n.translatef("e.g. %s", "53.873621")) - o.default = uci:get("gluon-node-info", location, "latitude") + o.default = lat o:depends(share_location, true) o.datatype = "float" function o:write(data) uci:set("gluon-node-info", location, "latitude", data) end + map.lat = o o = s:option(Value, "longitude", pkg_i18n.translate("Longitude"), pkg_i18n.translatef("e.g. %s", "10.689901")) - o.default = uci:get("gluon-node-info", location, "longitude") + o.default = lon o:depends(share_location, true) o.datatype = "float" function o:write(data) uci:set("gluon-node-info", location, "longitude", data) end + map.lon = o if show_altitude then o = s:option(Value, "altitude",