1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-29 10:48:21 +01:00
antd-web-apps/info/controllers/IndexController.lua

78 lines
1.9 KiB
Lua
Raw Normal View History

2018-08-28 10:49:12 +02:00
BaseController:subclass(
"IndexController",
2018-08-27 20:10:53 +02:00
{
registry = {},
2018-08-28 10:49:12 +02:00
models = {"sections", "category"}
}
)
2018-08-23 11:43:42 +02:00
local sectionsByCid = function(db, id)
local data, a = db:find({
where = {
cid = id,
publish = 1
},
order = {"start$desc"}
})
2018-08-28 10:49:12 +02:00
return data, a
end
2018-08-23 11:43:42 +02:00
function IndexController:index(...)
local args = {...}
-- now read all the data
-- get all root sections as the toc
local data, a = self.category:find({
where = {
pid = 0
},
order = {"name$asc"}
})
local toc = {}
if not data then
return self:error("Cannot query the ToC")
end
-- find all children category of the toc
2018-08-28 10:49:12 +02:00
for key, cat in pairs(data) do
cat.name = cat.name:gsub("^%d+%.", "")
table.insert(toc, {cat.name, cat.id})
local children, b = self.category:find({
where = {
pid = cat.id
},
order = {"name$asc"}
})
if children and #children > 0 then
2018-08-28 10:49:12 +02:00
for k, v in pairs(children) do
v.sections = sectionsByCid(self.sections, v.id)
end
cat.children = children
else
2018-08-28 10:49:12 +02:00
cat.sections = sectionsByCid(self.sections, cat.id)
end
end
self.template:set("data", data)
self.template:set("toc", toc)
2018-08-23 11:43:42 +02:00
return true
end
function IndexController:notoc(...)
self.template:setView("index")
return self:index(table.unpack({...}))
end
2018-08-23 15:50:55 +02:00
function IndexController:actionnotfound(...)
return self:notoc(table.unpack({...}))
2018-08-28 10:49:12 +02:00
end
2018-09-11 10:35:02 +02:00
function IndexController:pdf(...)
2020-06-07 19:46:59 +02:00
local tmp_file = WWW_ROOT.."/cv_exported.pdf"
2021-01-05 20:12:35 +01:00
local cmd = "wkhtmltopdf "..HTTP_ROOT.."/"..self.registry.user.."/index/notoc "..tmp_file
print(cmd)
2018-09-11 10:35:02 +02:00
local r = os.execute(cmd)
if r then
2022-11-08 10:32:26 +01:00
std.sendFile(tmp_file)
2018-09-11 10:35:02 +02:00
return false
else
return self:error("Sorry.Problem generate PDF file")
end
2020-06-07 15:20:21 +02:00
end