Enable printing in Docify

This commit is contained in:
Xuan Sang LE 2021-01-30 17:45:45 +00:00
parent 752b2a6f1d
commit b0c2e088f9
15 changed files with 155 additions and 9 deletions

View File

@ -2,6 +2,7 @@
Simple PDF document manager
## Change logs
- v0.0.6-a: Add print dialog (support server side printing)
- v0.0.5-a: Fix delete file bug
- v0.0.4-a: Display file size in entry meta-data
- v0.0.3-a: Fix document moved bug, sort entries by year, month, day

View File

@ -396,6 +396,33 @@ handle.delete = function(param)
end
end
handle.printdoc = function(opt)
local cmd = "lp "
if opt.printer and opt.printer ~= "" then
cmd = cmd .. " -d "..opt.printer
end
if opt.side == 0 then
cmd = cmd.. " -o sides=one-sided"
elseif opt.side == 1 then
cmd = cmd.. " -o sides=two-sided-long-edge"
elseif opt.side == 2 then
cmd = cmd .. " -o sides=two-sided-short-edge"
end
-- orientation landscape
if opt.orientation == 1 then
cmd = cmd.." -o orientation-requested=5"
end
if opt.range == 1 then
cmd = cmd.." -P "..opt.pages
end
cmd = cmd.. " "..vfs.ospath(opt.file)
print(cmd)
os.execute(cmd)
return result("A print job has been posted on server. Check if it successes")
end
if arg.action and handle[arg.action] then
-- check if the database exits

View File

@ -26,7 +26,7 @@
<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>
<afx-button text="__(Print on server)" data-id="btprint" ></afx-button>
</div>
</afx-vbox>
</afx-hbox>

View File

@ -2,6 +2,7 @@
Simple PDF document manager
## Change logs
- v0.0.6-a: Add print dialog (support server side printing)
- v0.0.5-a: Fix delete file bug
- v0.0.4-a: Display file size in entry meta-data
- v0.0.3-a: Fix document moved bug, sort entries by year, month, day

View File

@ -396,6 +396,33 @@ handle.delete = function(param)
end
end
handle.printdoc = function(opt)
local cmd = "lp "
if opt.printer and opt.printer ~= "" then
cmd = cmd .. " -d "..opt.printer
end
if opt.side == 0 then
cmd = cmd.. " -o sides=one-sided"
elseif opt.side == 1 then
cmd = cmd.. " -o sides=two-sided-long-edge"
elseif opt.side == 2 then
cmd = cmd .. " -o sides=two-sided-short-edge"
end
-- orientation landscape
if opt.orientation == 1 then
cmd = cmd.." -o orientation-requested=5"
end
if opt.range == 1 then
cmd = cmd.." -P "..opt.pages
end
cmd = cmd.. " "..vfs.ospath(opt.file)
print(cmd)
os.execute(cmd)
return result("A print job has been posted on server. Check if it successes")
end
if arg.action and handle[arg.action] then
-- check if the database exits

View File

@ -13,4 +13,13 @@ canvas[data-id = "preview-canvas"]
{
display: block;
margin:0 auto;
}
afx-app-window[data-id = "DocifyPrintDialog"] i.label-text {
font-weight: bold;
}
afx-app-window[data-id = "DocifyPrintDialog"] input[type="radio"] {
margin: 0;
height: 12px;
margin-left: 10px;
}

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@
"author": "",
"email": ""
},
"version":"0.0.5-a",
"version":"0.0.6-a",
"category":"Other",
"iconclass":"fa fa-adn",
"mimes":["none"],

View File

@ -26,7 +26,7 @@
<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>
<afx-button text="__(Print on server)" data-id="btprint" ></afx-button>
</div>
</afx-vbox>
</afx-hbox>

Binary file not shown.

View File

@ -125,7 +125,7 @@ class DocDialog extends this.OS.GUI.BasicDialog
value: 0
}
@ylist.selected = 0
for y in [1980..new Date().getFullYear()]
for y in [1960..new Date().getFullYear()]
@ylist.push {
text:"#{y}",
value: y,
@ -273,4 +273,57 @@ FilePreviewDialog.scheme = """
</afx-vbox>
</afx-hbox>
</afx-app-window>
"""
class PrintDialog extends this.OS.GUI.BasicDialog
constructor: () ->
super "PrintDialog", PrintDialog.scheme
main: () ->
super.main()
@find("printerName").value = @parent.setting.printer
@find("btnprint").onbtclick = (e) =>
data = {}
data.range = parseInt($('input[name=range]:checked', @scheme).val())
data.pages = @find("txtPageRange").value
data.printer = @find("printerName").value
data.orientation = parseInt($('input[name=orientation]:checked', @scheme).val())
data.side = parseInt($('input[name=side]:checked', @scheme).val())
@handle data if @handle
@quit()
PrintDialog.scheme = """
<afx-app-window width='300' height='300' data-id="DocifyPrintDialog" apptitle = "__(Print)">
<afx-vbox>
<afx-label text = "__(Printer name)" data-height="22"></afx-label>
<input type="text" data-id="printerName" data-height="25"/>
<afx-label text = "__(Range)" data-height="22"></afx-label>
<div>
<input type="radio" name="range" value="0" checked />
<label for="0">All</label><br>
<input type="radio" name="range" value="1" />
<label for="1">Pages: </label>
<input type="text" data-id="txtPageRange" />
</div>
<afx-label text = "__(Orientation)" data-height="22"></afx-label>
<div>
<input type="radio" name="orientation" value="0" checked />
<label for="0">Portrait</label><br>
<input type="radio" name="orientation" value="1" />
<label for="1">Landscape</label>
</div>
<afx-label text = "__(Side)" data-height="22"></afx-label>
<div>
<input type="radio" name="side" value="0" />
<label for="0">One side</label><br>
<input type="radio" name="side" value="1" checked />
<label for="1">Double side long edge</label><br>
<input type="radio" name="side" value="2" />
<label for="2">Double side short edge</label>
</div>
<div data-height="30" style="text-align:right;">
<afx-button text="__(Print)" style="margin-right:5px;" data-id="btnprint"></afx-button>
</div>
</afx-vbox>
</afx-app-window>
"""

View File

@ -4,6 +4,8 @@ class Docify extends this.OS.application.BaseApplication
main: () ->
@setting.printer = "" unless @setting.printer
@catview = @find "catview"
@docview = @find "docview"
@docpreview = @find "preview-canvas"
@ -26,6 +28,18 @@ class Docify extends this.OS.application.BaseApplication
return @error m.error if m.error
@_gui.openWith m.result
.catch (e) => @error e.toString(), e
@find("btprint").onbtclick = (e) =>
item = @docview.selectedItem
return unless item
@openDialog new PrintDialog(), {}
.then (d) =>
return unless d
d.file = item.data.file
@exec("printdoc", d)
.then (r) =>
return @error r.error if r.error
@notify r.result
.catch (e) => @error __("Unable to insert category: {0}", e.toString()), e
@catview.buttons = [
{
text: "",
@ -241,11 +255,12 @@ class Docify extends this.OS.application.BaseApplication
menu: () ->
[
{
text: "__(View)",
text: "__(Options)",
nodes: [
{ text: "__(Owners)", id:"owners"},
{ text: "__(Preview)", id:"preview"},
{ text: "__(Change doc path)", id:"setdocp"}
{ text: "__(Change doc path)", id:"setdocp"},
{ text: "__(Set default printer)", id:"setprinter"}
],
onchildselect: (e) => @fileMenuHandle e.data.item.data.id
}
@ -262,5 +277,9 @@ class Docify extends this.OS.application.BaseApplication
when "setdocp"
@setting.docpath = undefined
@initialize()
when "setprinter"
@openDialog "PromptDialog", {title: __("Default Printer"), label: __("Enter printer name")}
.then (n) =>
@setting.printer = n
this.OS.register "Docify", Docify

View File

@ -12,4 +12,13 @@ canvas[data-id = "preview-canvas"]
{
display: block;
margin:0 auto;
}
afx-app-window[data-id = "DocifyPrintDialog"] i.label-text {
font-weight: bold;
}
afx-app-window[data-id = "DocifyPrintDialog"] input[type="radio"] {
margin: 0;
height: 12px;
margin-left: 10px;
}

View File

@ -7,7 +7,7 @@
"author": "",
"email": ""
},
"version":"0.0.5-a",
"version":"0.0.6-a",
"category":"Other",
"iconclass":"fa fa-adn",
"mimes":["none"],

View File

@ -105,7 +105,7 @@
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Docify/README.md",
"category": "Other",
"author": "",
"version": "0.0.5-a",
"version": "0.0.6-a",
"dependencies": [],
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Docify/build/release/Docify.zip"
},