From 9fece9b8ab9a1c3173a77aea44610c87ba87beaf Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 18 Feb 2022 16:48:06 -0500 Subject: [PATCH] LP1965326 Printer Settings Angular Port Ports the Admin -> Workstation Admin -> Printer Settings interface to Angular. Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/app/core/hatch.service.ts | 51 ++++ .../workstation/printers/printers.component.html | 306 +++++++++++++++++++++ .../workstation/printers/printers.component.ts | 210 ++++++++++++++ .../admin/workstation/printers/printers.module.ts | 18 ++ .../admin/workstation/printers/routing.module.ts | 17 ++ .../app/staff/admin/workstation/routing.module.ts | 10 +- .../templates/staff/admin/workstation/t_splash.tt2 | 2 +- 7 files changed, 610 insertions(+), 4 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.component.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.module.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/routing.module.ts diff --git a/Open-ILS/src/eg2/src/app/core/hatch.service.ts b/Open-ILS/src/eg2/src/app/core/hatch.service.ts index 45ba5f4cd7..eecf098655 100644 --- a/Open-ILS/src/eg2/src/app/core/hatch.service.ts +++ b/Open-ILS/src/eg2/src/app/core/hatch.service.ts @@ -1,5 +1,23 @@ import {Injectable, EventEmitter} from '@angular/core'; +export type PrintContext = 'default' | 'receipt' | 'label' | 'mail' | 'offline'; + +export const PRINT_CONTEXTS: PrintContext[] = [ + 'default', + 'receipt', + 'label', + 'mail', + 'offline' +]; + +export interface PrintConfig { + context: PrintContext; + printer: string; + autoMargins: boolean; + allPages: boolean; + pageRanges: number[]; +} + export class HatchMessage { msgid: number; resolver: (HatchMessage) => void; // promise resolver @@ -28,6 +46,7 @@ export class HatchService { isAvailable: boolean; msgId: number; messages: {[msgid: number]: HatchMessage}; + printers: any[]; constructor() { this.isAvailable = null; @@ -129,5 +148,37 @@ export class HatchService { const msg = new HatchMessage({action: 'remove', key: key}); return this.sendRequest(msg).then((m: HatchMessage) => m.response); } + + getPrinterOptions(name: string): Promise { + if (name === 'hatch_file_writer' || name === 'hatch_browser_printing') { + return Promise.resolve({}); + } + const msg = new HatchMessage({action: 'printer-options', printer: name}); + return this.sendRequest(msg).then((m: HatchMessage) => m.response); + } + + getPrinters(): Promise { + if (this.printers) { return Promise.resolve(this.printers); } + + this.printers = [ + {name: 'hatch_file_writer'}, + {name: 'hatch_browser_printing'} + ]; + + const msg = new HatchMessage({action: 'printers'}); + return this.sendRequest(msg).then((m: HatchMessage) => m.response) + .then( + printers => { + this.printers = + printers.sort((p1, p2) => p1.name < p2.name ? -1 : 1) + .concat(this.printers); + + return this.printers; + }, + err => { + return this.printers; + } + ); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.component.html b/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.component.html new file mode 100644 index 0000000000..bd70efbee7 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.component.html @@ -0,0 +1,306 @@ + + + + + + + +
+ +
+
Default: {{printerOptions[defAttr]}}
+
+ +
+ +
+ Hatch printing is not enabled on this browser. The settings below will + have no effect until Hatch printing is enabled. +
+ + + +
+ + + +
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+ + + +
+
+ +
+ +
+
+
+ Hatch File Writer translates print output to plain text + and writes the content to a text file in the Hatch profile directory. + No additional settings are required. +
+
+ Hatch Browser Printing sends print requests directly + to the browser, bypassing the external Hatch print mechanism. No + additional settings are required. +
+
+
+ +
+
+ +
+
Print Color
+ + +
+ +
+
Paper Source
+ + +
+ +
+
Paper
+ + +
+ +
+
Page Orientation
+ + +
+ +
+
Collation
+ + +
+ +
+
Print Quality
+ + +
+ +
+
Print Sides
+ + +
+ +
+
Number of Items
+
+ +
+
Default: {{printerOptions.defaultCopies}}
+
+ +
+
+ +
+
Automatic Margins
+
+ +
+
Default: {{printerOptions.defaultMarginType}}
+
+ +
+
+ +
+
Manual Margins
+
+
+
+
+
+ Left +
+ +
+
+
+
+
+ Top +
+ +
+
+
+
+
+
+
+ Right +
+ +
+
+
+
+
+ Bottom +
+ +
+
+
+
+
+ +
+
Page Ranges
+
+
+
+ + +
+
+ + +
+
+
+
+
+
+ Start +
+ +
+
+
+
+
+ End +
+ +
+
+
+
+
+ +
+
+ +
+
+

Compiled Printer Settings

+
{{printConfigs[context] | json}}
+
+
+
+ + + +
+
+
+
+ +
+
+ +
+
+
+ + + +
+ +
+ +
+ + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.component.ts new file mode 100644 index 0000000000..25663dc23b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.component.ts @@ -0,0 +1,210 @@ +import {Component, OnInit, ViewChild} from '@angular/core'; +import {Router, ActivatedRoute} from '@angular/router'; +import {from} from 'rxjs'; +import {concatMap} from 'rxjs/operators'; +import {ServerStoreService} from '@eg/core/server-store.service'; +import {IdlObject} from '@eg/core/idl.service'; +import {NetService} from '@eg/core/net.service'; +import {PermService} from '@eg/core/perm.service'; +import {AuthService} from '@eg/core/auth.service'; +import {OrgService} from '@eg/core/org.service'; +import {EventService} from '@eg/core/event.service'; +import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; +import {HatchService, PrintContext, PrintConfig, PRINT_CONTEXTS} from '@eg/core/hatch.service'; +import {PrintService, PrintRequest} from '@eg/share/print/print.service'; +import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap'; +import {StringComponent} from '@eg/share/string/string.component'; + +@Component({ + templateUrl: 'printers.component.html' +}) +export class PrintersComponent implements OnInit { + + printers: any[]; + printerName: string; + context: PrintContext = 'default'; + showTestView = false; + printConfigs: {[ctx: string]: PrintConfig} = {}; + printerOptions: any = {}; + useHatchPrinting = false; + testTab = 'text'; + + marginLeft: number; + marginRight: number; + marginTop: number; + marginBottom: number; + + textPrintContent = ''; + htmlPrintContent = ''; + + testText = `1234567890 + +12345678901234567890 + +123456789012345678901234567890 + +1234567890123456789012345678901234567890 + +12345678901234567890123456789012345678901234567890 + +12345678901234567890123456789012345678901234567890123456790`; + + testHtml = `
+ +

Test HTML Print

+
+

More Content

+
+
`; + + + @ViewChild('fileWriter') private fileWriter: StringComponent; + @ViewChild('browserPrinting') private browserPrinting: StringComponent; + + constructor( + private router: Router, + private route: ActivatedRoute, + private evt: EventService, + private net: NetService, + private serverStore: ServerStoreService, + private auth: AuthService, + private org: OrgService, + private hatch: HatchService, + private printer: PrintService, + private perm: PermService + ) {} + + ngOnInit() { + + this.serverStore.getItem('eg.hatch.enable.printing') + .then(use => this.useHatchPrinting = use); + + this.hatch.getPrinters() + .then(printers => { + + this.printers = printers; + + return from(PRINT_CONTEXTS).pipe(concatMap(ctx => { + return from( + this.getPrintConfig(ctx).then(conf => { + if (conf) { + this.printConfigs[ctx] = conf; + } else { + this.resetConfig(ctx); + } + }) + ); + })).toPromise(); + }) + .then(_ => this.setContext('default')); + } + + getPrinterLabel(name: string): string { + switch (name) { + case 'hatch_file_writer': + return this.fileWriter ? this.fileWriter.text : ''; + case 'hatch_browser_printing': + return this.browserPrinting ? this.browserPrinting.text : ''; + default: + if (this.printers) { + const p = this.printers.filter(p2 => p2.name === name)[0]; + return p ? p.name : ''; + } else { + return ''; + } + } + } + + virtualPrinter(): boolean { + const conf = this.printConfigs[this.context]; + return conf && ( + conf.printer === 'hatch_file_writer' || + conf.printer === 'hatch_browser_printing' + ); + } + + setContext(c: PrintContext) { + this.context = c; + this.showTestView = false; + + const conf = this.printConfigs[c as string]; + if (conf) { this.setPrinter(conf.printer); } + } + + getPrinterOptions(name: string): Promise { + return this.hatch.getPrinterOptions(name).then(ops => { + this.printerOptions = ops; + }); + } + + resetConfig(c: PrintContext) { + this.printConfigs[c] = { + context: 'default', + printer: '', + autoMargins: true, + allPages: true, + pageRanges: [] + }; + } + + saveConfig(context: PrintContext): Promise { + return this.setPrintConfig(context, this.printConfigs[context]); + } + + setPrinter(name: string, reset?: boolean): Promise { + if (reset) { this.resetConfig(this.context); } + + this.printerName = name; + this.printConfigs[this.context].printer = name; + + return this.getPrinterOptions(name); + } + + testPrint(withDialog: boolean) { + const req: PrintRequest = { + printContext: this.context, + showDialog: withDialog, + contentType: this.testTab === 'text' ? 'text/plain' : 'text/html', + text: this.testTab === 'text' ? this.testText : this.testHtml + }; + + this.printer.print(req); + } + + useFileWriter(): boolean { + return ( + this.printConfigs[this.context] && + this.printConfigs[this.context].printer === 'hatch_file_writer' + ); + } + + useBrowserPrinting(): boolean { + return ( + this.printConfigs[this.context] && + this.printConfigs[this.context].printer === 'hatch_browser_printing' + ); + } + + beforeTabChange(evt: NgbNavChangeEvent) { + if (evt.nextId === 'test') { + this.showTestView = true; + } else { + this.showTestView = false; + this.setContext(evt.nextId as PrintContext); + } + } + + beforeTestTabChange(evt: NgbNavChangeEvent) { + this.testTab = evt.nextId; + } + + setPrintConfig(context: PrintContext, config: PrintConfig): Promise { + return this.serverStore.setItem('eg.print.config.' + context, config); + } + + getPrintConfig(context: PrintContext): Promise { + return this.serverStore.getItem(`eg.print.config.${context}`); + } +} + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.module.ts new file mode 100644 index 0000000000..0afe68c1f7 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/printers.module.ts @@ -0,0 +1,18 @@ +import {NgModule} from '@angular/core'; +import {StaffCommonModule} from '@eg/staff/common.module'; +import {PrintersRoutingModule} from './routing.module'; +import {PrintersComponent} from './printers.component'; + +@NgModule({ + declarations: [ + PrintersComponent, + ], + imports: [ + StaffCommonModule, + PrintersRoutingModule + ] +}) + +export class ManagePrintersModule {} + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/routing.module.ts new file mode 100644 index 0000000000..ef48fbae5b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/workstation/printers/routing.module.ts @@ -0,0 +1,17 @@ +import {NgModule} from '@angular/core'; +import {RouterModule, Routes} from '@angular/router'; +import {PrintersComponent} from './printers.component'; + +const routes: Routes = [{ + path: '', + component: PrintersComponent +}]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) + +export class PrintersRoutingModule { +} + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/workstation/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/workstation/routing.module.ts index 6996a85080..e59b8bffa2 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/workstation/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/workstation/routing.module.ts @@ -2,9 +2,13 @@ import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; const routes: Routes = [{ - path: 'workstations', - loadChildren: () => - import('./workstations/workstations.module').then(m => m.ManageWorkstationsModule) + path: 'workstations', + loadChildren: () => + import('./workstations/workstations.module').then(m => m.ManageWorkstationsModule) +}, { + path: 'printers', + loadChildren: () => + import('./printers/printers.module').then(m => m.ManagePrintersModule) }]; @NgModule({ diff --git a/Open-ILS/src/templates/staff/admin/workstation/t_splash.tt2 b/Open-ILS/src/templates/staff/admin/workstation/t_splash.tt2 index 61a8d08fe8..0657f48eab 100644 --- a/Open-ILS/src/templates/staff/admin/workstation/t_splash.tt2 +++ b/Open-ILS/src/templates/staff/admin/workstation/t_splash.tt2 @@ -16,7 +16,7 @@
-- 2.11.0