0400-geo-location.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. local cbi = require "luci.cbi"
  2. local i18n = require "luci.i18n"
  3. local uci = luci.model.uci.cursor()
  4. local site = require 'gluon.site_config'
  5. local M = {}
  6. local function show_altitude()
  7. if ((site.config_mode or {}).geo_location or {}).show_altitude ~= false then
  8. return true
  9. end
  10. if uci:get_first("gluon-node-info", "location", "altitude") then
  11. return true
  12. end
  13. return false
  14. end
  15. function M.section(form)
  16. local text = i18n.translate('If you want the location of your node to '
  17. .. 'be displayed on the map, you can enter its coordinates here.')
  18. if show_altitude() then
  19. text = text .. ' ' .. i18n.translate("gluon-config-mode:altitude-help")
  20. end
  21. local s = form:section(cbi.SimpleSection, nil, text)
  22. local o
  23. o = s:option(cbi.Flag, "_location", i18n.translate("Show node on the map"))
  24. o.default = uci:get_first("gluon-node-info", "location", "share_location", o.disabled)
  25. o.rmempty = false
  26. o = s:option(cbi.Value, "_latitude", i18n.translate("Latitude"))
  27. o.default = uci:get_first("gluon-node-info", "location", "latitude")
  28. o:depends("_location", "1")
  29. o.rmempty = false
  30. o.datatype = "float"
  31. o.description = i18n.translatef("e.g. %s", "53.873621")
  32. o = s:option(cbi.Value, "_longitude", i18n.translate("Longitude"))
  33. o.default = uci:get_first("gluon-node-info", "location", "longitude")
  34. o:depends("_location", "1")
  35. o.rmempty = false
  36. o.datatype = "float"
  37. o.description = i18n.translatef("e.g. %s", "10.689901")
  38. if show_altitude() then
  39. o = s:option(cbi.Value, "_altitude", i18n.translate("gluon-config-mode:altitude-label"))
  40. o.default = uci:get_first("gluon-node-info", "location", "altitude")
  41. o:depends("_location", "1")
  42. o.rmempty = true
  43. o.datatype = "float"
  44. o.description = i18n.translatef("e.g. %s", "11.51")
  45. end
  46. end
  47. function M.handle(data)
  48. local sname = uci:get_first("gluon-node-info", "location")
  49. uci:set("gluon-node-info", sname, "share_location", data._location)
  50. if data._location and data._latitude ~= nil and data._longitude ~= nil then
  51. uci:set("gluon-node-info", sname, "latitude", data._latitude:trim())
  52. uci:set("gluon-node-info", sname, "longitude", data._longitude:trim())
  53. if data._altitude ~= nil then
  54. uci:set("gluon-node-info", sname, "altitude", data._altitude:trim())
  55. else
  56. uci:delete("gluon-node-info", sname, "altitude")
  57. end
  58. end
  59. uci:save("gluon-node-info")
  60. uci:commit("gluon-node-info")
  61. end
  62. return M