1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2025-07-23 17:19:47 +02:00

the info page now use the silk framework

This commit is contained in:
Xuan Sang LE
2018-08-23 15:22:59 +02:00
parent 5f5c165f0b
commit dc9e9a85d6
14 changed files with 271 additions and 28 deletions

View File

@ -1,10 +1,47 @@
IndexController = BaseController:extends{
class = "IndexController",
registry = {},
models = { "sections", "user", "category" }
models = { "sections", "category" }
}
local sectionsByCid = function(db, id)
local cond = { exp = { ["="] = { cid = id } } , order = { start = "DESC" } }
local data, a = db:find(cond)
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 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" } }
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)
end
cat.children = children
else
cat.sections = sectionsByCid(self.sections,cat.id)
end
end
self.template:set("data", data)
self.template:set("toc", toc)
return true
end
function IndexController:notoc(...)
self.template:setView("index")
return self:index(table.unpack({...}))
end

View File

@ -0,0 +1,7 @@
TocController = BaseController:extends{
class = "TocController"
}
function TocController:index(...)
return true
end

View File

@ -0,0 +1,14 @@
UserController = BaseController:extends{
class = "UserController",
models = {"user"}
}
function UserController:index(...)
local args = {...}
local data = self.user:findAll()
if not data or not data[1] then
self:error("Cannot fetch user info")
end
self.template:set("data", data[1])
return true
end