LP1830391 Ang print service emits on job queued user/berick/lp1830391-hatch-omnibus-java-workstations-files-5-tmp
authorBill Erickson <berickxx@gmail.com>
Wed, 30 Oct 2019 16:09:38 +0000 (12:09 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 30 Oct 2019 16:10:38 +0000 (12:10 -0400)
Emit an event when a print job has either been delivered to Hatch or
window.print() has returned.  This gives the caller a better idea of
the completeness of a print job.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/print/print.component.ts
Open-ILS/src/eg2/src/app/share/print/print.service.ts

index 6af06bd..644f653 100644 (file)
@@ -79,7 +79,10 @@ export class PrintComponent implements OnInit {
         this.applyTemplate(printReq).then(() => {
             // Give templates a chance to render before printing
             setTimeout(() => {
-                this.dispatchPrint(printReq).then(_ => this.reset());
+                this.dispatchPrint(printReq).then(_ => {
+                    this.reset();
+                    this.printer.printJobQueued$.emit(printReq);
+                });
             });
         });
     }
@@ -191,7 +194,7 @@ export class PrintComponent implements OnInit {
 
         return this.checkHatchEnabled().then(enabled => {
             if (enabled) {
-                this.printViaHatch(printReq);
+                return this.printViaHatch(printReq);
             } else {
                 // Here the needed HTML is already in the page.
                 window.print();
@@ -199,7 +202,7 @@ export class PrintComponent implements OnInit {
         });
     }
 
-    printViaHatch(printReq: PrintRequest) {
+    printViaHatch(printReq: PrintRequest): Promise<any> {
         if (!printReq.contentType) {
             printReq.contentType = 'text/html';
         }
@@ -210,7 +213,8 @@ export class PrintComponent implements OnInit {
             html = `<html><body>${printReq.text}</body></html>`;
         }
 
-        this.serverStore.getItem(`eg.print.config.${printReq.printContext}`)
+        return this.serverStore.getItem(
+            `eg.print.config.${printReq.printContext}`)
         .then(config => {
 
             let msg: HatchMessage;
@@ -238,7 +242,7 @@ export class PrintComponent implements OnInit {
                 });
             }
 
-            this.hatch.sendRequest(msg).then(
+            return this.hatch.sendRequest(msg).then(
                 ok  => console.debug('Print request succeeded'),
                 err => console.warn('Print request failed', err)
             );
index 25ef206..5723a4c 100644 (file)
@@ -31,12 +31,18 @@ export class PrintService {
 
     onPrintRequest$: EventEmitter<PrintRequest>;
 
+    // Emitted after a print request has been delivered to Hatch or
+    // window.print() has completed.  Note window.print() returning
+    // is not necessarily an indication the job has completed.
+    printJobQueued$: EventEmitter<PrintRequest>;
+
     constructor(
         private locale: LocaleService,
         private auth: AuthService,
         private store: StoreService
     ) {
         this.onPrintRequest$ = new EventEmitter<PrintRequest>();
+        this.printJobQueued$ = new EventEmitter<PrintRequest>();
     }
 
     print(printReq: PrintRequest) {