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

@ -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 = """
<afx-app-window width='500' height='300'>
<afx-app-window width='600' height='400'>
<afx-hbox>
<afx-vbox data-width="300">
<afx-vbox data-width="350">
<afx-hbox data-height="22">
<afx-label text = "__(title)" data-width="50"></afx-label>
<input type="text"></input>
<input type="text" data-id="title"></input>
</afx-hbox>
<afx-hbox data-height="22">
<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-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-list-view dropdown="true"></afx-list-view>
<afx-list-view dropdown="true" data-id="ylist"></afx-list-view>
</afx-hbox>
<afx-label text = "__(Files)" data-height="22"></afx-label>
<afx-list-view data-id="file-list"></afx-list-view>
<afx-label text = "__(Note)" data-height="22"></afx-label>
<textarea></textarea>
<textarea data-id="note"></textarea>
<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>
<input type="text"></input>
<input type="text" data-id="tag"></input>
</afx-hbox>
</afx-vbox>
<afx-vbox>
<div></div>
<afx-button text="__(Save)" iconclass="" data-height="30" ></afx-button>
<div data-id = "preview-container">
<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-hbox>
</afx-app-window>
@ -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 = """
<afx-app-window width='500' height='300'>
<afx-app-window width='400' height='400' apptitle = "__(Document preview)">
<afx-hbox>
<afx-vbox data-width="200">
<afx-vbox data-width="150">
<afx-label text = "__(Files)" data-height="22"></afx-label>
<afx-list-view data-id="file-list"></afx-list-view>
</afx-vbox>
<afx-vbox>
<div></div>
<afx-button text="__(Ok)" iconclass="" data-height="30" ></afx-button>
<div data-id = "preview-container">
<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-hbox>
</afx-app-window>

View File

@ -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