nav.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. module("luci.tools.freifunk-wizard.nav", package.seeall)
  2. function maybe_redirect_to_successor()
  3. local pre, suc = get()
  4. if suc then
  5. luci.http.redirect(luci.dispatcher.build_url("wizard", suc.href))
  6. end
  7. end
  8. function get()
  9. local disp = require "luci.dispatcher"
  10. local request = disp.context.path
  11. local category = request[1]
  12. local cattree = category and disp.node(category)
  13. local childs = disp.node_childs(cattree)
  14. local predecessor = nil
  15. local successor = nil
  16. if #childs > 0 then
  17. local found_pre = false
  18. for i, r in ipairs(childs) do
  19. local nnode = cattree.nodes[r]
  20. nnode.href = r
  21. if r == request[2] then
  22. found_pre = true
  23. elseif found_pre and successor == nil then
  24. successor = nnode
  25. end
  26. if not found_pre then
  27. predecessor = nnode
  28. end
  29. end
  30. end
  31. return predecessor, successor
  32. end