1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01:00
This commit is contained in:
Xuan Sang LE 2018-08-28 14:49:03 +02:00
parent 692d437c67
commit 0817dd6079
23 changed files with 1632 additions and 92 deletions

View File

@ -1,10 +1,23 @@
BUILDDIR = ../build/apps
copyfiles = ./*
copyfiles = router.lua controllers logs views models
coffees = assets/coffee/bootstrap.coffee \
assets/coffee/BaseObject.coffee \
assets/coffee/APIManager.coffee \
assets/coffee/MarkOn.coffee \
main:
- mkdir $(BUILDDIR)
main: js
- mkdir -p $(BUILDDIR)/assets
cp -rf $(copyfiles) $(BUILDDIR)
cp -r assets/css assets/scripts $(BUILDDIR)/assets
- cd $(BUILDDIR) && ln -s ../grs ./rst
js:
- rm assets/scripts/main.js
for f in $(coffees); do (cat "$${f}"; echo) >> assets/scripts/main.coffee; done
coffee --compile assets/scripts/main.coffee
- rm assets/scripts/main.coffee
clean:
rm -rf $(BUILDDIR)/*

View File

@ -0,0 +1,22 @@
class APIManager extends window.classes.BaseObject
constructor: () ->
super "APIManager"
init: (cname) ->
console.log(cname)
@ready()
.then () ->
if mobilecheck()
mobileConsole.init()
# load the class
return if not cname or cname is ""
return console.error("Cannot find class ", cname) unless window.classes[cname]
(new window.classes[cname]).init()
.catch ( m, s ) ->
console.error(m, s)
APIManager.dependencies = [
"/assets/scripts/mobile_console.js"
]
makeclass "APIManager", APIManager

View File

@ -0,0 +1,25 @@
class BaseObject
constructor: (@name) ->
ready: () ->
me = @
return new Promise (r, e) ->
me.resolveDep()
.then () -> r()
.catch (m, s) -> e(m, s)
resolveDep: () ->
me = @
return new Promise (r, e) ->
dep = window.classes[me.name].dependencies
r() unless dep
fn = (l, i) ->
return r() if i >= dep.length
require(l[i])
.then () -> fn(l, i + 1)
.catch (m, s) -> e(m, s)
fn dep, 0
makeclass "BaseObject", BaseObject

View File

@ -0,0 +1,17 @@
class MarkOn extends window.classes.BaseObject
constructor: (@id) ->
super "MarkOn"
init: () ->
me = @
@ready()
.then () ->
me.editor = new SimpleMDE { element: $(me.id)[0] }
.catch (m, s) ->
console.error(m, s)
MarkOn.dependencies = [
"/rst/gscripts/mde/simplemde.min.js"
]
makeclass "MarkOn", MarkOn

View File

@ -0,0 +1,19 @@
window.classes = {}
window.libraries = {}
window.myuri = "/"
window.mobilecheck = () ->
if navigator.userAgent.match(/Android/i) or navigator.userAgent.match(/webOS/i) or navigator.userAgent.match(/iPhone/i) or navigator.userAgent.match(/iPad/i) or navigator.userAgent.match(/iPod/i) or navigator.userAgent.match(/BlackBerry/i) or navigator.userAgent.match(/Windows Phone/i)
return true
return false
window.makeclass = (n, o) -> window.classes[n] = o
window.require = (lib) ->
return new Promise (r, e) ->
return r() if window.libraries[lib]
$.getScript window.myuri + lib
.done (d) ->
window.libraries[lib] = true
r()
.fail (m, s) ->
e(m, s)

File diff suppressed because one or more lines are too long

145
apps/assets/scripts/main.js Normal file
View File

@ -0,0 +1,145 @@
// Generated by CoffeeScript 1.9.3
(function() {
var APIManager, BaseObject, MarkOn,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
window.classes = {};
window.libraries = {};
window.myuri = "/";
window.mobilecheck = function() {
if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) {
return true;
}
return false;
};
window.makeclass = function(n, o) {
return window.classes[n] = o;
};
window.require = function(lib) {
return new Promise(function(r, e) {
if (window.libraries[lib]) {
return r();
}
return $.getScript(window.myuri + lib).done(function(d) {
window.libraries[lib] = true;
return r();
}).fail(function(m, s) {
return e(m, s);
});
});
};
BaseObject = (function() {
function BaseObject(name) {
this.name = name;
}
BaseObject.prototype.ready = function() {
var me;
me = this;
return new Promise(function(r, e) {
return me.resolveDep().then(function() {
return r();
})["catch"](function(m, s) {
return e(m, s);
});
});
};
BaseObject.prototype.resolveDep = function() {
var me;
me = this;
return new Promise(function(r, e) {
var dep, fn;
dep = window.classes[me.name].dependencies;
if (!dep) {
r();
}
fn = function(l, i) {
if (i >= dep.length) {
return r();
}
return require(l[i]).then(function() {
return fn(l, i + 1);
})["catch"](function(m, s) {
return e(m, s);
});
};
return fn(dep, 0);
});
};
return BaseObject;
})();
makeclass("BaseObject", BaseObject);
APIManager = (function(superClass) {
extend(APIManager, superClass);
function APIManager() {
APIManager.__super__.constructor.call(this, "APIManager");
}
APIManager.prototype.init = function(cname) {
console.log(cname);
return this.ready().then(function() {
if (mobilecheck()) {
mobileConsole.init();
}
if (!cname || cname === "") {
return;
}
if (!window.classes[cname]) {
return console.error("Cannot find class ", cname);
}
return (new window.classes[cname]).init();
})["catch"](function(m, s) {
return console.error(m, s);
});
};
return APIManager;
})(window.classes.BaseObject);
APIManager.dependencies = ["/assets/scripts/mobile_console.js"];
makeclass("APIManager", APIManager);
MarkOn = (function(superClass) {
extend(MarkOn, superClass);
function MarkOn(id) {
this.id = id;
MarkOn.__super__.constructor.call(this, "MarkOn");
}
MarkOn.prototype.init = function() {
var me;
me = this;
return this.ready().then(function() {
return me.editor = new SimpleMDE({
element: $(me.id)[0]
});
})["catch"](function(m, s) {
return console.error(m, s);
});
};
return MarkOn;
})(window.classes.BaseObject);
MarkOn.dependencies = ["/rst/gscripts/mde/simplemde.min.js"];
makeclass("MarkOn", MarkOn);
}).call(this);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
BaseController:subclass("IndexController", {
registry = {}
})
function IndexController:index( ... )
return true
end
function IndexController:actionnotfound(...)
self.template:setView("index")
return self:index(table.unpack({...}))
end

View File

@ -0,0 +1,13 @@
BaseController:subclass("MarkOnController", {
registry = {}
})
function MarkOnController:index( ... )
self.template:set("jsclass", "MarkOn")
return true
end
function MarkOnController:actionnotfound(...)
self.template:setView("index")
return self:index(table.unpack({...}))
end

View File

@ -1,35 +0,0 @@
BaseController:subclass("PostController", {
registry = {},
models = { "post" }
})
function PostController:index(...)
local args = {...}
self:setSession("postsession", "Huehuehue")
self.template:set("post", self.post:findAll())
return true
end
function PostController:edit(...)
if self:getSession("postsession") then
self.template:set("auth", true)
else
self.template:set("auth", false)
end
self:switchLayout("admin")
return true
end
function PostController:add(...)
local args = {...}
local m = {
cid = tonumber(args[1]),
content = "This is the content for #cid="..args[1]
}
if(self.post:create(m)) then
self.template:set("status", "Post created")
else
self.template:set("status", "Cannot create post")
end
return true
end

View File

@ -1,8 +0,0 @@
BaseModel:subclass("PostModel", {
registry = {},
name = "post",
fields = {
cid = "NUMERIC",
content = "TEXT"
}
})

View File

@ -5,7 +5,7 @@
-- some global variables
DIR_SEP = "/"
WWW_ROOT = "/opt/www/htdocs/apps"
HTTP_ROOT = "https://apps.localhost:9195/"
HTTP_ROOT = "https://10.1.10.84:9195/apps"
-- class path: path.to.class
BASE_FRW = ""
-- class path: path.to.class

View File

View File

@ -1,11 +0,0 @@
<?lua
local args = {...}
echo("Admin pages<br />")
local views = args[1]
for k, v in pairs(views) do
echo(k.." -> ")
v:render()
echo("<br/>")
end
--views.__main__:render()
?>

View File

@ -1,5 +0,0 @@
<?lua
local args = {...}
echo("edit page <br/>")
echo(JSON.encode(args))
?>

View File

@ -0,0 +1 @@
<textarea id = "editor"></textarea>

View File

@ -0,0 +1,3 @@
<h1>
Site under construction
</h1>

View File

@ -1,26 +1,34 @@
<?lua
local args = {...}
local views = args[1]
local main = views.__main__
local jsclass = main:get("jsclass")
if jsclass == nil then jsclass = "" end
?>
<html>
<head>
<title>Application pages</title>
<!--link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/asset/get/grs/ubuntu-regular.css" />
<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" />
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/gscripts/riot.min.js"> </script>
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/resources/antos_tags.js"></script>
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/gscripts/jquery-3.2.1.min.js"> </script>
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/main.js"></script>
<script type="text/javascript" src="<?=HTTP_ROOT?>/asset/get/rst/gscripts/showdown.min.js"></script-->
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/rst/ubuntu-regular.css" />
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/assets/css/style.css" />
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/rst/font-awesome.css" />
<!--script type="text/javascript" src="<?=HTTP_ROOT?>/rst/gscripts/riot.min.js"> </script>
<script type="text/javascript" src="<?=HTTP_ROOT?>/rst/resources/antos_tags.js"></script-->
<script type="text/javascript" src="<?=HTTP_ROOT?>/rst/gscripts/jquery-3.2.1.min.js"> </script>
<script type="text/javascript" src="<?=HTTP_ROOT?>/assets/scripts/main.js"></script>
<!--script type="text/javascript" src="<?=HTTP_ROOT?>/rst/gscripts/showdown.min.js"></script-->
<script>
$(window).on('load', function(){
window.myuri = '<?=HTTP_ROOT?>';
var manager = new window.classes.APIManager();
manager.init('<?=jsclass?>');
});
</script>
</head>
<body>
<div id="desktop">
<?lua
local args = {...}
local views = args[1]
for k, v in pairs(views) do
echo(k.." -> ")
v:render()
echo("<br/>")
end
--views.__main__:render()
main:render()
?>
</div>
</body>

View File

@ -1,5 +0,0 @@
<?lua
local args = {...}
echo("add page : <br/>")
echo(JSON.encode(args))
?>

View File

@ -1,3 +0,0 @@
<?lua
echo("<h1>Public file of edit action</h1><br/>")
?>

View File

@ -1,4 +0,0 @@
<?lua
local args = {...}
echo(JSON.encode(args))
?>

View File

@ -21,7 +21,7 @@ function Router:infer(url)
-- a is controller name
-- b is action
-- c,d,e is parameters
-- if user dont provice the url, try to infer it
-- if user dont provide the url, try to infer it
-- from the REQUEST
url = url or REQUEST.query.r
url = std.trim(url, "/")
@ -84,6 +84,7 @@ function Router:delegate()
data.controller.main = true
views.__main__ = self:call(data)
if not views.__main__ then
--self:error("No main template is set")
return
end
-- get all visible routes