1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-28 02:08:22 +01:00
antd-web-apps/info/controllers/IndexController.lua

66 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)
2019-06-11 18:35:34 +02:00
local cond = {exp = { ["and"] = {{["="] = {cid = id}}, {["= "] = {publish = 1}} }}, order = {start = "DESC"}}
local data, a = db:find(cond)
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
2018-08-28 10:49:12 +02:00
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
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})
cond = {exp = {["="] = {pid = cat.id}}, order = {name = "ASC"}}
local children, b = self.category:find(cond)
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"
local cmd = "wkhtmltopdf "..HTTP_ROOT.."/"..self.registry.user.."/notoc "..tmp_file
2018-09-11 10:35:02 +02:00
local r = os.execute(cmd)
if r then
local mime = std.mimeOf(tmp_file)
std.header(mime)
2020-06-07 15:20:21 +02:00
std.f(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