add database support

This commit is contained in:
Xuan Sang LE 2018-02-05 19:05:41 +01:00
parent 37c10daaad
commit 107e85e612
11 changed files with 165 additions and 8 deletions

View File

@ -8,6 +8,7 @@ coffees= src/core/core.coffee\
src/core/api.coffee\
src/core/handlers/RemoteHandler.coffee\
src/core/vfs.coffee\
src/core/db.coffee\
src/core/gui.coffee\
src/core/BaseModel.coffee\
src/core/BaseApplication.coffee\
@ -20,7 +21,7 @@ coffees= src/core/core.coffee\
packages = CoreServices NotePad wTerm ActivityMonitor DummyApp Files MarkOn MarketPlace
packages = CoreServices NotePad wTerm ActivityMonitor DummyApp Files MarkOn MarketPlace Blogger
main: build_coffees build_tags build_themes schemes libs build_packages
- cp src/index.html $(BUILDDIR)/

View File

@ -69,4 +69,5 @@ class BaseModel
find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme
select: (sel) -> $ sel, @scheme if @scheme
this.OS.GUI.BaseModel = BaseModel

13
src/core/db.coffee Normal file
View File

@ -0,0 +1,13 @@
class DB
constructor: (@table) ->
save: (d, f) ->
_API.handler.dbquery "save", { table: @table, data: d }, f
delete: (id, f) ->
_API.handler.dbquery "delete", { table: @table, id: id }, f
get: (id, f) ->
_API.handler.dbquery "get", { table: @table, id: id }, f
find: (cond, f) ->
_API.handler.dbquery "select", { table: @table, cond: cond }, f
self.OS.API.DB = DB

View File

@ -76,3 +76,8 @@ self.OS.API.handler =
_courrier.oserror "Cannot save system setting", d.error if d.error
, (e, s) ->
_courrier.osfail "Fail to make request: #{p}", e, s
dbquery: (cmd,d, c) ->
path = "#{_REST}/db/#{cmd}"
_API.post path, d, c, (e, s) ->
_courrier.osfail "Fail to query data from database: #{p}", e, s

View File

@ -1,5 +1,5 @@
<afx-hbox style = "display:block;">
<div ref = "container" class="afx-vbox-container">
<div ref = "container" class="afx-hbox-container">
<yield/>
</div>
<script>
@ -35,8 +35,6 @@
.each(function(e)
{
this.observable = self.root.observable
$(this)
.css("flex-grow","1")
//.css("height",avaiheight + "px")
var dw = $(this).attr("data-width")
if(dw)
@ -47,6 +45,8 @@
}
else
{
$(this)
.css("flex-grow","1")
auto_width.push(this)
}
})

View File

@ -1,5 +1,5 @@
<afx-vbox style = "display:block;">
<div ref = "container" class="afx-hbox-container">
<div ref = "container" class="afx-vbox-container">
<yield/>
</div>
<script>
@ -38,8 +38,6 @@
.each(function(e)
{
this.observable = self.root.observable
$(this)
.css("flex-grow","1")
//.css("border","1px solid black")
var dw = $(this).attr("data-height")
if(dw)
@ -50,6 +48,8 @@
}
else
{
$(this)
.css("flex-grow","1")
auto_height.push(this)
}
})

View File

@ -0,0 +1,11 @@
coffee_files = main.coffee
jsfiles =
cssfiles = main.css
copyfiles = scheme.html package.json
PKG_NAME=Blogger
include ../pkg.mk

View File

@ -0,0 +1,39 @@
class Blogger extends this.OS.GUI.BaseApplication
constructor: (args) ->
super "Blogger", args
main: () ->
me = @
@tabbar = @find "tabbar"
@containers = [
@find("user-container"),
@find("cv-container"),
@find("blog-container")
]
@cvlist = @find "cv-list"
@bloglist = @find "blog-list"
@tabbar.set "onlistselect", (e) ->
($ el).hide() for el in me.containers
($ me.containers[e.idx]).show()
@tabbar.set "items", [
{ iconclass: "fa fa-user-circle", selected: true },
{ iconclass: "fa fa-info-circle" },
{ iconclass: "fa fa-book" }
]
(@find "bt-user-save").set "onbtclick", (e) ->
me.saveUser()
saveUser:() ->
me = @
inputs = @select "[imput-class='user-input']"
data = {}
data[v.name] = ($ v).val() for v in inputs
return @notify "Full name must be entered" if not data.fullname or data.fullname is ""
db = new @_api.DB("user")
db.save data, (r) ->
return me.error "Cannot save user data" if r.error
return me.notify "User data updated"
Blogger.singleton = true
this.OS.register "Blogger", Blogger

View File

@ -0,0 +1,25 @@
afx-app-window[data-id="blogger-win"] afx-list-view[data-id="tabbar"] {
padding: 0;
margin: 0;
background-color: #333333;
}
afx-app-window[data-id="blogger-win"] afx-list-view[data-id="tabbar"] li {
background-color: #333333;
font-size: 20px;
color: #929292;
}
afx-app-window[data-id="blogger-win"] afx-list-view[data-id="tabbar"] li.selected{
color:white;
}
afx-app-window[data-id="blogger-win"] afx-hbox[data-id="user-container"] {
padding: 10px;
}
afx-app-window[data-id="blogger-win"] afx-hbox[data-id="user-container"] afx-hbox{
margin-bottom: 5px;
margin-top: 5px;
}
afx-app-window[data-id="blogger-win"] afx-hbox[data-id="user-container"] afx-label{
font-weight: bold;
}

View File

@ -0,0 +1,13 @@
{
"app":"Blogger",
"name":"Blogging application",
"description":"Backend manager for blogging",
"info":{
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"category":"Internet",
"iconclass":"fa fa-book",
"mimes":["none"]
}

View File

@ -0,0 +1,49 @@
<afx-app-window data-id = "blogger-win" apptitle="MarketPlace" width="500" height="400">
<afx-hbox >
<afx-list-view data-id="tabbar" data-width="30"></afx-list-view>
<afx-vbox>
<afx-hbox data-id="user-container" data-height="grow">
<afx-vbox>
<afx-hbox data-height = "30">
<afx-label data-width= "70" text = "Full name:"></afx-label>
<input type = "text" name="fullname" imput-class = "user-input"/>
</afx-hbox>
<afx-hbox data-height = "30">
<afx-label text = "Address:" data-width= "70"></afx-label>
<input type = "text" name="address" imput-class = "user-input"/>
</afx-hbox>
<afx-hbox data-height = "30">
<afx-label text = "Phone:" data-width= "70"></afx-label>
<input type = "text" name="Phone" imput-class = "user-input"/>
</afx-hbox>
<afx-hbox data-height = "30">
<afx-label text = "Email:" data-width= "70"></afx-label>
<input type = "text" name="email" imput-class = "user-input"/>
</afx-hbox>
<afx-hbox data-height = "30">
<afx-label text = "Url:" data-width= "70"></afx-label>
<input type = "text" name="url" imput-class = "user-input"/>
</afx-hbox>
<afx-label data-height = "30" text = "Short biblio:"/>
<textarea rows="10" name="shortbiblio" imput-class = "user-input"/>
<afx-hbox data-height = "30">
<div></div>
<afx-button iconclass = "fa fa-save" data-id = "bt-user-save" data-width="55" text = "Save"/>
</afx-hbox>
</afx-vbox>
</afx-hbox>
<afx-hbox data-id="cv-container" data-height="grow">
<afx-list-view data-id = "cv-list" data-width="100" ></afx-list-view>
<afx-vbox>
info here
</afx-vbox>
</afx-hbox>
<afx-hbox data-id = "blog-container" data-height="grow">
<afx-list-view data-id = "blog-list" data-width="100"></afx-list-view>
<afx-vbox>
blog here
</afx-vbox>
</afx-hbox>
</afx-vbox>
</afx-hbox>
</afx-app-window>