From 6ee45214af3e6074e0903f1390ab5cd98b283348 Mon Sep 17 00:00:00 2001 From: lxsang Date: Sun, 22 Nov 2020 21:00:55 +0000 Subject: [PATCH] update Docify --- Docify/api/api.lua | 159 ++++++++++- Docify/assets/scheme.html | 21 +- Docify/build/debug/api.lua | 157 ++++++++++- Docify/build/debug/main.css | 11 + Docify/build/debug/main.js | 460 +------------------------------- Docify/build/debug/scheme.html | 21 +- Docify/build/release/Docify.zip | Bin 0 -> 28503 bytes Docify/coffees/dialogs.coffee | 157 +++++++++-- Docify/coffees/main.coffee | 155 ++++++++++- Docify/css/main.css | 11 + packages.json | 9 + 11 files changed, 655 insertions(+), 506 deletions(-) create mode 100644 Docify/build/release/Docify.zip diff --git a/Docify/api/api.lua b/Docify/api/api.lua index 5f44aba..db1e86d 100644 --- a/Docify/api/api.lua +++ b/Docify/api/api.lua @@ -31,6 +31,49 @@ local mkdirp =function(p) return true, nil 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) local r, e = mkdirp(docpath) @@ -124,6 +167,20 @@ handle.init = function(args) return result("Docify initialized") 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) local db = sqlite._getdb(vfs.ospath(dbpath)) if not db then @@ -176,19 +233,113 @@ handle.preview = function(path) local tpath = docpath.."/cache/"..name if not vfs.exists(tpath) then -- 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) end if vfs.exists(tpath) then - --local cmd = "rm "..vfs.ospath(tpath) - --os.execute(cmd) - return result("exist") + local cmd = "chmod 777 "..vfs.ospath(tpath) + os.execute(cmd) + return result(tpath) else return error("do not exist") 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) if not param.data.id or param.data.id == 0 then return error("Record id is 0 or not found") diff --git a/Docify/assets/scheme.html b/Docify/assets/scheme.html index 840e102..df9e332 100644 --- a/Docify/assets/scheme.html +++ b/Docify/assets/scheme.html @@ -1,4 +1,4 @@ - +
@@ -8,15 +8,26 @@ - + +
- - + +
- + +
+ +
+ +
+ + + +
+
\ No newline at end of file diff --git a/Docify/build/debug/api.lua b/Docify/build/debug/api.lua index 1b11aee..db1e86d 100644 --- a/Docify/build/debug/api.lua +++ b/Docify/build/debug/api.lua @@ -31,6 +31,49 @@ local mkdirp =function(p) return true, nil 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) local r, e = mkdirp(docpath) @@ -124,6 +167,20 @@ handle.init = function(args) return result("Docify initialized") 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) local db = sqlite._getdb(vfs.ospath(dbpath)) if not db then @@ -176,19 +233,113 @@ handle.preview = function(path) local tpath = docpath.."/cache/"..name if not vfs.exists(tpath) then -- 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) end if vfs.exists(tpath) then - local cmd = "rm "..vfs.ospath(tpath) + local cmd = "chmod 777 "..vfs.ospath(tpath) os.execute(cmd) - return result("exist") + return result(tpath) else return error("do not exist") 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) if not param.data.id or param.data.id == 0 then return error("Record id is 0 or not found") diff --git a/Docify/build/debug/main.css b/Docify/build/debug/main.css index bef144d..d6335a0 100644 --- a/Docify/build/debug/main.css +++ b/Docify/build/debug/main.css @@ -2,4 +2,15 @@ afx-app-window[data-id = "Docify"] .header .label-text { font-weight: bold; +} +div[data-id = "preview-container"] +{ + overflow: auto; + display: block; +} + +canvas[data-id = "preview-canvas"] +{ + display: block; + margin:0 auto; } \ No newline at end of file diff --git a/Docify/build/debug/main.js b/Docify/build/debug/main.js index 39fd3c8..5e7c5cf 100644 --- a/Docify/build/debug/main.js +++ b/Docify/build/debug/main.js @@ -1,459 +1 @@ -(function() { - var DocDialog, Docify, FilePreviewDialog, OwnerDialog; - - OwnerDialog = class OwnerDialog extends this.OS.GUI.BasicDialog { - constructor() { - super("OwnerDialog", OwnerDialog.scheme); - } - - main() { - super.main(); - this.oview = this.find("ownview"); - this.oview.buttons = [ - { - text: "", - iconclass: "fa fa-plus-circle", - onbtclick: (e) => { - return this.openDialog("PromptDialog", - { - title: __("Owner"), - label: __("Name") - }).then((d) => { - return this.parent.exec("insert", - { - table: "owners", - data: { - name: d - } - }).then((r) => { - if (r.error) { - return this.error(r.error); - } - return this.owner_refresh(); - }).catch((e) => { - return this.error(__("Unable to insert owner: {0}", - e.toString()), - e); - }); - }).catch((e) => { - return this.error(e.toString(), - e); - }); - } - }, - { - text: "", - iconclass: "fa fa-minus-circle", - onbtclick: (e) => { - var item; - item = this.oview.selectedItem; - if (!item) { - return; - } - return this.ask({ - text: __("Do you realy want to delete: `{0}`", - item.data.text) - }).then((d) => { - if (!d) { - return; - } - return this.parent.exec("delete", - { - table: "owners", - id: parseInt(item.data.id) - }).then((d) => { - if (d.error) { - return this.error(d.error); - } - return this.owner_refresh(); - }).catch((e) => { - return this.error(__("Unable delete category: {0}", - e.toString()), - e); - }); - }); - } - }, - { - text: "", - iconclass: "fa fa-pencil-square-o", - onbtclick: (e) => { - var item; - item = this.oview.selectedItem; - if (!item) { - return; - } - return this.openDialog("PromptDialog", - { - title: __("Owner"), - label: __("Name"), - value: item.data.name - }).then((d) => { - return this.parent.exec("update", - { - table: "owners", - data: { - id: parseInt(item.data.id), - name: d - } - }).then((r) => { - if (r.error) { - return this.error(r.error); - } - return this.owner_refresh(); - }).catch((e) => { - return this.error(__("Unable to update owner: {0}", - e.toString()), - e); - }); - }).catch((e) => { - return this.error(e.toString()); - }); - } - } - ]; - return this.owner_refresh(); - } - - owner_refresh() { - return this.parent.exec("fetch", "owners").then((d) => { - var i, len, ref, v; - ref = d.result; - for (i = 0, len = ref.length; i < len; i++) { - v = ref[i]; - v.text = v.name; - } - return this.oview.data = d.result; - }).catch((err) => { - return this.error(__("Unable to fetch owners: {0}", err.toString()), e); - }); - } - - }; - - OwnerDialog.scheme = ` - - - -`; - - DocDialog = class DocDialog extends this.OS.GUI.BasicDialog { - constructor() { - super("DocDialog", DocDialog.scheme); - } - - main() { - super.main(); - return this.find("file-list").buttons = [ - { - text: "", - iconclass: "fa fa-plus-circle", - onbtclick: (e) => {} - }, - { - text: "", - iconclass: "fa fa-minus-circle", - onbtclick: (e) => {} - } - ]; - } - - }; - - DocDialog.scheme = ` - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
-
`; - - FilePreviewDialog = class FilePreviewDialog extends this.OS.GUI.BasicDialog { - constructor() { - super("FilePreviewDialog", FilePreviewDialog.scheme); - } - - main() { - super.main(); - this.flist = this.find("file-list"); - this.flist.onlistselect = (e) => { - // console.log e.data.item.data - return this.parent.exec("preview", e.data.item.data.path).then((d) => { - return console.log(d); - }).catch((e) => { - return this.error(e.toString(), e); - }); - }; - return this.refresh(); - } - - refresh() { - return `${this.parent.setting.docpath}/unclassified`.asFileHandle().read().then((d) => { - var i, len, ref, v; - if (d.error) { - return this.parent.error(d.error); - } - ref = d.result; - for (i = 0, len = ref.length; i < len; i++) { - v = ref[i]; - v.text = v.filename; - } - return this.flist.data = d.result; - }).catch((e) => { - return this.error(__("Unable to fetch unclassified file list: {0}", e.toString()), e); - }); - } - - }; - - FilePreviewDialog.scheme = ` - - - - - - -
- -
-
-
`; - - Docify = class Docify extends this.OS.application.BaseApplication { - constructor(args) { - super("Docify", args); - } - - main() { - this.catview = this.find("catview"); - this.catview.buttons = [ - { - text: "", - iconclass: "fa fa-plus-circle", - onbtclick: (e) => { - return this.openDialog("PromptDialog", - { - title: __("Category"), - label: __("Name") - }).then((d) => { - return this.exec("insert", - { - table: "categories", - data: { - name: d - } - }).then((r) => { - if (r.error) { - return this.error(r.error); - } - return this.cat_refresh(); - }).catch((e) => { - return this.error(__("Unable to insert category: {0}", - e.toString())); - }); - }).catch((e) => { - return this.error(e.toString()); - }); - } - }, - { - text: "", - iconclass: "fa fa-minus-circle", - onbtclick: (e) => { - var item; - item = this.catview.selectedItem; - if (!item) { - return; - } - return this.ask({ - text: __("Do you realy want to delete: `{0}`", - item.data.text) - }).then((d) => { - if (!d) { - return; - } - return this.exec("delete", - { - table: "categories", - id: parseInt(item.data.id) - }).then((d) => { - if (d.error) { - return this.error(d.error); - } - return this.cat_refresh(); - }).catch((e) => { - return this.error(__("Unable delete category: {0}", - e.toString())); - }); - }); - } - }, - { - text: "", - iconclass: "fa fa-pencil-square-o", - onbtclick: (e) => { - var item; - item = this.catview.selectedItem; - if (!item) { - return; - } - return this.openDialog("PromptDialog", - { - title: __("Category"), - label: __("Name"), - value: item.data.name - }).then((d) => { - return this.exec("update", - { - table: "categories", - data: { - id: parseInt(item.data.id), - name: d - } - }).then((r) => { - if (r.error) { - return this.error(r.error); - } - return this.cat_refresh(); - }).catch((e) => { - return this.error(__("Unable to update category: {0}", - e.toString())); - }); - }).catch((e) => { - return this.error(e.toString()); - }); - } - } - ]; - this.find("bt-add-doc").onbtclick = (e) => { - return this.openDialog(new DocDialog()); - }; - return this.initialize(); - } - - cat_refresh() { - return this.exec("fetch", "categories").then((d) => { - var i, len, ref, v; - ref = d.result; - for (i = 0, len = ref.length; i < len; i++) { - v = ref[i]; - v.text = v.name; - } - return this.catview.data = d.result; - }).catch((err) => { - return this.error(__("Unable to fetch categories: {0}", err.toString())); - }); - } - - initialize() { - // Check if we have configured docpath - if (this.setting.docpath) { - // check data base - return this.initdb(); - } else { - // ask user to choose a docpath - return this.openDialog("FileDialog", { - title: __("Please select a doc path"), - mimes: ['dir'] - }).then((d) => { - this.setting.docpath = d.file.path; - this._api.setting(); - return this.initdb(); - }).catch((msg) => { - return this.error(msg.toString(), msg); - }); - } - } - - exec(action, args) { - var cmd; - cmd = { - path: `${this.path()}/api.lua`, - parameters: { - action: action, - docpath: this.setting.docpath, - args: args - } - }; - return this.call(cmd); - } - - initdb() { - if (!this.setting.docpath) { - return this.error(__("No configured docpath")); - } - // fetch the categories from the database - return this.exec("init").then((d) => { - if (d.error) { - return this.error(d.error); - } - this.notify(d.result); - // load categories - return this.cat_refresh(); - }).catch((e) => { - return this.error(__("Unable to init database: {0}", e.toString())); - }); - } - - menu() { - return [ - { - text: "__(View)", - nodes: [ - { - text: "__(Owners)", - id: "owners", - shortcut: "A-O" - }, - { - text: "__(Preview)", - id: "preview", - shortcut: "A-P" - } - ], - onchildselect: (e) => { - return this.fileMenuHandle(e.data.item.data.id); - } - } - ]; - } - - fileMenuHandle(id) { - switch (id) { - case "owners": - return this.openDialog(new OwnerDialog(), { - title: __("Owners") - }); - case "preview": - return this.openDialog(new FilePreviewDialog()); - } - } - - }; - - this.OS.register("Docify", Docify); - -}).call(this); +(function(){var t,i,a,r;(r=class t extends this.OS.GUI.BasicDialog{constructor(){super("OwnerDialog",t.scheme)}main(){return super.main(),this.oview=this.find("ownview"),this.oview.buttons=[{text:"",iconclass:"fa fa-plus-circle",onbtclick:t=>this.openDialog("PromptDialog",{title:__("Owner"),label:__("Name")}).then(t=>this.parent.exec("insert",{table:"owners",data:{name:t}}).then(t=>t.error?this.error(t.error):this.owner_refresh()).catch(t=>this.error(__("Unable to insert owner: {0}",t.toString()),t))).catch(t=>this.error(t.toString(),t))},{text:"",iconclass:"fa fa-minus-circle",onbtclick:t=>{var e;if(e=this.oview.selectedItem)return this.ask({text:__("Do you realy want to delete: `{0}`",e.data.text)}).then(t=>{if(t)return this.parent.exec("delete",{table:"owners",id:parseInt(e.data.id)}).then(t=>t.error?this.error(t.error):this.owner_refresh()).catch(t=>this.error(__("Unable delete category: {0}",t.toString()),t))})}},{text:"",iconclass:"fa fa-pencil-square-o",onbtclick:t=>{var e;if(e=this.oview.selectedItem)return this.openDialog("PromptDialog",{title:__("Owner"),label:__("Name"),value:e.data.name}).then(t=>this.parent.exec("update",{table:"owners",data:{id:parseInt(e.data.id),name:t}}).then(t=>t.error?this.error(t.error):this.owner_refresh()).catch(t=>this.error(__("Unable to update owner: {0}",t.toString()),t))).catch(t=>this.error(t.toString()))}}],this.owner_refresh()}owner_refresh(){return this.parent.exec("fetch","owners").then(t=>{var e,i,a,r;for(e=0,i=(a=t.result).length;ethis.error(__("Unable to fetch owners: {0}",t.toString()),e))}}).scheme="\n \n \n \n",(t=class t extends this.OS.GUI.BasicDialog{constructor(){super("DocDialog",t.scheme)}main(){var t,e,i,r,s,n,h,o;for(super.main(),this.flist=this.find("file-list"),this.dlist=this.find("dlist"),this.mlist=this.find("mlist"),this.ylist=this.find("ylist"),this.olist=this.find("olist"),this.setting=this.parent.setting,this.exec=this.parent.exec,this.preview=this.parent.preview,this.exec("fetch","owners").then(t=>{var e,i,a,r,s,n,h;if(t.error)return this.error(t.error);for(e=0,a=(s=t.result).length;ethis.error(__("Unable to fetch owner list: {0}",t.toString()),t)),this.dlist.push({text:"None",value:0}),h=0,t=i=1;i<=31;t=++i)this.dlist.push({text:""+t,value:t}),this.data&&parseInt(this.data.day)===t&&(h=t);for(this.dlist.selected=h,this.mlist.push({text:"None",value:0}),h=0,t=r=1;r<=12;t=++r)this.mlist.push({text:""+t,value:t}),this.data&&parseInt(this.data.month)===t&&(h=t);for(this.mlist.selected=h,this.ylist.push({text:"None",value:0}),this.ylist.selected=0,o=s=1980,n=(new Date).getFullYear();1980<=n?s<=n:s>=n;o=1980<=n?++s:--s)this.ylist.push({text:""+o,value:o,selected:this.data&&parseInt(this.data.year)===o});if(this.flist.buttons=[{text:"",iconclass:"fa fa-plus-circle",onbtclick:t=>this.openDialog(new a).then(t=>(t.text=t.filename,this.flist.push(t)))},{text:"",iconclass:"fa fa-minus-circle",onbtclick:t=>{var e;if(e=this.flist.selectedItem)return this.flist.delete(e)}}],this.flist.onlistselect=t=>this.parent.preview(t.data.item.data.path,this.find("preview-canvas")),this.find("btsave").onbtclick=t=>{var e,i;return(e={name:this.find("title").value.trim(),day:this.dlist.selectedItem.data.value,month:this.mlist.selectedItem.data.value,year:this.ylist.selectedItem.data.value,file:function(){var t,e,a,r;for(r=[],t=0,e=(a=this.flist.data).length;t0?(this.handle&&this.handle(e),this.quit()):this.notify(__("Please attach files to the entry")):this.notify(__("Please enter title"))},this.data)return this.find("title").value=this.data.name,this.find("note").value=this.data.note,this.find("tag").value=this.data.tags,(e=this.data.file.asFileHandle()).text=e.filename,this.flist.data=[e]}}).scheme='\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n
\n
\n \n
\n
\n
\n
',(a=class t extends this.OS.GUI.BasicDialog{constructor(){super("FilePreviewDialog",t.scheme)}main(){return super.main(),this.flist=this.find("file-list"),this.flist.buttons=[{text:"",iconclass:"fa fa-refresh",onbtclick:t=>this.refresh()}],this.flist.onlistselect=t=>this.parent.preview(t.data.item.data.path,this.find("preview-canvas")),this.find("btok").onbtclick=t=>{var e;return(e=this.flist.selectedItem)?(this.handle&&this.handle(e.data),this.quit()):this.quit()},this.refresh()}refresh(){return(this.parent.setting.docpath+"/unclassified").asFileHandle().read().then(t=>{var e,i,a,r;if(t.error)return this.error(t.error);for(e=0,i=(a=t.result).length;ethis.error(__("Unable to fetch unclassified file list: {0}",t.toString()),t))}}).scheme='\n \n \n \n \n \n \n
\n \n
\n
\n \n
\n \n
\n
\n
',i=class extends this.OS.application.BaseApplication{constructor(t){super("Docify",t)}main(){return this.catview=this.find("catview"),this.docview=this.find("docview"),this.docpreview=this.find("preview-canvas"),this.docgrid=this.find("docgrid"),this.docgrid.header=[{text:"",width:100},{text:""}],this.find("btdld").onbtclick=t=>{var e;if(e=this.docview.selectedItem)return e.data.file.asFileHandle().download().catch(t=>this.error(__("Unable to download: {}",t.toString()),t))},this.find("btopen").onbtclick=t=>{var e;if(e=this.docview.selectedItem)return e.data.file.asFileHandle().meta().then(t=>t.error?this.error(t.error):this._gui.openWith(t.result)).catch(t=>this.error(t.toString(),t))},this.catview.buttons=[{text:"",iconclass:"fa fa-plus-circle",onbtclick:t=>this.openDialog("PromptDialog",{title:__("Category"),label:__("Name")}).then(t=>this.exec("insert",{table:"categories",data:{name:t}}).then(t=>t.error?this.error(t.error):this.cat_refresh()).catch(t=>this.error(__("Unable to insert category: {0}",t.toString()),t))).catch(t=>this.error(t.toString(),t))},{text:"",iconclass:"fa fa-minus-circle",onbtclick:t=>{var e;if(e=this.catview.selectedItem)return this.ask({text:__("Do you realy want to delete: `{0}`",e.data.text)}).then(t=>{if(t)return this.exec("delete",{table:"categories",id:parseInt(e.data.id)}).then(t=>t.error?this.error(t.error):this.cat_refresh()).catch(t=>this.error(__("Unable delete category: {0}",t.toString()),t))})}},{text:"",iconclass:"fa fa-pencil-square-o",onbtclick:t=>{var e;if(e=this.catview.selectedItem)return this.openDialog("PromptDialog",{title:__("Category"),label:__("Name"),value:e.data.name}).then(t=>this.exec("update",{table:"categories",data:{id:parseInt(e.data.id),name:t}}).then(t=>t.error?this.error(t.error):this.cat_refresh()).catch(t=>this.error(__("Unable to update category: {0}",t.toString()),t))).catch(t=>this.error(t.toString(),t))}}],this.docview.onlistselect=t=>{var e;if(this.clear_preview(),e=t.data.item)return this.exec("get_doc",e.data.id).then(t=>{var e,i,a,r,s,n;if(t.error)return this.error(t.error);for(i in this.preview(t.result.file,this.docpreview),s=[],a={ctime:"Created on",mtime:"Modified on",note:"Note",tags:"Tags",name:"Title",owner:"Owner",edate:"Effective date",file:"File"},t.result.edate=`${t.result.day}/${t.result.month}/${t.result.year}`,r=t.result)n=r[i],(e=a[i])&&s.push([{text:e},{text:n}]);return this.docgrid.rows=s}).catch(t=>this.error(t.toString(),t))},this.catview.onlistselect=t=>{var e;if(this.clear_preview(),e=t.data.item)return this.update_doclist(e.data.id)},this.find("bt-add-doc").onbtclick=e=>{var i;return(i=this.catview.selectedItem)?this.openDialog(new t).then(t=>(t.cid=parseInt(i.data.id),this.exec("insertdoc",t).then(t=>t.error?this.error(t.error):(t.result&&this.notify(t.result),this.update_doclist(i.data.id),this.clear_preview())).catch(t=>this.error(t.toString(),t)))):this.notify(__("Please select a category"))},this.find("bt-del-doc").onbtclick=t=>{var e;if(e=this.docview.selectedItem)return this.ask({text:__("Do you really want to delete: `{0}`",e.data.name)}).then(t=>{if(t)return this.exec("deletedoc",{id:e.data.id,file:e.data.file}).then(t=>t.error?this.error(t.error):(this.notify(t.result),this.update_doclist(e.data.cid),this.clear_preview())).catch(t=>this.error(t.toString(),t))})},this.find("bt-edit-doc").onbtclick=e=>{var i,a;if(a=this.docview.selectedItem,i=this.catview.selectedItem,a)return this.openDialog(new t,a.data).then(t=>(t.cid=parseInt(i.data.id),t.id=a.data.id,this.exec("updatedoc",{data:t,rm:!t.file.includes(a.data.file)&&a.data.file}).then(t=>t.error?this.error(t.error):(t.result&&this.notify(t.result),this.update_doclist(i.data.id),this.clear_preview())).catch(t=>this.error(t.toString(),t))))},this.initialize()}update_doclist(t){return this.exec("select",{table:"docs",cond:"cid = "+t}).then(t=>{var e,i,a,r;if(t.error)return this.error(t.error);for(e=0,i=(a=t.result).length;ethis.error(t.toString(),t))}clear_preview(){return this.docpreview.getContext("2d").clearRect(0,0,this.docpreview.width,this.docpreview.height),this.docgrid.rows=[]}preview(t,e){return this.exec("preview",t).then(t=>{var i;return t.error?this.error(t.error):(i=t.result.asFileHandle()).read("binary").then(t=>{var a,r;return(r=new Image).onload=()=>{var t;return t=e.getContext("2d"),e.height=r.height,e.width=r.width,t.drawImage(r,0,0)},a=new Blob([t],{type:i.info.mime}),r.src=URL.createObjectURL(a)}).catch(t=>this.error(t.toString(),t))}).catch(t=>this.error(t.toString(),t))}cat_refresh(){return this.exec("fetch","categories").then(t=>{var e,i,a,r;for(e=0,i=(a=t.result).length;ethis.error(__("Unable to fetch categories: {0}",t.toString()),t))}initialize(){return this.setting.docpath?this.initdb():this.openDialog("FileDialog",{title:__("Please select a doc path"),mimes:["dir"]}).then(t=>(this.setting.docpath=t.file.path,this._api.setting(),this.initdb())).catch(t=>this.error(t.toString(),t))}exec(t,e){var i;return i={path:this.path()+"/api.lua",parameters:{action:t,docpath:this.setting.docpath,args:e}},this.call(i)}initdb(){return this.setting.docpath?this.exec("init").then(t=>t.error?this.error(t.error):(this.notify(t.result),this.cat_refresh())).catch(t=>this.error(__("Unable to init database: {0}",t.toString()),t)):this.error(__("No configured docpath"))}menu(){return[{text:"__(View)",nodes:[{text:"__(Owners)",id:"owners",shortcut:"A-O"},{text:"__(Preview)",id:"preview",shortcut:"A-P"}],onchildselect:t=>this.fileMenuHandle(t.data.item.data.id)}]}fileMenuHandle(t){switch(t){case"owners":return this.openDialog(new r,{title:__("Owners")});case"preview":return this.openDialog(new a).then(t=>this.notify(t.path))}}},this.OS.register("Docify",i)}).call(this); \ No newline at end of file diff --git a/Docify/build/debug/scheme.html b/Docify/build/debug/scheme.html index 840e102..df9e332 100644 --- a/Docify/build/debug/scheme.html +++ b/Docify/build/debug/scheme.html @@ -1,4 +1,4 @@ - +
@@ -8,15 +8,26 @@ - + +
- - + +
- + +
+ +
+ +
+ + + +
+
\ No newline at end of file diff --git a/Docify/build/release/Docify.zip b/Docify/build/release/Docify.zip new file mode 100644 index 0000000000000000000000000000000000000000..5d457112b18226e34166a5a479eff3b74dec7bf6 GIT binary patch literal 28503 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gR}A&1LZBpr(IR5Bi71@s^qco7_?l{ExAk4ZQQ@i(mf@dh#3i-yh>r|9?;D G+y4TCjmCli literal 0 HcmV?d00001 diff --git a/Docify/coffees/dialogs.coffee b/Docify/coffees/dialogs.coffee index 82bdd80..f5f8842 100644 --- a/Docify/coffees/dialogs.coffee +++ b/Docify/coffees/dialogs.coffee @@ -74,47 +74,147 @@ class DocDialog extends this.OS.GUI.BasicDialog 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: "", iconclass: "fa fa-plus-circle", onbtclick: (e) => + @openDialog(new FilePreviewDialog()) + .then (d) => + d.text = d.filename + @flist.push d }, { text: "", iconclass: "fa fa-minus-circle", 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 = """ - + - + - + - + - + - + - + + + - + -
- +
+ +
+
+ +
@@ -127,34 +227,49 @@ class FilePreviewDialog extends this.OS.GUI.BasicDialog main: () -> super.main() @flist = @find("file-list") + @flist.buttons = [ + { + text: "", + iconclass: "fa fa-refresh", + onbtclick: (e) => @refresh() + } + ] + @flist.onlistselect = (e) => # console.log e.data.item.data - @parent.exec("preview", e.data.item.data.path) - .then (d) => - console.log d - .catch (e) => - @error e.toString(), e + @parent.preview(e.data.item.data.path, @find("preview-canvas")) + @find("btok").onbtclick = (e) => + item = @flist.selectedItem + return @quit() unless item + @handle(item.data) if @handle + @quit() + @refresh() refresh: () -> "#{@parent.setting.docpath}/unclassified".asFileHandle().read() .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 @flist.data = d.result .catch (e) => @error __("Unable to fetch unclassified file list: {0}", e.toString()), e FilePreviewDialog.scheme = """ - + - + -
- +
+ +
+
+ +
+
diff --git a/Docify/coffees/main.coffee b/Docify/coffees/main.coffee index 35ac037..42a061e 100644 --- a/Docify/coffees/main.coffee +++ b/Docify/coffees/main.coffee @@ -5,6 +5,27 @@ class Docify extends this.OS.application.BaseApplication main: () -> @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 = [ { text: "", @@ -16,8 +37,8 @@ class Docify extends this.OS.application.BaseApplication .then (r) => return @error r.error if r.error @cat_refresh() - .catch (e) => @error __("Unable to insert category: {0}", e.toString()) - .catch (e) => @error e.toString() + .catch (e) => @error __("Unable to insert category: {0}", e.toString()), e + .catch (e) => @error e.toString(), e }, { text: "", @@ -33,7 +54,7 @@ class Docify extends this.OS.application.BaseApplication return @error d.error if d.error @cat_refresh() .catch (e) => - @error __("Unable delete category: {0}", e.toString()) + @error __("Unable delete category: {0}", e.toString()), e }, { text: "", @@ -47,22 +68,136 @@ class Docify extends this.OS.application.BaseApplication .then (r) => return @error r.error if r.error @cat_refresh() - .catch (e) => @error __("Unable to update category: {0}", e.toString()) - .catch (e) => @error e.toString() + .catch (e) => @error __("Unable to update category: {0}", e.toString()), e + .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) => - @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() + 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: () -> @exec("fetch", "categories") .then (d) => v.text = v.name for v in 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: () -> # Check if we have configured docpath @@ -97,7 +232,7 @@ class Docify extends this.OS.application.BaseApplication # load categories @cat_refresh() .catch (e) => - @error __("Unable to init database: {0}", e.toString()) + @error __("Unable to init database: {0}", e.toString()), e menu: () -> [ @@ -116,6 +251,8 @@ class Docify extends this.OS.application.BaseApplication when "owners" @openDialog new OwnerDialog(), { title: __("Owners")} when "preview" - @openDialog new FilePreviewDialog() + @openDialog(new FilePreviewDialog()) + .then (d) => + @notify d.path this.OS.register "Docify", Docify \ No newline at end of file diff --git a/Docify/css/main.css b/Docify/css/main.css index 2ccf8f6..b828c05 100644 --- a/Docify/css/main.css +++ b/Docify/css/main.css @@ -1,4 +1,15 @@ afx-app-window[data-id = "Docify"] .header .label-text { font-weight: bold; +} +div[data-id = "preview-container"] +{ + overflow: auto; + display: block; +} + +canvas[data-id = "preview-canvas"] +{ + display: block; + margin:0 auto; } \ No newline at end of file diff --git a/packages.json b/packages.json index 3328379..100f5a9 100644 --- a/packages.json +++ b/packages.json @@ -71,6 +71,15 @@ "version": "0.0.2-a", "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", "name": "Graph Editor",