mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-11-19 18:08:21 +01:00
fix
This commit is contained in:
parent
3d2e1299b1
commit
692d437c67
@ -1,38 +1,40 @@
|
||||
BaseController:subclass("IndexController",
|
||||
BaseController:subclass(
|
||||
"IndexController",
|
||||
{
|
||||
registry = {},
|
||||
models = { "sections", "category" }
|
||||
})
|
||||
models = {"sections", "category"}
|
||||
}
|
||||
)
|
||||
|
||||
local sectionsByCid = function(db, id)
|
||||
local cond = { exp = { ["="] = { cid = id } } , order = { start = "DESC" } }
|
||||
local cond = {exp = {["="] = {cid = id}}, order = {start = "DESC"}}
|
||||
local data, a = db:find(cond)
|
||||
return data,a
|
||||
return data, a
|
||||
end
|
||||
|
||||
function IndexController:index(...)
|
||||
local args = {...}
|
||||
-- now read all the data
|
||||
-- get all root sections as the toc
|
||||
local cond = { exp = { ["="] = { pid = 0 } }, order = { name = "ASC" } }
|
||||
local cond = {exp = {["="] = {pid = 0}}, order = {name = "ASC"}}
|
||||
local data, a = self.category:find(cond)
|
||||
local toc = {}
|
||||
if not data then
|
||||
return self:error("Cannot query the ToC")
|
||||
end
|
||||
-- find all children category of the toc
|
||||
for key,cat in pairs(data) do
|
||||
cat.name = cat.name:gsub("^%d+%.","")
|
||||
table.insert( toc, {cat.name, cat.id} )
|
||||
cond = { exp = { ["="] = { pid = cat.id } }, order = { name = "ASC" } }
|
||||
for key, cat in pairs(data) do
|
||||
cat.name = cat.name:gsub("^%d+%.", "")
|
||||
table.insert(toc, {cat.name, cat.id})
|
||||
cond = {exp = {["="] = {pid = cat.id}}, order = {name = "ASC"}}
|
||||
local children, b = self.category:find(cond)
|
||||
if children and #children > 0 then
|
||||
for k,v in pairs(children) do
|
||||
v.sections = sectionsByCid(self.sections,v.id)
|
||||
for k, v in pairs(children) do
|
||||
v.sections = sectionsByCid(self.sections, v.id)
|
||||
end
|
||||
cat.children = children
|
||||
else
|
||||
cat.sections = sectionsByCid(self.sections,cat.id)
|
||||
cat.sections = sectionsByCid(self.sections, cat.id)
|
||||
end
|
||||
end
|
||||
self.template:set("data", data)
|
||||
@ -47,4 +49,4 @@ end
|
||||
|
||||
function IndexController:actionnotfound(...)
|
||||
return self:notoc(table.unpack({...}))
|
||||
end
|
||||
end
|
||||
|
@ -1,13 +1,16 @@
|
||||
BaseController:subclass("UserController",{
|
||||
models = {"user"}
|
||||
})
|
||||
BaseController:subclass(
|
||||
"UserController",
|
||||
{
|
||||
models = {"user"}
|
||||
}
|
||||
)
|
||||
|
||||
function UserController:index(...)
|
||||
local args = {...}
|
||||
local data = self.user:findAll()
|
||||
if not data or not data[1] then
|
||||
if not data or not data[1] then
|
||||
self:error("Cannot fetch user info")
|
||||
end
|
||||
self.template:set("data", data[1])
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -21,6 +21,7 @@ end
|
||||
|
||||
function BaseObject:error(msg, trace)
|
||||
html()
|
||||
--local line = debug.getinfo(1).currentline
|
||||
echo(msg)
|
||||
self:log(msg,"ERROR")
|
||||
if trace then
|
||||
|
Loading…
Reference in New Issue
Block a user