add shared library support

This commit is contained in:
Xuan Sang LE 2018-02-16 18:38:14 +01:00
parent dad5993c20
commit 13c6a1e9ff
23 changed files with 309 additions and 61 deletions

3
TODO
View File

@ -1,2 +1 @@
VFS mountpoints object (selected) is changed between apps, which is not a good ideal
Some error in event handle using observable
add require function that allows load shared library between application

View File

@ -17,7 +17,7 @@ class SubWindow extends this.OS.GUI.BaseModel
@parent.meta()
show: () ->
@trigger 'focus'
($ @scheme).css "z-index", window._zindex+2
($ @scheme).css "z-index", window._zindex + 2
hide: () ->
@trigger 'hide'
@ -182,7 +182,7 @@ this.OS.register "InfoDialog", InfoDialog
class YesNoDialog extends BasicDialog
constructor: () ->
super "YesNoDialog", {
tags: [{ tag: "afx-label", att: "style = 'padding:10px;'" }],
tags: [{ tag: "afx-label", att: "style = 'padding-left:10px;'" }],
width: 300,
height: 100,
resizable: true,

View File

@ -20,6 +20,11 @@ class BaseModel
@dialog.quit() if @dialog
_PM.kill @
path: () ->
mt = @meta()
return mt.path if mt and mt.path
return null
init: ->
#implement by sub class
onexit: (e) ->

View File

@ -3,6 +3,7 @@ self.OS.API =
# fetch user data, used by the API to make requests
# handlers are defined in /src/handlers
handler: { }
shared: {} # shared libraries
#request a user data
post: (p, d, c, f) ->
q = _courrier.getMID()
@ -115,6 +116,33 @@ self.OS.API =
path = "resources/#{r}"
_API.get path, c, f
require: (l,f) ->
path = "os:///scripts/"
if not _API.shared[l]
js = "#{path}#{l}.js"
js.asFileHandler().onready (d) ->
_API.shared[l] = true
el = $ '<script>', { src: "#{_API.handler.get}/#{js}" }
.appendTo 'head'
#load css file
css = "#{path}#{l}.css"
css.asFileHandler().onready (d) ->
el = $ '<link>', { rel: 'stylesheet', type: 'text/css', 'href': "#{_API.handler.get}/#{css}" }
.appendTo 'head'
, () ->
console.log "loaded", l
_courrier.trigger "sharedlibraryloaded", l
f() if f
else
console.log l, "Library exist, no need to load"
_courrier.trigger "sharedlibraryloaded", l
requires:(libs, f) ->
return f() unless libs.length > 0
_courrier.observable.one "sharedlibraryloaded", (l) ->
libs.splice 0, 1
_API.requires libs, f
_API.require libs[0], null
packages:
fetch: (f) ->
_API.handler.packages {

View File

@ -44,21 +44,27 @@ self.OS or=
pidalloc: 0
processes: {}
createProcess: (app, cls, args) ->
#if it is single ton
# and a process is existing
# just return it
if cls.singleton and _PM.processes[app] and _PM.processes[app].length == 1
_PM.processes[app][0].show()
f = () ->
#if it is single ton
# and a process is existing
# just return it
if cls.singleton and _PM.processes[app] and _PM.processes[app].length == 1
_PM.processes[app][0].show()
else
_PM.processes[app] = [] if not _PM.processes[app]
obj = new cls(args)
obj.birth = (new Date).getTime()
_PM.pidalloc++
obj.pid = _PM.pidalloc
_PM.processes[app].push obj
if cls.type is 1 then _GUI.dock obj, cls.meta else _GUI.attachservice obj
if cls.type is 2
_courrier.trigger "srvroutineready", app
if cls.dependencies
libs = (v for v in cls.dependencies)
_API.requires libs, f
else
_PM.processes[app] = [] if not _PM.processes[app]
obj = new cls(args)
obj.birth = (new Date).getTime()
_PM.pidalloc++
obj.pid = _PM.pidalloc
_PM.processes[app].push obj
if cls.type is 1 then _GUI.dock obj, cls.meta else _GUI.attachservice obj
if cls.type is 2
_courrier.trigger "srvroutineready", app
f()
appByPid: (pid) ->
app = undefined
find = (l) ->

View File

@ -5,8 +5,8 @@ class DB
_API.handler.dbquery "save", { table: @table, data: d }, f
delete: (c, f) ->
rq = { table: @table }
return _courrier.oserror "Unknown condition for delete command",
(_API.throwe "OS.DB"), c unless c and c inst ""
return ( _courrier.oserror "Unknown condition for delete command",
(_API.throwe "OS.DB"), c ) unless c and c isnt ""
if isNaN c
rq.cond = c
else

View File

@ -26,12 +26,12 @@ self.OS.GUI =
.attr "href", path
pushServices: (srvs) ->
f = (v) ->
_courrier.observable.one "srvroutineready", () -> _GUI.pushService v
return unless srvs.length > 0
_courrier.observable.one "srvroutineready", () ->
srvs.splice 0, 1
_GUI.pushServices srvs
_GUI.pushService srvs[0]
srvs.splice 0, 1
f i for i in srvs
openDialog: (d, f, title, data) ->
if _GUI.dialog
_GUI.dialog.show()

View File

@ -1,5 +1,5 @@
self.OS.API.HOST = self.location.hostname+ (if self.location.port then":#{self.location.port}" else "")
self.OS.API.REST = "https://#{self.OS.API.HOST}/lua-api"
self.OS.API.REST = "#{self.location.protocol}//#{self.OS.API.HOST}/lua-api"
_REST = self.OS.API.REST
self.OS.API.handler =

View File

@ -7,7 +7,7 @@
<afx-label color = {item.color} iconclass = {item.iconclass} icon = {item.icon} text = {item.text}></afx-label>
<i if = {item.closable} class = "closable" click = {parent._remove}></i>
<ul if = {item.complex} class = "complex-content">
<li each = {ctn,j in item.content} class = {ctn.class}>{ctn.text}</li>
<li each = {ctn,j in item.detail} class = {ctn.class}>{ctn.text}</li>
</ul>
</li>
</ul>

View File

@ -70,7 +70,7 @@ class BaseFileHandler
me = @
me.meta (d) ->
if d.error
return if err then err d else _courrier.osfail d.error, (_API.throwe "OS.VFS"), d.error
return if err then err d else _courrier.osfail "#{me.path}: #{d.error}", (_API.throwe "OS.VFS"), d.error
me.info = d.result
me.ready = true
f()
@ -164,7 +164,7 @@ class RemoteFileHandler extends self.OS.API.VFS.BaseFileHandler
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^(home|shared|desktop|os)$", RemoteFileHandler
self.OS.API.VFS.register "^(home|shared|desktop|os|Untitled)$", RemoteFileHandler
# Application Handler
class ApplicationHandler extends self.OS.API.VFS.BaseFileHandler
@ -206,4 +206,53 @@ class ApplicationHandler extends self.OS.API.VFS.BaseFileHandler
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^app$", ApplicationHandler
self.OS.API.VFS.register "^app$", ApplicationHandler
class BlobFileHandler extends self.OS.API.VFS.BaseFileHandler
constructor: (path, mime, data) ->
super path
@cache = data if data
@info =
mime: mime
path: path
size: if data then data.length else 0
name: @basename
type: "file"
meta: (f) ->
f()
onchange: (f) ->
@onchange = f
action: (n, p, f) ->
me = @
switch n
when "read"
return f { result: @cache }
when "mk"
return
when "write"
@cache = p
@onchange @ if @onchange
f { result: true }
when "upload"
# install
return
when "remove"
#uninstall
return
when "download"
blob = new Blob [@cache], { type: "octet/stream" }
_API.saveblob me.basename, blob
when "move"
return
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^blob$", BlobFileHandler

View File

@ -9,10 +9,6 @@
<script src="scripts/jquery-3.2.1.min.js"></script>
<script src="resources/antos_tags.js" type="riot/tag"></script>
<script src="scripts/riot.compiler.min.js"> </script>
<script src="scripts/ace/ace.js"></script>
<script src="scripts/ace/ext-language_tools.js"></script>
<script src="scripts/ace/ext-modelist.js"></script>
<script src="scripts/ace/ext-themelist.js"></script>
<script src="scripts/antos.js"></script>
</head>
<body>

View File

@ -4,7 +4,7 @@ jsfiles =
cssfiles = main.css
copyfiles = scheme.html package.json
copyfiles = scheme.html cvsection.html package.json
PKG_NAME=Blogger

View File

@ -0,0 +1,28 @@
<afx-app-window data-id = "blogger-cv-sec-win" apptitle="Porforlio section" width="450" height="400">
<afx-vbox >
<afx-hbox data-height = "30" >
<afx-label data-width= "70" text = "Title*:"></afx-label>
<input type = "text" name="title" input-class = "user-input"/>
</afx-hbox>
<afx-hbox data-height = "30" >
<afx-label text = "Subtitle:" data-width= "70"></afx-label>
<input type = "text" name="subtitle" input-class = "user-input"/>
</afx-hbox>
<afx-hbox data-height = "30" >
<afx-label text = "Location:" data-width= "70"></afx-label>
<input type = "text" name="location" input-class = "user-input"/>
</afx-hbox>
<afx-hbox data-height = "30" >
<afx-label text = "From:" data-width= "70"></afx-label>
<input type = "text" name="start" input-class = "user-input"/>
<afx-label text = "To:" style="text-align:center;" data-width= "70"></afx-label>
<input type = "text" name="end" input-class = "user-input"/>
</afx-hbox>
<afx-label data-height = "30" text = "Content*:" style = "margin-left:5px;"/>
<textarea name="content" input-class = "user-input" style = "margin-left:5px; margin-right:5px;" />
<afx-hbox data-height = "30">
<div></div>
<afx-button iconclass = "fa fa-save" data-id = "bt-cv-sec-save" data-width="55" text = "Save"/>
</afx-hbox>
</afx-vbox>
</afx-app-window>

View File

@ -44,4 +44,30 @@ class BloggerCategoryDialog extends this.OS.GUI.BasicDialog
}
this.OS.register "BloggerCategoryDialog", BloggerCategoryDialog
this.OS.register "BloggerCategoryDialog", BloggerCategoryDialog
# This dialog is use for cv section editing
class BloggerCVSectionDiaglog extends this.OS.GUI.BaseDialog
constructor: () ->
super "BloggerCVSectionDiaglog"
init: () ->
@render "#{@path()}/cvsection.html"
main: () ->
me = @
@scheme.set "apptitle", @title
inputs = me.select "[input-class='user-input']"
(($ v).val me.data[v.name] for v in inputs ) if me.data
(@find "bt-cv-sec-save").set "onbtclick", (e) ->
data = {}
console.log inputs
data[v.name] = ($ v).val() for v in inputs
return me.notify "Title must not be blank" if data.title is ""
return me.notify "Content must not be blank" if data.content is ""
data.id = me.data.id if me.data and me.data.id
me.handler data if me.handler
me.quit()
this.OS.register "BloggerCVSectionDiaglog", BloggerCVSectionDiaglog

View File

@ -13,10 +13,11 @@ class Blogger extends this.OS.GUI.BaseApplication
@user = {}
@cvlist = @find "cv-list"
@cvlist.set "ontreeselect", (d) ->
#console.log d
me.CVSectionByCID Number(d.id)
@bloglist = @find "blog-list"
@userdb = new @_api.DB("user")
@cvcatdb = new @_api.DB("cv_cat")
@cvsecdb = new @_api.DB("cv_sections")
@tabbar.set "onlistselect", (e) ->
($ el).hide() for el in me.containers
me.fetchData e.idx
@ -56,7 +57,7 @@ class Blogger extends this.OS.GUI.BaseApplication
name: d.value
me.cvcatdb.save c, (r) ->
me.error "Cannot Edit category" if r.error
return me.error "Cannot Edit category" if r.error
me.refreshCVCat()
, "Edit category", { tree: (me.cvlist.get "data"), cat: cat }
@ -69,6 +70,35 @@ class Blogger extends this.OS.GUI.BaseApplication
console.log "delete all child + theirs content"
, "Delete cagegory" ,
{ iconclass: "fa fa-question-circle", text: "Do you really want to delete: #{cat.name} ?" }
(@find "cv-sec-add").set "onbtclick", (e) ->
cat = me.cvlist.get "selectedItem"
return me.notify "Please select a category" unless cat and cat.id isnt 0
me.openDialog "BloggerCVSectionDiaglog", (d) ->
d.cid = Number cat.id
d.start = Number d.start
d.end = Number d.end
me.cvsecdb.save d, (r) ->
return me.error "Cannot save section: #{r.error}" if r.error
me.CVSectionByCID Number(cat.id)
, "New section entry for #{cat.name}", null
(@find "cv-sec-edit").set "onbtclick", (e) ->
sec = (me.find "cv-sec-list").get "selected"
return me.notify "Please select a section to edit" unless sec
me.openDialog "BloggerCVSectionDiaglog", (d) ->
d.cid = Number sec.cid
d.start = Number d.start
d.end = Number d.end
me.cvsecdb.save d, (r) ->
return me.error "Cannot save section: #{r.error}" if r.error
console.log d.cid
me.CVSectionByCID Number(sec.cid)
, "Modify section entry", sec
# USER TAB
fetchData: (idx) ->
me = @
switch idx
@ -77,13 +107,25 @@ class Blogger extends this.OS.GUI.BaseApplication
@userdb.get null, (d) ->
return me.error "Cannot fetch user data" if d.error
me.user = d.result[0]
inputs = me.select "[imput-class='user-input']"
inputs = me.select "[input-class='user-input']"
($ v).val me.user[v.name] for v in inputs
when 1 # category
@refreshCVCat()
else
console.log "Not implemented yet"
saveUser:() ->
me = @
inputs = @select "[input-class='user-input']"
@user[v.name] = ($ v).val() for v in inputs
return @notify "Full name must be entered" if not @user.fullname or @user.fullname is ""
#console.log @user
@userdb.save @user, (r) ->
return me.error "Cannot save user data" if r.error
return me.notify "User data updated"
# PORFOLIO TAB
refreshCVCat: () ->
me = @
data =
@ -91,11 +133,13 @@ class Blogger extends this.OS.GUI.BaseApplication
id:0,
nodes: []
@cvcatdb.get null, (d) ->
return me.notify "Cannot fetch CV categories" if d.error
if d.error
me.cvlist.set "data", data
return me.notify "Cannot fetch CV categories"
me.fetchCVCat d.result, data, "0"
me.cvlist.set "data", data
it = (me.cvlist.find "pid", "2")[0]
me.cvlist.set "selectedItem", it
#it = (me.cvlist.find "pid", "2")[0]
#me.cvlist.set "selectedItem", it
fetchCVCat: (table, data, id) ->
result = (v for v in table when v.pid is id)
@ -105,17 +149,39 @@ class Blogger extends this.OS.GUI.BaseApplication
@fetchCVCat table, v, v.id
#v.nodes = null if v.nodes.length is 0
data.nodes.push v
saveUser:() ->
CVSectionByCID: (cid) ->
me = @
inputs = @select "[imput-class='user-input']"
@user[v.name] = ($ v).val() for v in inputs
return @notify "Full name must be entered" if not @user.fullname or @user.fullname is ""
#console.log @user
@userdb.save @user, (r) ->
return me.error "Cannot save user data" if r.error
return me.notify "User data updated"
@cvsecdb.find "cid=#{cid} ORDER BY start DESC", (d) ->
return me.notify "Section list is empty, please add one" if d.error
v.text = v.title for v in d.result
items = []
$(me.find "cv-sec-status").html "Found #{d.result.length} sections"
for v in d.result
v.text = v.title
v.complex = true
v.start = Number(v.start)
v.end = Number(v.end)
v.detail = []
v.detail.push { text: v.subtitle, class: "cv-subtitle" } if v.subtitle isnt ""
v.detail.push { text: "#{v.start} - #{v.end}", class: "cv-period" } if v.start isnt 0 and v.end isnt 0
v.detail.push { text: v.location, class: "cv-loc" } if v.location isnt ""
#v.detail.push { text: v.end } if v.end isnt 0
v.closable = true
v.detail.push { text: v.content, class: "cv-content" }
items.push v
el = me.find "cv-sec-list"
el.set "onitemclose", (e) ->
d = me.openDialog "YesNoDialog", (b) ->
return unless b
me.cvsecdb.delete e.item.item.id, (r) ->
return me.error "Cannot delete the section: #{r.error}" if r.error
el.remove e.item.item, true
, "Delete section" ,
{ iconclass: "fa fa-question-circle", text: "Do you really want to delete: #{e.item.item.text} ?" }
return false
el.set "items", items
Blogger.singleton = true
Blogger.dependencies = [ "mde/simplemde.min" ]
this.OS.register "Blogger", Blogger

View File

@ -40,3 +40,35 @@ afx-app-window[data-id="blogger-win"] afx-hbox[data-id="cv-container"] afx-labe
text-align: center;
}
afx-app-window[data-id="blogger-cv-sec-win"] afx-hbox{
padding:5px;
}
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] > div.list-container > ul > li{
padding-bottom: 10px;
padding-top:10px;
/*border-bottom: 1px solid #cbcbcb;*/
}
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] > div.list-container > ul afx-label{
font-weight: bold;
}
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] > div.list-container > ul > li.selected {
border: 2px solid #cbcbcb;
color: #414339;
background-color: transparent;
border-radius: 5px;
}
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .cv-content{
text-align: justify;
}
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .cv-period, .cv-loc{
text-align: right;
}
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] .cv-subtitle{
font-style: italic;
float:left;
}
afx-app-window[data-id="blogger-win"] afx-list-view[ data-id = "cv-sec-list"] i.closable::before{
content: "\f014";
font-size: 15px;
}

View File

@ -6,26 +6,26 @@
<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"/>
<input type = "text" name="fullname" input-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"/>
<input type = "text" name="address" input-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"/>
<input type = "text" name="Phone" input-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"/>
<input type = "text" name="email" input-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"/>
<input type = "text" name="url" input-class = "user-input"/>
</afx-hbox>
<afx-label data-height = "30" text = "Short biblio:"/>
<textarea name="shortbiblio" imput-class = "user-input"/>
<textarea name="shortbiblio" input-class = "user-input"/>
<afx-hbox data-height = "35">
<div></div>
<afx-button iconclass = "fa fa-save" data-id = "bt-user-save" data-width="55" text = "Save"/>
@ -44,7 +44,12 @@
</afx-vbox>
<afx-resizer data-width = "3"/>
<afx-vbox>
info here
<afx-list-view data-id = "cv-sec-list" ></afx-list-view>
<afx-hbox data-height="30" class = "cv-side-bar-btn">
<div data-id = "cv-sec-status"></div>
<afx-button data-id = "cv-sec-add" data-width = "25" text = "" iconclass = "fa fa-plus-circle"></afx-button>
<afx-button data-id = "cv-sec-edit" data-width = "25" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
</afx-hbox>
</afx-vbox>
</afx-hbox>
<afx-hbox data-id = "blog-container" data-height="100%">

View File

@ -58,7 +58,7 @@ class DummyApp extends this.OS.GUI.BaseApplication
{text:"some thing"},
{text:"some thing"},
{text:"some thing"},
{text:"some thing", complex:true, content:[{text:"Inner content", class:""}]},
{text:"some thing", complex:true, detail:[{text:"Inner content", class:""}]},
{text:"some thing"},
{text:"some thing"},
{text:"some thing"},

View File

@ -1,8 +1,8 @@
coffee_files = main.coffee
jsfiles = simplemde.min.js
jsfiles =
cssfiles = simplemde.min.css main.css
cssfiles = main.css
copyfiles = scheme.html package.json

View File

@ -118,4 +118,6 @@ class MarkOn extends this.OS.GUI.BaseApplication
me.quit()
, "Quit", { text: "Quit without saving ?" }
MarkOn.dependencies = [ "mde/simplemde.min" ]
this.OS.register "MarkOn", MarkOn

View File

@ -279,4 +279,10 @@ class NotePad extends this.OS.GUI.BaseApplication
, "Quit", { text: "Ignore all #{dirties.length} unsaved files ?" }
NotePad.singleton = false
NotePad.dependencies = [
"ace/ace",
"ace/ext-language_tools",
"ace/ext-modelist",
"ace/ext-themelist"
]
this.OS.register "NotePad", NotePad