1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01: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,6 +1,6 @@
BUILDDIR = ../build/info BUILDDIR = ../build/info
copyfiles = index.ls style.css router.lua models views controllers copyfiles = index.ls style.css router.lua models views controllers logs
main: main:
- mkdir $(BUILDDIR) - mkdir $(BUILDDIR)

View File

@ -1,10 +1,47 @@
IndexController = BaseController:extends{ IndexController = BaseController:extends{
class = "IndexController", class = "IndexController",
registry = {}, 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(...) function IndexController:index(...)
local args = {...} 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 return true
end 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

View File

@ -5,7 +5,7 @@
-- some global variables -- some global variables
DIR_SEP = "/" DIR_SEP = "/"
WWW_ROOT = "/opt/www/htdocs/info" WWW_ROOT = "/opt/www/htdocs/info"
HTTP_ROOT = "https://apps.localhost:9195/" HTTP_ROOT = "https://info.localhost:9195/"
-- class path: path.to.class -- class path: path.to.class
BASE_FRW = "" BASE_FRW = ""
-- class path: path.to.class -- class path: path.to.class
@ -34,19 +34,19 @@ router:setPath(CONTROLLER_ROOT)
-- example of depedencies to the current main route -- example of depedencies to the current main route
-- each layout may have different dependencies -- each layout may have different dependencies
local default_routes_dependencies = { local default_routes_dependencies = {
edit = { user = {
url = "post/edit", url = "user/index",
visibility = "ALL"
},
toc = {
url = "toc/index",
visibility = { visibility = {
shown = true, shown = true,
routes = { routes = {
["post/index"] = true ["index/index"] = true
} }
} }
}, }
--category = {
-- url = "cat/index",
-- visibility = "ALL"
--}
} }
router:route('default', default_routes_dependencies ) router:route('default', default_routes_dependencies )
router:delegate() router:delegate()

View File

@ -1,3 +1,92 @@
<?lua <?lua
echo("main page") local args = {...}
local data = args[1].data
if not data then return end
for k,v in pairs(data) do
if v.children then
?>
<div class="container" id =<?='"toc'..v.id..'"'?>>
<h1><?=v.name:gsub("^%d+%.","")?></h1>
<?lua
for l,child in pairs(v.children) do
?>
<div class="sub-container">
<h2><?=child.name:gsub("^%d+%.","")?></h2>
<?lua
if child.sections then
for m, entry in pairs(child.sections) do
?>
<div class= "entry">
<p>
<?lua if entry.title ~= "" then ?>
<span class= "fa fa-bookmark"></span>
<span class= "title"><?=entry.title?></span>
<?lua end ?>
<span class= "title-optional"></span>
<span class="location"><?=entry.location?></span>
</p>
<div class="entry-short-des">
<span><?=entry.subtitle?></span>
<span class="date">
<?lua
if entry["start"]:match("^20%d.*") and entry['end']:match("^20%d.*") then
echo(entry.start.."-"..entry['end'])
end
?>
</span>
</div>
<div class="entry-description">
<?=entry.content?>
</div>
</div>
<?lua
end
end
?>
</div>
<?lua
end
?>
</div>
<?lua
else
?>
<div class="container" id =<?='"toc'..v.id..'"'?>>
<h1><?=v.name?></h1>
<?lua
if v.sections then
for m, entry in pairs(v.sections) do
?>
<div class= "entry">
<p>
<?lua if entry.title ~= "" then ?>
<span class= "fa fa-bookmark"></span>
<span class= "title"><?=entry.title?></span>
<?lua end ?>
<span class= "title-optional"></span>
<span class="location"><?=entry.location?></span>
</p>
<div class="entry-short-des">
<span><?=entry.subtitle?></span>
<span class="date">
<?lua
if entry["start"]:match("^20%d.*") and entry['end']:match("^20%d.*") then
echo(entry.start.."-"..entry['end'])
end
?>
</span>
</div>
<div class="entry-description">
<?=entry.content?>
</div>
</div>
<?lua
end
end
?>
</div>
<?lua
end
end
?> ?>

View File

@ -1,9 +1,51 @@
<?lua <?lua
echo("<h1>Default page</h1>")
local args = {...} local args = {...}
local views = args[1] local views = args[1]
if views.__main__ then
views.__main__:render()
end
?> ?>
<html>
<head>
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/gscripts/showdown.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/asset/get/style.css" />
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/asset/get/rst/font-awesome.css" />
<title>Porfolio</title>
</head>
<body>
<div class="layout">
<div class = "cv-content">
<?lua
if views.user then
views.user:render()
end
if views.__main__ then
views.__main__:render()
end
?>
<div class = "container">
<h1 style="margin:0;"></h1>
<p style="text-align:right; padding:0; margin:0;color:#878887;">Powered by antd server, (C) 2017-2018 Xuan Sang LE</p>
</div>
</div>
<?lua
if views.toc then
views.toc:set("data", views.__main__:get("toc"))
views.toc:render()
end
?>
</div>
<script>
window.onload = function()
{
var els = document.getElementsByClassName("entry-description");
var converter = new showdown.Converter();
for(var i in els)
{
var text = els[i].innerHTML;
var html = converter.makeHtml(text);
els[i].innerHTML = html;
}
}
</script>
</body>
</html>

View File

@ -0,0 +1,17 @@
<?lua
if HEADER.mobile then return end
local args = {...}
local data = args[1].data
if not data then return end
?>
<div class = "cv-toc">
<ul>
<?lua
for k, v in pairs(data) do
?>
<li><a href=<?='"#toc'..v[2]..'"'?>><?=v[1]?></a></li>
<?lua
end
?>
</ul>
</div>

View File

@ -0,0 +1,24 @@
<?lua
local args = {...}
local data = args[1].data
?>
<h1>
<span class="name"><?=data.fullname?></span>
<span class="cv">Curriculum Vitae</span>
</h1>
<p class="coordination">
<span class="fa fa-home"></span><?=data.address?></p>
<p class="coordination">
<span class="fa fa-phone"></span>
<span class="text"><?=data.Phone?></span>
<span class="fa fa-envelope-o"></span>
<span class="text"><?=data.email?></span>
<span class="fa fa-globe"></span>
<span class="text"><a href ="<?=data.url?>"><?=data.url?></a></span>
</p>
<p class="shortbio">
<span class="fa fa-quote-left"></span>
<span><?=data.shortbiblio?></span>
<span class="fa fa-quote-right"></span>
</p>

View File

@ -68,7 +68,8 @@ NotfoundController = BaseController:extends{ registry = {}, models = {} }
function NotfoundController:index(...) function NotfoundController:index(...)
local args = {...} local args = {...}
self:error("404: Controller "..args[1].." not found") local error = args[2] or ""
self:error("404: Controller "..args[1].." not found : "..error)
return false return false
end end
@ -86,9 +87,9 @@ function AssetController:get(...)
if POLICY.mimes[mime] then if POLICY.mimes[mime] then
std.header(mime) std.header(mime)
if std.isBinary(path) then if std.isBinary(path) then
std.f(path)
else
std.fb(path) std.fb(path)
else
std.f(path)
end end
end end
return false return false

View File

@ -22,4 +22,5 @@ function BaseObject:error(msg, trace)
else else
error(msg) error(msg)
end end
return false
end end

View File

@ -44,11 +44,11 @@ function Router:infer(url)
local controller_path = self.path.."."..controller_name local controller_path = self.path.."."..controller_name
-- require the controller module -- require the controller module
-- ignore the error -- ignore the error
pcall(require, controller_path) local r,e = pcall(require, controller_path)
--require(controller_path) --require(controller_path)
if not _G[controller_name] then if not _G[controller_name] then
data.controller = NotfoundController:new{ registry = self.registry } data.controller = NotfoundController:new{ registry = self.registry }
data.args = {controller_name} data.args = {controller_name, e}
data.action = "index" data.action = "index"
data.name = "notfound" data.name = "notfound"
else else
@ -113,9 +113,9 @@ function Router:dependencies(url)
end end
function Router:call(data) function Router:call(data)
data.controller.template:setView(data.action, data.name)
local obj = data.controller[data.action](data.controller,table.unpack(data.args)) local obj = data.controller[data.action](data.controller,table.unpack(data.args))
if obj then if obj then
data.controller.template:setView(data.action, data.name)
return data.controller.template return data.controller.template
else else
return false return false

View File

@ -11,21 +11,32 @@ function Template:set(k, v, ow)
end end
end end
function Template:get(k)
return self.vars[k]
end
function Template:remove(k) function Template:remove(k)
self.vars[k] = nil self.vars[k] = nil
end end
-- infer view path -- infer view path
function Template:setView(name, controller) function Template:setView(name, controller)
self.path = VIEW_ROOT..DIR_SEP..self.registry.layout..DIR_SEP..controller..DIR_SEP..name..".ls" self.name = name
if ulib.exists(self.path) then if controller then
self.controller = controller
end
end
function Template:path()
local path = VIEW_ROOT..DIR_SEP..self.registry.layout..DIR_SEP..self.controller..DIR_SEP..self.name..".ls"
if ulib.exists(path) then
return path
else else
self:error("View not found: "..self.path) self:error("View not found: "..path)
end end
end end
-- render the page -- render the page
function Template:render() function Template:render()
local fn, e = loadscript(self.path) local fn, e = loadscript(self:path())
if fn then if fn then
local r,o = pcall(fn, self.vars) local r,o = pcall(fn, self.vars)
if not r then if not r then