-- @param path Controller base directory
-- @param suffix Controller file suffix
function createindex_plain(path, suffix)
+ local controllers = util.combine(
+ luci.fs.glob(path .. "*" .. suffix) or {},
+ luci.fs.glob(path .. "*/*" .. suffix) or {}
+ )
+
if indexcache then
local cachedate = fs.mtime(indexcache)
- if cachedate and cachedate > fs.mtime(path) then
+ if cachedate then
+ local realdate = 0
+ for _, obj in ipairs(controllers) do
+ local omtime = fs.mtime(path .. "/" .. obj)
+ realdate = (omtime and omtime > realdate) and omtime or realdate
+ end
- assert(
- sys.process.info("uid") == fs.stat(indexcache, "uid")
- and fs.stat(indexcache, "mode") == "rw-------",
- "Fatal: Indexcache is not sane!"
- )
+ if cachedate > realdate then
+ assert(
+ sys.process.info("uid") == fs.stat(indexcache, "uid")
+ and fs.stat(indexcache, "mode") == "rw-------",
+ "Fatal: Indexcache is not sane!"
+ )
- index = loadfile(indexcache)()
- return index
+ index = loadfile(indexcache)()
+ return index
+ end
end
end
index = {}
- local controllers = util.combine(
- luci.fs.glob(path .. "*" .. suffix) or {},
- luci.fs.glob(path .. "*/*" .. suffix) or {}
- )
-
for i,c in ipairs(controllers) do
local module = "luci.controller." .. c:sub(#path+1, #c-#suffix):gsub("/", ".")
local mod = require(module)
local ctx = context
local tree = {nodes={}}
+ local modi = {}
ctx.treecache = setmetatable({}, {__mode="v"})
ctx.tree = tree
+ ctx.modifiers = modi
-- Load default translation
require "luci.i18n".loadc("default")
v()
end
+ local function modisort(a,b)
+ return modi[a].order < modi[b].order
+ end
+
+ for _, v in util.spairs(modi, modisort) do
+ scope._NAME = v.module
+ setfenv(v.func, scope)
+ v.func()
+ end
+
return tree
end
+--- Register a tree modifier.
+-- @param func Modifier function
+-- @param order Modifier order value (optional)
+function modifier(func, order)
+ context.modifiers[#context.modifiers+1] = {
+ func = func,
+ order = order or 0,
+ module = getfenv(2)._NAME
+ }
+end
+
--- Clone a node of the dispatching tree to another position.
-- @param path Virtual path destination
-- @param clone Virtual path source
local c = _create_node({...})
c.module = getfenv(2)._NAME
- c.path = arg
c.auto = nil
return c
local c = cache[name]
if not c then
+ local new = {nodes={}, auto=true, path=util.clone(path)}
local last = table.remove(path)
+
c = _create_node(path, cache)
- local new = {nodes={}, auto=true}
c.nodes[last] = new
cache[name] = new
end
end
+ if config.on_valid_to and state and state > 0 and state < 2 then
+ luci.http.redirect(config.on_valid_to)
+ return
+ end
+
+ if config.on_changed_to and state and state > 1 then
+ luci.http.redirect(config.on_changed_to)
+ return
+ end
+
+ if config.on_success_to and state and state > 0 then
+ luci.http.redirect(config.on_success_to)
+ return
+ end
+
if config.state_handler then
if not config.state_handler(state, maps) then
return