X-Git-Url: https://git.evergreen-ils.org/?p=working%2FEvergreen.git;a=blobdiff_plain;f=Open-ILS%2Fsrc%2Feg2%2Fsrc%2Fapp%2Fshare%2Fprint%2Fprint.component.ts;h=ff1c3ed1f49feabbe804a96bd3263cac4c9782f6;hp=4f6994982bae929c882d7a8057a736bf9716af10;hb=d372c6c204fb3b835bfa8d97ee6f19622a1a6890;hpb=9e58a1d0ef04f5fe0b19daab2ee19bed889bf02b diff --git a/Open-ILS/src/eg2/src/app/share/print/print.component.ts b/Open-ILS/src/eg2/src/app/share/print/print.component.ts index 4f6994982b..ff1c3ed1f4 100644 --- a/Open-ILS/src/eg2/src/app/share/print/print.component.ts +++ b/Open-ILS/src/eg2/src/app/share/print/print.component.ts @@ -1,6 +1,8 @@ import {Component, OnInit, TemplateRef, ElementRef, Renderer2} from '@angular/core'; import {PrintService, PrintRequest} from './print.service'; import {StoreService} from '@eg/core/store.service'; +import {ServerStoreService} from '@eg/core/server-store.service'; +import {HatchService, HatchMessage} from './hatch.service'; @Component({ selector: 'eg-print', @@ -26,6 +28,8 @@ export class PrintComponent implements OnInit { private renderer: Renderer2, private elm: ElementRef, private store: StoreService, + private serverStore: ServerStoreService, + private hatch: HatchService, private printer: PrintService) { this.isPrinting = false; this.printQueue = []; @@ -49,35 +53,64 @@ export class PrintComponent implements OnInit { this.isPrinting = true; - this.applyTemplate(printReq); - - // Give templates a chance to render before printing - setTimeout(() => { - this.dispatchPrint(printReq); - this.reset(); + this.applyTemplate(printReq).then(() => { + // Give templates a chance to render before printing + setTimeout(() => { + this.dispatchPrint(printReq); + this.reset(); + }); }); } - applyTemplate(printReq: PrintRequest) { + applyTemplate(printReq: PrintRequest): Promise { if (printReq.template) { - // Inline template. Let Angular do the interpolationwork. + // Local Angular template. this.template = printReq.template; this.context = {$implicit: printReq.contextData}; - return; + return Promise.resolve(); + } + + let promise; + + // Precompiled text + if (printReq.text) { + promise = Promise.resolve(); + + } else if (printReq.templateName || printReq.templateId) { + // Server-compiled template + + promise = this.printer.compileRemoteTemplate(printReq).then( + response => { + printReq.text = response.content; + printReq.contentType = response.contentType; + }, + err => { + console.error('Error compiling template', printReq); + return Promise.reject(new Error( + 'Error compiling server-hosted print template')); + } + ); + + } else { + console.error('Cannot find template', printReq); + return Promise.reject(new Error('Cannot find print template')); } - if (printReq.text && true /* !this.hatch.isActive */) { - // Insert HTML into the browser DOM for in-browser printing only. + return promise.then(() => { - if (printReq.contentType === 'text/plain') { + // Insert HTML into the browser DOM for in-browser printing. + if (printReq.text && !this.useHatch()) { + + if (printReq.contentType === 'text/plain') { // Wrap text/plain content in pre's to prevent // unintended html formatting. - printReq.text = `
${printReq.text}
`; - } + printReq.text = `
${printReq.text}
`; + } - this.htmlContainer.innerHTML = printReq.text; - } + this.htmlContainer.innerHTML = printReq.text; + } + }); } // Clear the print data @@ -109,7 +142,7 @@ export class PrintComponent implements OnInit { show_dialog: printReq.showDialog }); - if (0 /* this.hatch.isActive */) { + if (this.useHatch()) { this.printViaHatch(printReq); } else { // Here the needed HTML is already in the page. @@ -117,17 +150,35 @@ export class PrintComponent implements OnInit { } } + useHatch(): boolean { + return this.store.getLocalItem('eg.hatch.enable.printing') + && this.hatch.connect(); + } + printViaHatch(printReq: PrintRequest) { // Send a full HTML document to Hatch - const html = `${printReq.text}`; + let html = printReq.text; + if (printReq.contentType === 'text/html') { + html = `${printReq.text}`; + } - /* - this.hatch.print({ - printContext: printReq.printContext, - content: html + this.serverStore.getItem(`eg.print.config.${printReq.printContext}`) + .then(config => { + + const msg = new HatchMessage({ + action: 'print', + content: html, + settings: config || {}, + contentType: 'text/html', + showDialog: printReq.showDialog + }); + + this.hatch.sendRequest(msg).then( + ok => console.debug('Print request succeeded'), + err => console.warn('Print request failed', err) + ); }); - */ } }