update Docify

This commit is contained in:
lxsang 2020-11-22 21:00:55 +00:00
parent 685841635f
commit 6ee45214af
11 changed files with 655 additions and 506 deletions

View File

@ -31,6 +31,49 @@ local mkdirp =function(p)
return true, nil return true, nil
end end
local merge_files = function(data)
local firstfile = data.file[1]
local fpath = docpath.."/"..data.cid
local r, e = mkdirp(fpath)
if not r then return e end
fpath = fpath.."/"..os.date("%d-%m-%Y_%H_%M_%S")..".pdf"
-- concat the files
if #data.file > 1 then
local cmd = "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="..vfs.ospath(fpath)
for i,v in ipairs(data.file) do
cmd = cmd.." "..vfs.ospath(v)
end
os.execute(cmd)
if not vfs.exists(fpath) then
return error("Unable to merge PDF files")
end
cmd = "chmod 777 "..vfs.ospath(fpath)
os.execute(cmd)
else
if not vfs.move(firstfile, fpath) then
return error("Unable to move file")
end
end
-- move the thumb file to the cache folder
local thumb = docpath.."/cache/"..std.sha1(firstfile:gsub(docpath, ""))..".png"
local desthumb = docpath.."/cache/"..std.sha1(fpath:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.move(thumb, desthumb)
end
-- remove all other thumb files
for i,v in ipairs(data.file) do
thumb = docpath.."/cache/"..std.sha1(v:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.delete(thumb)
end
-- delete all files
if vfs.exists(v) then
vfs.delete(v)
end
end
return result(fpath)
end
handle.init = function(args) handle.init = function(args)
local r, e = mkdirp(docpath) local r, e = mkdirp(docpath)
@ -124,6 +167,20 @@ handle.init = function(args)
return result("Docify initialized") return result("Docify initialized")
end end
handle.select = function(param)
local db = sqlite._getdb(vfs.ospath(dbpath))
if not db then
return error("Unable to get database "..dbpath)
end
local r = sqlite.select(db, param.table, "*", param.cond)
sqlite.dbclose(db)
if r == nil then
return error("Unable to select data from "..param.table)
else
return result(r)
end
end
handle.fetch = function(table) handle.fetch = function(table)
local db = sqlite._getdb(vfs.ospath(dbpath)) local db = sqlite._getdb(vfs.ospath(dbpath))
if not db then if not db then
@ -176,19 +233,113 @@ handle.preview = function(path)
local tpath = docpath.."/cache/"..name local tpath = docpath.."/cache/"..name
if not vfs.exists(tpath) then if not vfs.exists(tpath) then
-- regenerate thumb -- regenerate thumb
local cmd = "convert -resize 200x500 "..vfs.ospath(path).."[0] "..vfs.ospath(tpath) local cmd = "convert -resize 250x500 "..vfs.ospath(path).."[0] "..vfs.ospath(tpath)
os.execute(cmd) os.execute(cmd)
end end
if vfs.exists(tpath) then if vfs.exists(tpath) then
--local cmd = "rm "..vfs.ospath(tpath) local cmd = "chmod 777 "..vfs.ospath(tpath)
--os.execute(cmd) os.execute(cmd)
return result("exist") return result(tpath)
else else
return error("do not exist") return error("do not exist")
end end
end end
handle.get_doc = function(id)
local db = sqlite._getdb(vfs.ospath(dbpath))
if not db then
return error("Unable to get database "..dbpath)
end
local r = sqlite.select(db, "docs", "*", "id = "..id)
if r == nil or #r == 0 then
sqlite.dbclose(db)
return error("Unable to select data from "..param.table)
else
r = r[1]
local o = sqlite.select(db, "owners", "*", "id = "..r.oid)
sqlite.dbclose(db)
if o == nil or #o == 0 then
return result(r)
else
o = o[1]
r.owner = o.name
if r.ctime then
r.ctime = os.date("%d/%m/%Y %H:%M:%S", r.ctime)
end
if r.mtime then
r.mtime = os.date("%d/%m/%Y %H:%M:%S", r.mtime)
end
local edate = ""
return result(r)
end
end
end
handle.deletedoc = function(param)
local db = sqlite._getdb(vfs.ospath(dbpath))
if not db then
return error("Unable to get database "..dbpath)
end
local sql = "DELETE FROM docs WHERE id="..param.id..";"
local ret = sqlite.query(db, sql) == 1
sqlite.dbclose(db)
if not ret then
return error("Unable to delete doc meta-data from database")
end
-- move file to unclassified
local newfile = docpath.."/unclassified/"..std.basename(param.file)
vfs.move(param.file, newfile)
-- delete thumb file
local thumb = docpath.."/cache/"..std.sha1(param.file:gsub(docpath,""))..".png"
if vfs.exists(thumb) then
vfs.delete(thumb)
end
return result("Document entry deleted")
end
handle.updatedoc = function(param)
local r = merge_files(param.data)
if r.error then return r end
if param.rm then
-- move ve the old file to unclassified
local newfile = docpath.."/unclassified/"..std.basename(param.rm)
if vfs.exists(param.rm) then
vfs.move(param.rm, newfile)
end
-- move the thumb file if needed
local thumb = docpath.."/cache/"..std.sha1(param.rm:gsub(docpath,""))..".png"
local newwthumb = docpath.."/cache/"..std.sha1(newfile:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.move(thumb, newwthumb)
end
end
param.data.file = r.result
print(r.result)
param.data.mtime = os.time(os.date("!*t"))
return handle.update({
table = "docs",
data = param.data
})
end
handle.insertdoc = function(data)
local r = merge_files(data)
if r.error then return r end
-- save data
data.file = r.result
data.ctime = os.time(os.date("!*t"))
data.mtime = os.time(os.date("!*t"))
local ret = handle.insert({
table = "docs",
data = data
})
return ret
end
handle.update = function(param) handle.update = function(param)
if not param.data.id or param.data.id == 0 then if not param.data.id or param.data.id == 0 then
return error("Record id is 0 or not found") return error("Record id is 0 or not found")

View File

@ -1,4 +1,4 @@
<afx-app-window apptitle="Docify" width="700" height="400" data-id="Docify"> <afx-app-window apptitle="Docify" width="700" height="500" data-id="Docify">
<afx-hbox > <afx-hbox >
<div data-width="5"></div> <div data-width="5"></div>
<afx-vbox data-width="150"> <afx-vbox data-width="150">
@ -8,15 +8,26 @@
</afx-vbox> </afx-vbox>
<afx-resizer data-width="4"></afx-resizer> <afx-resizer data-width="4"></afx-resizer>
<afx-vbox data-width = "300"> <afx-vbox data-width = "300">
<afx-grid-view data-id="gridview"></afx-grid-view> <afx-label class="header" iconclass = "fa fa-bars" text="__(Documents)" data-height="22"></afx-label>
<afx-list-view data-id="docview"></afx-list-view>
<afx-hbox data-height="30"> <afx-hbox data-height="30">
<div data-width="5"></div> <div data-width="5"></div>
<afx-button data-id="bt-add-doc" data-width = "25" text = "" iconclass = "fa fa-plus-circle"></afx-button> <afx-button data-id="bt-add-doc" data-width = "25" text = "" iconclass = "fa fa-plus-circle"></afx-button>
<afx-button data-width = "25" text = "" iconclass = "fa fa-minus-circle"></afx-button> <afx-button data-id="bt-del-doc" data-width = "25" text = "" iconclass = "fa fa-minus-circle"></afx-button>
<afx-button data-width = "25" text = "" iconclass = "fa fa-pencil-square-o"></afx-button> <afx-button data-id="bt-edit-doc" data-width = "25" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
</afx-hbox> </afx-hbox>
</afx-vbox> </afx-vbox>
<afx-resizer data-width="4"></afx-resizer> <afx-resizer data-width="4"></afx-resizer>
<afx-vbox></afx-vbox> <afx-vbox>
<div data-id = "preview-container">
<canvas data-id="preview-canvas"></canvas>
</div>
<afx-grid-view data-id="docgrid"></afx-grid-view>
<div style="text-align: right;" data-height="30" >
<afx-button text="__(Open)" data-id="btopen" ></afx-button>
<afx-button text="__(Download)" data-id="btdld" ></afx-button>
<afx-button text="__(Print)" data-id="btopen" ></afx-button>
</div>
</afx-vbox>
</afx-hbox> </afx-hbox>
</afx-app-window> </afx-app-window>

View File

@ -31,6 +31,49 @@ local mkdirp =function(p)
return true, nil return true, nil
end end
local merge_files = function(data)
local firstfile = data.file[1]
local fpath = docpath.."/"..data.cid
local r, e = mkdirp(fpath)
if not r then return e end
fpath = fpath.."/"..os.date("%d-%m-%Y_%H_%M_%S")..".pdf"
-- concat the files
if #data.file > 1 then
local cmd = "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="..vfs.ospath(fpath)
for i,v in ipairs(data.file) do
cmd = cmd.." "..vfs.ospath(v)
end
os.execute(cmd)
if not vfs.exists(fpath) then
return error("Unable to merge PDF files")
end
cmd = "chmod 777 "..vfs.ospath(fpath)
os.execute(cmd)
else
if not vfs.move(firstfile, fpath) then
return error("Unable to move file")
end
end
-- move the thumb file to the cache folder
local thumb = docpath.."/cache/"..std.sha1(firstfile:gsub(docpath, ""))..".png"
local desthumb = docpath.."/cache/"..std.sha1(fpath:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.move(thumb, desthumb)
end
-- remove all other thumb files
for i,v in ipairs(data.file) do
thumb = docpath.."/cache/"..std.sha1(v:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.delete(thumb)
end
-- delete all files
if vfs.exists(v) then
vfs.delete(v)
end
end
return result(fpath)
end
handle.init = function(args) handle.init = function(args)
local r, e = mkdirp(docpath) local r, e = mkdirp(docpath)
@ -124,6 +167,20 @@ handle.init = function(args)
return result("Docify initialized") return result("Docify initialized")
end end
handle.select = function(param)
local db = sqlite._getdb(vfs.ospath(dbpath))
if not db then
return error("Unable to get database "..dbpath)
end
local r = sqlite.select(db, param.table, "*", param.cond)
sqlite.dbclose(db)
if r == nil then
return error("Unable to select data from "..param.table)
else
return result(r)
end
end
handle.fetch = function(table) handle.fetch = function(table)
local db = sqlite._getdb(vfs.ospath(dbpath)) local db = sqlite._getdb(vfs.ospath(dbpath))
if not db then if not db then
@ -176,19 +233,113 @@ handle.preview = function(path)
local tpath = docpath.."/cache/"..name local tpath = docpath.."/cache/"..name
if not vfs.exists(tpath) then if not vfs.exists(tpath) then
-- regenerate thumb -- regenerate thumb
local cmd = "convert -resize 200x500 "..vfs.ospath(path).."[0] "..vfs.ospath(tpath) local cmd = "convert -resize 250x500 "..vfs.ospath(path).."[0] "..vfs.ospath(tpath)
os.execute(cmd) os.execute(cmd)
end end
if vfs.exists(tpath) then if vfs.exists(tpath) then
local cmd = "rm "..vfs.ospath(tpath) local cmd = "chmod 777 "..vfs.ospath(tpath)
os.execute(cmd) os.execute(cmd)
return result("exist") return result(tpath)
else else
return error("do not exist") return error("do not exist")
end end
end end
handle.get_doc = function(id)
local db = sqlite._getdb(vfs.ospath(dbpath))
if not db then
return error("Unable to get database "..dbpath)
end
local r = sqlite.select(db, "docs", "*", "id = "..id)
if r == nil or #r == 0 then
sqlite.dbclose(db)
return error("Unable to select data from "..param.table)
else
r = r[1]
local o = sqlite.select(db, "owners", "*", "id = "..r.oid)
sqlite.dbclose(db)
if o == nil or #o == 0 then
return result(r)
else
o = o[1]
r.owner = o.name
if r.ctime then
r.ctime = os.date("%d/%m/%Y %H:%M:%S", r.ctime)
end
if r.mtime then
r.mtime = os.date("%d/%m/%Y %H:%M:%S", r.mtime)
end
local edate = ""
return result(r)
end
end
end
handle.deletedoc = function(param)
local db = sqlite._getdb(vfs.ospath(dbpath))
if not db then
return error("Unable to get database "..dbpath)
end
local sql = "DELETE FROM docs WHERE id="..param.id..";"
local ret = sqlite.query(db, sql) == 1
sqlite.dbclose(db)
if not ret then
return error("Unable to delete doc meta-data from database")
end
-- move file to unclassified
local newfile = docpath.."/unclassified/"..std.basename(param.file)
vfs.move(param.file, newfile)
-- delete thumb file
local thumb = docpath.."/cache/"..std.sha1(param.file:gsub(docpath,""))..".png"
if vfs.exists(thumb) then
vfs.delete(thumb)
end
return result("Document entry deleted")
end
handle.updatedoc = function(param)
local r = merge_files(param.data)
if r.error then return r end
if param.rm then
-- move ve the old file to unclassified
local newfile = docpath.."/unclassified/"..std.basename(param.rm)
if vfs.exists(param.rm) then
vfs.move(param.rm, newfile)
end
-- move the thumb file if needed
local thumb = docpath.."/cache/"..std.sha1(param.rm:gsub(docpath,""))..".png"
local newwthumb = docpath.."/cache/"..std.sha1(newfile:gsub(docpath, ""))..".png"
if vfs.exists(thumb) then
vfs.move(thumb, newwthumb)
end
end
param.data.file = r.result
print(r.result)
param.data.mtime = os.time(os.date("!*t"))
return handle.update({
table = "docs",
data = param.data
})
end
handle.insertdoc = function(data)
local r = merge_files(data)
if r.error then return r end
-- save data
data.file = r.result
data.ctime = os.time(os.date("!*t"))
data.mtime = os.time(os.date("!*t"))
local ret = handle.insert({
table = "docs",
data = data
})
return ret
end
handle.update = function(param) handle.update = function(param)
if not param.data.id or param.data.id == 0 then if not param.data.id or param.data.id == 0 then
return error("Record id is 0 or not found") return error("Record id is 0 or not found")

View File

@ -3,3 +3,14 @@ afx-app-window[data-id = "Docify"] .header .label-text
{ {
font-weight: bold; font-weight: bold;
} }
div[data-id = "preview-container"]
{
overflow: auto;
display: block;
}
canvas[data-id = "preview-canvas"]
{
display: block;
margin:0 auto;
}

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
<afx-app-window apptitle="Docify" width="700" height="400" data-id="Docify"> <afx-app-window apptitle="Docify" width="700" height="500" data-id="Docify">
<afx-hbox > <afx-hbox >
<div data-width="5"></div> <div data-width="5"></div>
<afx-vbox data-width="150"> <afx-vbox data-width="150">
@ -8,15 +8,26 @@
</afx-vbox> </afx-vbox>
<afx-resizer data-width="4"></afx-resizer> <afx-resizer data-width="4"></afx-resizer>
<afx-vbox data-width = "300"> <afx-vbox data-width = "300">
<afx-grid-view data-id="gridview"></afx-grid-view> <afx-label class="header" iconclass = "fa fa-bars" text="__(Documents)" data-height="22"></afx-label>
<afx-list-view data-id="docview"></afx-list-view>
<afx-hbox data-height="30"> <afx-hbox data-height="30">
<div data-width="5"></div> <div data-width="5"></div>
<afx-button data-id="bt-add-doc" data-width = "25" text = "" iconclass = "fa fa-plus-circle"></afx-button> <afx-button data-id="bt-add-doc" data-width = "25" text = "" iconclass = "fa fa-plus-circle"></afx-button>
<afx-button data-width = "25" text = "" iconclass = "fa fa-minus-circle"></afx-button> <afx-button data-id="bt-del-doc" data-width = "25" text = "" iconclass = "fa fa-minus-circle"></afx-button>
<afx-button data-width = "25" text = "" iconclass = "fa fa-pencil-square-o"></afx-button> <afx-button data-id="bt-edit-doc" data-width = "25" text = "" iconclass = "fa fa-pencil-square-o"></afx-button>
</afx-hbox> </afx-hbox>
</afx-vbox> </afx-vbox>
<afx-resizer data-width="4"></afx-resizer> <afx-resizer data-width="4"></afx-resizer>
<afx-vbox></afx-vbox> <afx-vbox>
<div data-id = "preview-container">
<canvas data-id="preview-canvas"></canvas>
</div>
<afx-grid-view data-id="docgrid"></afx-grid-view>
<div style="text-align: right;" data-height="30" >
<afx-button text="__(Open)" data-id="btopen" ></afx-button>
<afx-button text="__(Download)" data-id="btdld" ></afx-button>
<afx-button text="__(Print)" data-id="btopen" ></afx-button>
</div>
</afx-vbox>
</afx-hbox> </afx-hbox>
</afx-app-window> </afx-app-window>

Binary file not shown.

View File

@ -74,47 +74,147 @@ class DocDialog extends this.OS.GUI.BasicDialog
main: () -> main: () ->
super.main() super.main()
@find("file-list").buttons = [ @flist = @find("file-list")
@dlist = @find("dlist")
@mlist = @find("mlist")
@ylist = @find("ylist")
@olist = @find("olist")
@setting = @parent.setting
@exec = @parent.exec
@preview = @parent.preview
@exec("fetch", "owners")
.then (d) =>
return @error d.error if d.error
v.text = v.name for v in d.result
v.selected = (@data and @data.oid is v.id) for v in d.result
@olist.data = d.result
@olist.selected = 0 if not @olist.selectedItem
.catch (e) =>
@error __("Unable to fetch owner list: {0}", e.toString()), e
@dlist.push {
text:"None",
value: 0
}
selected = 0
for d in [1..31]
@dlist.push {
text:"#{d}",
value: d
}
selected = d if @data and parseInt(@data.day) is d
@dlist.selected = selected
@mlist.push {
text:"None",
value: 0
}
selected = 0
for d in [1..12]
@mlist.push {
text:"#{d}",
value: d
}
selected = d if @data and parseInt(@data.month) is d
@mlist.selected = selected
@ylist.push {
text:"None",
value: 0
}
@ylist.selected = 0
for y in [1980..new Date().getFullYear()]
@ylist.push {
text:"#{y}",
value: y,
selected: @data and parseInt(@data.year) is y
}
@flist.buttons = [
{ {
text: "", text: "",
iconclass: "fa fa-plus-circle", iconclass: "fa fa-plus-circle",
onbtclick: (e) => onbtclick: (e) =>
@openDialog(new FilePreviewDialog())
.then (d) =>
d.text = d.filename
@flist.push d
}, },
{ {
text: "", text: "",
iconclass: "fa fa-minus-circle", iconclass: "fa fa-minus-circle",
onbtclick: (e) => onbtclick: (e) =>
item = @flist.selectedItem
return unless item
@flist.delete item
} }
] ]
@flist.onlistselect = (e) =>
@parent.preview(e.data.item.data.path, @find("preview-canvas"))
@find("btsave").onbtclick = (e) =>
data = {
name: @find("title").value.trim(),
day: @dlist.selectedItem.data.value,
month: @mlist.selectedItem.data.value,
year: @ylist.selectedItem.data.value,
file: (v.path for v in @flist.data),
note: @find("note").value.trim(),
tags: @find("tag").value.trim(),
oid: parseInt(@olist.selectedItem.data.id)
}
return @notify __("Please enter title") unless data.name and data.title != ""
return @notify __("Please attach files to the entry") unless data.file.length > 0
@handle data if @handle
@quit()
return unless @data
@find("title").value = @data.name
@find("note").value = @data.note
@find("tag").value = @data.tags
file = @data.file.asFileHandle()
file.text = file.filename
@flist.data = [ file ]
# owner
DocDialog.scheme = """ DocDialog.scheme = """
<afx-app-window width='500' height='300'> <afx-app-window width='600' height='400'>
<afx-hbox> <afx-hbox>
<afx-vbox data-width="300"> <afx-vbox data-width="350">
<afx-hbox data-height="22"> <afx-hbox data-height="22">
<afx-label text = "__(title)" data-width="50"></afx-label> <afx-label text = "__(title)" data-width="50"></afx-label>
<input type="text"></input> <input type="text" data-id="title"></input>
</afx-hbox> </afx-hbox>
<afx-hbox data-height="22"> <afx-hbox data-height="22">
<afx-label text = "__(Day)" data-width="50"></afx-label> <afx-label text = "__(Day)" data-width="50"></afx-label>
<afx-list-view dropdown="true"></afx-list-view> <afx-list-view dropdown="true" data-id="dlist"></afx-list-view>
<afx-label text = "__(Month)"data-width="50" ></afx-label> <afx-label text = "__(Month)"data-width="50" ></afx-label>
<afx-list-view dropdown="true"></afx-list-view> <afx-list-view dropdown="true" data-id="mlist"></afx-list-view>
<afx-label text = "__(Year)"data-width="50" ></afx-label> <afx-label text = "__(Year)"data-width="50" ></afx-label>
<afx-list-view dropdown="true"></afx-list-view> <afx-list-view dropdown="true" data-id="ylist"></afx-list-view>
</afx-hbox> </afx-hbox>
<afx-label text = "__(Files)" data-height="22"></afx-label> <afx-label text = "__(Files)" data-height="22"></afx-label>
<afx-list-view data-id="file-list"></afx-list-view> <afx-list-view data-id="file-list"></afx-list-view>
<afx-label text = "__(Note)" data-height="22"></afx-label> <afx-label text = "__(Note)" data-height="22"></afx-label>
<textarea></textarea> <textarea data-id="note"></textarea>
<afx-hbox data-height = "27"> <afx-hbox data-height = "27">
<afx-label text = "__(Owner)" data-width="50"></afx-label>
<afx-list-view dropdown="true" data-id="olist"></afx-list-view>
<afx-label text = "__(Tags)" data-width="50"></afx-label> <afx-label text = "__(Tags)" data-width="50"></afx-label>
<input type="text"></input> <input type="text" data-id="tag"></input>
</afx-hbox> </afx-hbox>
</afx-vbox> </afx-vbox>
<afx-vbox> <afx-vbox>
<div></div> <div data-id = "preview-container">
<afx-button text="__(Save)" iconclass="" data-height="30" ></afx-button> <canvas data-id="preview-canvas"></canvas>
</div>
<div style="text-align: right;" data-height="30" >
<afx-button text="__(Save)" data-id="btsave" ></afx-button>
</div>
</afx-vbox> </afx-vbox>
</afx-hbox> </afx-hbox>
</afx-app-window> </afx-app-window>
@ -127,34 +227,49 @@ class FilePreviewDialog extends this.OS.GUI.BasicDialog
main: () -> main: () ->
super.main() super.main()
@flist = @find("file-list") @flist = @find("file-list")
@flist.buttons = [
{
text: "",
iconclass: "fa fa-refresh",
onbtclick: (e) => @refresh()
}
]
@flist.onlistselect = (e) => @flist.onlistselect = (e) =>
# console.log e.data.item.data # console.log e.data.item.data
@parent.exec("preview", e.data.item.data.path) @parent.preview(e.data.item.data.path, @find("preview-canvas"))
.then (d) => @find("btok").onbtclick = (e) =>
console.log d item = @flist.selectedItem
.catch (e) => return @quit() unless item
@error e.toString(), e @handle(item.data) if @handle
@quit()
@refresh() @refresh()
refresh: () -> refresh: () ->
"#{@parent.setting.docpath}/unclassified".asFileHandle().read() "#{@parent.setting.docpath}/unclassified".asFileHandle().read()
.then (d) => .then (d) =>
return @parent.error d.error if d.error return @error d.error if d.error
v.text = v.filename for v in d.result v.text = v.filename for v in d.result
@flist.data = d.result @flist.data = d.result
.catch (e) => .catch (e) =>
@error __("Unable to fetch unclassified file list: {0}", e.toString()), e @error __("Unable to fetch unclassified file list: {0}", e.toString()), e
FilePreviewDialog.scheme = """ FilePreviewDialog.scheme = """
<afx-app-window width='500' height='300'> <afx-app-window width='400' height='400' apptitle = "__(Document preview)">
<afx-hbox> <afx-hbox>
<afx-vbox data-width="200"> <afx-vbox data-width="150">
<afx-label text = "__(Files)" data-height="22"></afx-label> <afx-label text = "__(Files)" data-height="22"></afx-label>
<afx-list-view data-id="file-list"></afx-list-view> <afx-list-view data-id="file-list"></afx-list-view>
</afx-vbox> </afx-vbox>
<afx-vbox> <afx-vbox>
<div></div> <div data-id = "preview-container">
<afx-button text="__(Ok)" iconclass="" data-height="30" ></afx-button> <canvas data-id="preview-canvas"></canvas>
</div>
<div style="text-align: right;" data-height="30" >
<afx-button text="__(Ok)" data-id="btok" ></afx-button>
</div>
</afx-vbox> </afx-vbox>
</afx-hbox> </afx-hbox>
</afx-app-window> </afx-app-window>

View File

@ -5,6 +5,27 @@ class Docify extends this.OS.application.BaseApplication
main: () -> main: () ->
@catview = @find "catview" @catview = @find "catview"
@docview = @find "docview"
@docpreview = @find "preview-canvas"
@docgrid = @find "docgrid"
@docgrid.header = [
{ text: "", width: 100 },
{ text: "" },
]
@find("btdld").onbtclick = (e) =>
item = @docview.selectedItem
return unless item
item.data.file.asFileHandle()
.download()
.catch (e) => @error __("Unable to download: {}", e.toString()), e
@find("btopen").onbtclick = (e) =>
item = @docview.selectedItem
return unless item
item.data.file.asFileHandle().meta()
.then (m) =>
return @error m.error if m.error
@_gui.openWith m.result
.catch (e) => @error e.toString(), e
@catview.buttons = [ @catview.buttons = [
{ {
text: "", text: "",
@ -16,8 +37,8 @@ class Docify extends this.OS.application.BaseApplication
.then (r) => .then (r) =>
return @error r.error if r.error return @error r.error if r.error
@cat_refresh() @cat_refresh()
.catch (e) => @error __("Unable to insert category: {0}", e.toString()) .catch (e) => @error __("Unable to insert category: {0}", e.toString()), e
.catch (e) => @error e.toString() .catch (e) => @error e.toString(), e
}, },
{ {
text: "", text: "",
@ -33,7 +54,7 @@ class Docify extends this.OS.application.BaseApplication
return @error d.error if d.error return @error d.error if d.error
@cat_refresh() @cat_refresh()
.catch (e) => .catch (e) =>
@error __("Unable delete category: {0}", e.toString()) @error __("Unable delete category: {0}", e.toString()), e
}, },
{ {
text: "", text: "",
@ -47,22 +68,136 @@ class Docify extends this.OS.application.BaseApplication
.then (r) => .then (r) =>
return @error r.error if r.error return @error r.error if r.error
@cat_refresh() @cat_refresh()
.catch (e) => @error __("Unable to update category: {0}", e.toString()) .catch (e) => @error __("Unable to update category: {0}", e.toString()), e
.catch (e) => @error e.toString() .catch (e) => @error e.toString(), e
} }
] ]
@docview.onlistselect = (e) =>
@clear_preview()
item = e.data.item
return unless item
@exec("get_doc", item.data.id)
.then (d) =>
return @error d.error if d.error
@preview d.result.file, @docpreview
rows = []
map = {
ctime: "Created on",
mtime: "Modified on",
note: "Note",
tags: "Tags",
name: "Title",
owner: "Owner",
edate: "Effective date",
file: "File"
}
d.result.edate = "#{d.result.day}/#{d.result.month}/#{d.result.year}"
for key, value of d.result
field = map[key]
rows.push [{text: field}, {text: value}] if field
@docgrid.rows = rows
.catch (e) => @error e.toString(), e
@catview.onlistselect = (e) =>
@clear_preview()
item = e.data.item
return unless item
@update_doclist(item.data.id)
@find("bt-add-doc").onbtclick = (e) => @find("bt-add-doc").onbtclick = (e) =>
@openDialog new DocDialog catiem = @catview.selectedItem
return @notify __("Please select a category") unless catiem
@openDialog(new DocDialog())
.then (data) =>
data.cid = parseInt(catiem.data.id)
@exec("insertdoc", data)
.then (d) =>
return @error d.error if d.error
@notify d.result if d.result
@update_doclist(catiem.data.id)
@clear_preview()
.catch (e) => @error e.toString(), e
@find("bt-del-doc").onbtclick = (e) =>
item = @docview.selectedItem
return unless item
@ask({ text: __("Do you really want to delete: `{0}`", item.data.name) })
.then (d) =>
return unless d
@exec("deletedoc", {id: item.data.id, file: item.data.file})
.then (r) =>
return @error r.error if r.error
@notify r.result
@update_doclist(item.data.cid)
@clear_preview()
.catch (e) =>
@error e.toString(), e
@find("bt-edit-doc").onbtclick = (e) =>
item = @docview.selectedItem
catiem = @catview.selectedItem
return unless item
@openDialog(new DocDialog(), item.data)
.then (data) =>
data.cid = parseInt(catiem.data.id)
data.id = item.data.id
@exec("updatedoc", {
data:data,
rm: if not data.file.includes(item.data.file) then item.data.file else false
})
.then (d) =>
return @error d.error if d.error
@notify d.result if d.result
@update_doclist(catiem.data.id)
@clear_preview()
.catch (e) => @error e.toString(), e
@initialize() @initialize()
update_doclist: (cid) ->
@exec("select",{table: "docs", cond:"cid = #{cid}"})
.then (d) =>
return @error d.error if d.error
v.text = v.name for v in d.result
@docview.data = d.result
.catch (e) =>
@error e.toString(), e
clear_preview: () ->
@docpreview.getContext('2d').clearRect(0,0,@docpreview.width,@docpreview.height)
@docgrid.rows = []
preview: (path, canvas) ->
@exec("preview", path)
.then (d) =>
return @error d.error if d.error
file = d.result.asFileHandle()
file.read("binary")
.then (d) =>
img = new Image()
#($ me.view).append img
img.onload = () =>
context = canvas.getContext '2d'
canvas.height = img.height
canvas.width = img.width
#console.log canvas.width, canvas.height
context.drawImage img, 0, 0
blob = new Blob [d], { type: file.info.mime }
img.src = URL.createObjectURL blob
.catch (e) => @error e.toString(), e
.catch (e) =>
@error e.toString(), e
cat_refresh: () -> cat_refresh: () ->
@exec("fetch", "categories") @exec("fetch", "categories")
.then (d) => .then (d) =>
v.text = v.name for v in d.result v.text = v.name for v in d.result
@catview.data = d.result @catview.data = d.result
.catch (err) => @error __("Unable to fetch categories: {0}", err.toString()) .catch (err) => @error __("Unable to fetch categories: {0}", err.toString()), err
initialize: () -> initialize: () ->
# Check if we have configured docpath # Check if we have configured docpath
@ -97,7 +232,7 @@ class Docify extends this.OS.application.BaseApplication
# load categories # load categories
@cat_refresh() @cat_refresh()
.catch (e) => .catch (e) =>
@error __("Unable to init database: {0}", e.toString()) @error __("Unable to init database: {0}", e.toString()), e
menu: () -> menu: () ->
[ [
@ -116,6 +251,8 @@ class Docify extends this.OS.application.BaseApplication
when "owners" when "owners"
@openDialog new OwnerDialog(), { title: __("Owners")} @openDialog new OwnerDialog(), { title: __("Owners")}
when "preview" when "preview"
@openDialog new FilePreviewDialog() @openDialog(new FilePreviewDialog())
.then (d) =>
@notify d.path
this.OS.register "Docify", Docify this.OS.register "Docify", Docify

View File

@ -2,3 +2,14 @@ afx-app-window[data-id = "Docify"] .header .label-text
{ {
font-weight: bold; font-weight: bold;
} }
div[data-id = "preview-container"]
{
overflow: auto;
display: block;
}
canvas[data-id = "preview-canvas"]
{
display: block;
margin:0 auto;
}

View File

@ -71,6 +71,15 @@
"version": "0.0.2-a", "version": "0.0.2-a",
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/DBDecoder/build/release/DBDecoder.zip" "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/DBDecoder/build/release/DBDecoder.zip"
}, },
{
"pkgname": "Docify",
"name": "Docify",
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Docify/README.md",
"category": "Other",
"author": "",
"version": "0.0.1-a",
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Docify/build/release/Docify.zip"
},
{ {
"pkgname": "GraphEditor", "pkgname": "GraphEditor",
"name": "Graph Editor", "name": "Graph Editor",