0400-geo-location.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. return function(form, uci)
  2. local site = require 'gluon.site_config'
  3. local location = uci:get_first("gluon-node-info", "location")
  4. local function show_altitude()
  5. if ((site.config_mode or {}).geo_location or {}).show_altitude ~= false then
  6. return true
  7. end
  8. return uci:get_bool("gluon-node-info", location, "altitude")
  9. end
  10. local text = translate(
  11. 'If you want the location of your node to ' ..
  12. 'be displayed on the map, you can enter its coordinates here.'
  13. )
  14. if show_altitude() then
  15. text = text .. ' ' .. translate("gluon-config-mode:altitude-help")
  16. end
  17. local s = form:section(Section, nil, text)
  18. local o
  19. local share_location = s:option(Flag, "location", translate("Show node on the map"))
  20. share_location.default = uci:get_bool("gluon-node-info", location, "share_location")
  21. function share_location:write(data)
  22. uci:set("gluon-node-info", location, "share_location", data)
  23. end
  24. o = s:option(Value, "latitude", translate("Latitude"), translatef("e.g. %s", "53.873621"))
  25. o.default = uci:get("gluon-node-info", location, "latitude")
  26. o:depends(share_location, true)
  27. o.datatype = "float"
  28. function o:write(data)
  29. uci:set("gluon-node-info", location, "latitude", data)
  30. end
  31. o = s:option(Value, "longitude", translate("Longitude"), translatef("e.g. %s", "10.689901"))
  32. o.default = uci:get("gluon-node-info", location, "longitude")
  33. o:depends(share_location, true)
  34. o.datatype = "float"
  35. function o:write(data)
  36. uci:set("gluon-node-info", location, "longitude", data)
  37. end
  38. if show_altitude() then
  39. o = s:option(Value, "altitude", translate("gluon-config-mode:altitude-label"), translatef("e.g. %s", "11.51"))
  40. o.default = uci:get("gluon-node-info", location, "altitude")
  41. o:depends(share_location, true)
  42. o.datatype = "float"
  43. o.optional = true
  44. function o:write(data)
  45. if data then
  46. uci:set("gluon-node-info", location, "altitude", data)
  47. else
  48. uci:delete("gluon-node-info", location, "altitude")
  49. end
  50. end
  51. end
  52. return {'gluon-node-info'}
  53. end