vfs (contd.)

This commit is contained in:
Xuan Sang LE 2018-01-25 19:15:41 +01:00
parent d70cef3e95
commit 15f1fb45eb
8 changed files with 212 additions and 21 deletions

View File

@ -40,11 +40,12 @@ this.OS.GUI.BaseDialog = BaseDialog
} }
### ###
class BasicDialog extends BaseDialog class BasicDialog extends BaseDialog
constructor: ( name, @conf ) -> constructor: ( name, @conf, @title) ->
super name super name
init: () -> init: () ->
html = "<afx-app-window data-id = 'dia-window' apptitle='#{@name}' width='#{@conf.width}' height='#{@conf.height}'> @title = @name if not @title
html = "<afx-app-window data-id = 'dia-window' apptitle='#{@title}' width='#{@conf.width}' height='#{@conf.height}'>
<afx-hbox>" <afx-hbox>"
html += "<#{@conf.tag} #{@conf.att} data-id = 'content'></#{@conf.tag}>" html += "<#{@conf.tag} #{@conf.att} data-id = 'content'></#{@conf.tag}>"
html += "<div data-height = '40' style=' text-align:right;padding-top:3px;'>" html += "<div data-height = '40' style=' text-align:right;padding-top:3px;'>"
@ -70,6 +71,7 @@ class PromptDialog extends BasicDialog
tag: "input", tag: "input",
width: 200, width: 200,
height: 90, height: 90,
att: "type = 'text'"
resizable: false, resizable: false,
buttons: [ buttons: [
{ {
@ -86,7 +88,8 @@ class PromptDialog extends BasicDialog
} }
], ],
filldata: (d) -> filldata: (d) ->
d.scheme.set "apptitle", d.data if d.data return unless d.data
(d.find "content").value = d.data
} }
this.OS.register "PromptDialog", PromptDialog this.OS.register "PromptDialog", PromptDialog
@ -156,10 +159,38 @@ class InfoDialog extends BasicDialog
rows = [] rows = []
rows.push [ { value: k }, { value: v } ] for k, v of d.data rows.push [ { value: k }, { value: v } ] for k, v of d.data
(d.find "content").set "rows", rows (d.find "content").set "rows", rows
d.scheme.set "apptitle", d.data.filename
} }
this.OS.register "InfoDialog", InfoDialog this.OS.register "InfoDialog", InfoDialog
class YesNoDialog extends BasicDialog
constructor: () ->
super "YesNoDialog", {
tag: "afx-label",
width: 300,
height: 100,
att:"style = 'padding:10px;'"
resizable: true,
buttons: [
{
label: "Yes", onclick: (d) ->
d.handler true if d.handler
d.quit()
},
{
label: "No", onclick: (d) ->
d handler false if dhandler
d.quit()
}
],
filldata: (d) ->
return unless d.data
l = d.find "content"
for k, v of d.data
l.set k, v
}
this.OS.register "YesNoDialog", YesNoDialog
class AboutDialog extends BaseDialog class AboutDialog extends BaseDialog
constructor: () -> constructor: () ->
super "AboutDialog" super "AboutDialog"

View File

@ -31,7 +31,7 @@ class BaseModel
subscribe: (e, f) -> subscribe: (e, f) ->
_courrier.on e, f, @ _courrier.on e, f, @
openDialog: (d, f, data) -> openDialog: (d, f, title, data) ->
if @dialog if @dialog
@dialog.show() @dialog.show()
return return
@ -43,6 +43,7 @@ class BaseModel
@dialog.handler = f @dialog.handler = f
@dialog.pid = @pid @dialog.pid = @pid
@dialog.data = data @dialog.data = data
@dialog.title = title
@dialog.init() @dialog.init()
publish: (t, m) -> publish: (t, m) ->

View File

@ -23,6 +23,61 @@ self.OS.API =
.fail (e, s) -> .fail (e, s) ->
_API.loaded q, p, "FAIL" _API.loaded q, p, "FAIL"
f(e, s) f(e, s)
blob: (p, c, f) ->
q = _courrier.getMID()
r = new XMLHttpRequest()
r.open "GET", p, true
r.responseType = "arraybuffer"
r.onload = (e) ->
if @status is 200 and @readyState is 4
c @response
_API.loaded q, p, "OK"
else
f e, @
_API.loaded q, p, "FAIL"
_API.loading q, p
r.send()
upload: (p, d, c, f) ->
q = _courrier.getMID()
#insert a temporal file selector
o = ($ '<input>').attr('type', 'file').css("display", "none")
o.change () ->
_API.loading q, p
formd = new FormData()
formd.append 'path', d
# TODO: only one file is selected at this time
formd.append 'upload', o[0].files[0]
$.ajax {
url: p,
data: formd,
type: 'POST',
contentType: false,
processData: false,
}
.done (data) ->
_API.loaded q, p, "OK"
c(data)
.fail (e, s) ->
_API.loaded q, p, "FAIL"
f(e, s)
o.click()
saveblob: (name, b) ->
url = window.URL.createObjectURL b
o = ($ '<a>')
.attr("href", url)
.attr("download", name)
.css("display", "none")
.appendTo("body")
o[0].click()
window.URL.revokeObjectURL(url)
o.remove()
systemConfig: -> systemConfig: ->
_API.request 'config', (result) -> _API.request 'config', (result) ->
@ -54,7 +109,7 @@ self.OS.API =
resource: (r, c, f) -> resource: (r, c, f) ->
path = "resources/#{r}" path = "resources/#{r}"
_API.get path, c, f _API.get path, c, f
throwe: (n) -> throwe: (n) ->
err = undefined err = undefined
try try

View File

@ -156,7 +156,6 @@ self.OS.GUI =
username: ($ "#txtuser").val(), username: ($ "#txtuser").val(),
password: ($ "#txtpass").val() password: ($ "#txtpass").val()
_API.handler.login data, (d) -> _API.handler.login data, (d) ->
console.log d
if d.error then ($ "#login_error").html d.error else _GUI.startAntOS d.result if d.error then ($ "#login_error").html d.error else _GUI.startAntOS d.result
, (e, s) -> , (e, s) ->
alert "System fall: Cannot init login screen" alert "System fall: Cannot init login screen"

View File

@ -16,7 +16,27 @@ self.OS.API.handler =
readfile: (p, c) -> readfile: (p, c) ->
path = "lua-api/fs/get/" path = "lua-api/fs/get/"
_API.get path + p, c, (e, s) -> _API.get path + p, c, (e, s) ->
_courrier.osfail "Fail to read file: #{p}",e , s _courrier.osfail "Fail to read file: #{p}", e, s
move: (s, d, c) ->
path = "lua-api/fs/move"
_API.post path, { src: s, dest: d }, c, (e, s) ->
_courrier.osfail "Fail to move file: #{s} -> #{d}", e, s
delete: (p , c) ->
path = "lua-api/fs/delete"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to delete: #{p}", e, s
fileblob: (p, c) ->
path = "lua-api/fs/get/"
_API.blob path + p, c, (e, s) ->
_courrier.osfail "Fail to read file: #{p}", e, s
upload: (d, c) ->
path = "lua-api/fs/upload"
_API.upload path, d, c, (e, s) ->
_courrier.osfail "Fail to upload file to: #{d}", e, s
write: (p, d , c) -> write: (p, d , c) ->
path = "lua-api/fs/write" path = "lua-api/fs/write"

View File

@ -64,9 +64,17 @@ class BasicFileHandler
me = @ me = @
@onready (() -> me.action "remove", null, f) @onready (() -> me.action "remove", null, f)
upload: (f) ->
me = @
@onready (() -> me.action "upload", null, f)
download: (f) ->
me = @
@onready (() -> me.action "download", null, f)
move: (d, f) -> move: (d, f) ->
me = @ me = @
@onready (() -> me action "move", d, f) @onready (() -> me.action "move", d, f)
execute: (f) -> execute: (f) ->
me = @ me = @
@ -93,6 +101,7 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
_API.handler.fileinfo @path, f _API.handler.fileinfo @path, f
action: (n, p, f) -> action: (n, p, f) ->
me = @
switch n switch n
when "read" when "read"
return _API.handler.scandir @path, f if @meta.type is "dir" return _API.handler.scandir @path, f if @meta.type is "dir"
@ -103,6 +112,18 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
_API.handler.mkdir "#{@path}/#{p}", f _API.handler.mkdir "#{@path}/#{p}", f
when "write" when "write"
_API.handler.write @path, p, f _API.handler.write @path, p, f
when "upload"
return if @meta.type is "file"
_API.handler.upload @path, f
when "remove"
_API.handler.delete @path, f
when "download"
return if @meta.type is "dir"
_API.handler.fileblob @path, (d) ->
blob = new Blob [d], { type: "octet/stream" }
_API.saveblob me.basename, blob
when "move"
_API.handler.move @path, p, f
else else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n

View File

@ -55,7 +55,7 @@ class PushNotification extends this.OS.GUI.BaseService
pushout: (s, o, mfeed) -> pushout: (s, o, mfeed) ->
d = { d = {
text: "[#{s}] #{o.name} (#{o.id}): #{o.data.m} : #{o.data.e}", text: "[#{s}] #{o.name} (#{o.id}): #{o.data.m}",
icon: o.data.icon, icon: o.data.icon,
iconclass: o.data.iconclass, iconclass: o.data.iconclass,
closable: true } closable: true }

View File

@ -10,6 +10,7 @@ class Files extends this.OS.GUI.BaseApplication
@navbar = @find "nav-bar" @navbar = @find "nav-bar"
@currdir = undefined @currdir = undefined
@favo = @find "favouri" @favo = @find "favouri"
@clipboard = undefined
@view.contextmenuHandler = (e, m) -> @view.contextmenuHandler = (e, m) ->
m.set "items", [ me.mnFile(), me.mnEdit() ] m.set "items", [ me.mnFile(), me.mnEdit() ]
@ -61,8 +62,8 @@ class Files extends this.OS.GUI.BaseApplication
if(d.error) if(d.error)
return me.error "Resource not found #{p}" return me.error "Resource not found #{p}"
me.currdir = dir me.currdir = dir
($ me.navinput).val p ($ me.navinput).val dir.path
me.view.set "path", p me.view.set "path", dir.path
me.view.set "data", d.result me.view.set "data", d.result
mnFile:() -> mnFile:() ->
@ -72,7 +73,10 @@ class Files extends this.OS.GUI.BaseApplication
child: [ child: [
{ text: "New file", dataid: "#{@name}-mkf" }, { text: "New file", dataid: "#{@name}-mkf" },
{ text: "New folder", dataid: "#{@name}-mkdir" }, { text: "New folder", dataid: "#{@name}-mkdir" },
{ text: "Upload", dataid: "#{@name}-upload" } { text: "Open with", dataid: "#{@name}-open" },
{ text: "Upload", dataid: "#{@name}-upload" },
{ text: "Download", dataid: "#{@name}-download" },
{ text: "Properties", dataid: "#{@name}-info" }
], onmenuselect: (e) -> me.actionFile e ], onmenuselect: (e) -> me.actionFile e
} }
mnEdit: () -> mnEdit: () ->
@ -82,9 +86,9 @@ class Files extends this.OS.GUI.BaseApplication
child: [ child: [
{ text: "Rename", dataid: "#{@name}-mv" }, { text: "Rename", dataid: "#{@name}-mv" },
{ text: "Delete", dataid: "#{@name}-rm" }, { text: "Delete", dataid: "#{@name}-rm" },
{ text: "Information", dataid: "#{@name}-info" }, { text: "Cut", dataid: "#{@name}-cut" },
{ text: "Open with", dataid: "#{@name}-open" }, { text: "Copy", dataid: "#{@name}-copy" },
{ text: "Download", dataid: "#{@name}-download" }, { text: "Paste", dataid: "#{@name}-paste" }
], onmenuselect: (e) -> me.actionEdit e ], onmenuselect: (e) -> me.actionEdit e
} }
menu: () -> menu: () ->
@ -138,30 +142,90 @@ class Files extends this.OS.GUI.BaseApplication
#@toggleNav e.item.data.checked #@toggleNav e.item.data.checked
actionEdit: (e) -> actionEdit: (e) ->
me = @
file = @view.get "selectedFile"
switch e.item.data.dataid switch e.item.data.dataid
when "#{@name}-info" when "#{@name}-mv"
file = @view.get "selectedFile"
return unless file return unless file
@openDialog "InfoDialog", null, file @openDialog "PromptDialog",
(d) ->
return if d is file.filename
file.path.asFileHandler()
.move "#{me.currdir.path}/#{d}", (r) ->
if r.result then me.chdir null else me.error "Fail to rename to #{d}: #{r.error}"
, "Rename", file.filename
when "#{@name}-rm"
return unless file
@openDialog "YesNoDialog",
(d) ->
return unless d
file.path.asFileHandler()
.remove (r) ->
if r.result then me.chdir null else me.error "Fail to delete #{file.filename}: #{r.error}"
, "Delete" ,
{ iconclass: "fa fa-question-circle", text: "Do you really want to delete: #{file.filename} ?" }
when "#{@name}-cut"
return unless file
@clipboard =
cut: true
file: file.path.asFileHandler()
@notify "File #{file.filename} cut"
when "#{@name}-copy"
return unless file
@clipboard =
cut: false
file: file.path.asFileHandler()
@notify "File #{file.filename} copied"
when "#{@name}-paste"
me = @
return unless @clipboard
if @clipboard.cut
@clipboard.file # duplicate file check
.move "#{me.currdir.path}/#{@clipboard.file.basename}", (r) ->
me.clipboard = undefined
if r.result then me.chdir null else me.error "Fail to paste: #{r.error}"
else
@notify "Copy not yet implemented"
@clipboard = undefined
else else
@_api.handler.setting() @_api.handler.setting()
actionFile: (e) -> actionFile: (e) ->
me = @ me = @
file = @view.get "selectedFile"
switch e.item.data.dataid switch e.item.data.dataid
when "#{@name}-mkdir" when "#{@name}-mkdir"
@openDialog "PromptDialog", @openDialog "PromptDialog",
(d) -> (d) ->
me.currdir.mk d, (r) -> me.currdir.mk d, (r) ->
if r.result then me.chdir null else me.error "Fail to create #{d}" if r.result then me.chdir null else me.error "Fail to create #{d}: #{r.error}"
, "New folder" , "New folder"
when "#{@name}-mkf" when "#{@name}-mkf"
@openDialog "PromptDialog", @openDialog "PromptDialog",
(d) -> (d) ->
fp = "#{me.currdir.path}/#{d}".asFileHandler() fp = "#{me.currdir.path}/#{d}".asFileHandler()
fp.write "", (r) -> fp.write "", (r) ->
if r.result then me.chdir null else me.error "Fail to create #{d}" if r.result then me.chdir null else me.error "Fail to create #{d}: #{r.error}"
, "New file" , "New file"
when "#{@name}-info"
return unless file
@openDialog "InfoDialog", null, file.filename, file
when "#{@name}-upload"
me = @
@currdir.upload (r) ->
if r.result then me.chdir null else me.error "Faile to upload to: #{d}: #{r.error}"
when "#{@name}-download"
return unless file
file.path.asFileHandler().download ()->
else else
console.log e console.log e