From 1b08dbf0c0b6136c0876b3aca05c97d64b2e158a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 19 Apr 2019 17:06:23 -0400 Subject: [PATCH] server templates: ang and angjs cont. Signed-off-by: Bill Erickson --- .../src/eg2/src/app/share/print/print.component.ts | 59 ++++++++++++++++------ .../staff/admin/server/print-template.component.ts | 1 - .../eg2/src/app/staff/sandbox/sandbox.component.ts | 37 +++----------- .../eg2/src/app/staff/sandbox/sandbox.module.ts | 2 + .../js/ui/default/staff/admin/workstation/app.js | 2 +- 5 files changed, 54 insertions(+), 47 deletions(-) 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..de27bb8401 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 @@ -49,35 +49,59 @@ 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) { + + 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') { - // Wrap text/plain content in pre's to prevent - // unintended html formatting. + if (printReq.contentType === 'text/plain' && true /* this.hatch.isActive */) { + // When adding text output to DOM for rendering, wrap in + // pre to avoid unintended HTML formatting. printReq.text = `
${printReq.text}
`; } this.htmlContainer.innerHTML = printReq.text; - } + }); } // Clear the print data @@ -120,7 +144,10 @@ export class PrintComponent implements OnInit { 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({ diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts index 507bdbdc35..19c9bf0c4e 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts @@ -85,7 +85,6 @@ export class PrintTemplateComponent implements OnInit { } } - container(): any { // Only present when its tab is visible return document.getElementById('template-preview-pane'); diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index 8eb7f92989..abb0075e15 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -15,6 +15,7 @@ import {PrintService} from '@eg/share/print/print.service'; import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; import {FormatService} from '@eg/core/format.service'; import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; +import {SampleDataService} from '@eg/share/util/sample-data.service'; @Component({ templateUrl: 'sandbox.component.html' @@ -73,7 +74,8 @@ export class SandboxComponent implements OnInit { private strings: StringService, private toast: ToastService, private format: FormatService, - private printer: PrintService + private printer: PrintService, + private samples: SampleDataService ) { } @@ -227,40 +229,17 @@ export class SandboxComponent implements OnInit { testServerPrint() { // Note these values can be IDL objects or plain hashes. - const patron = this.idl.create('au'); - const address = this.idl.create('aua'); - patron.first_given_name('Crosby'); - patron.second_given_name('Stills'); - patron.family_name('Nash'); - address.street1('123 Pineapple Road'); - address.street2('Apt #4'); - address.city('Bahama'); - address.state('NC'); - address.post_code('555444'); - const templateData = { - patron: patron, - address: address + patron: this.samples.listOfThings('au')[0], + address: this.samples.listOfThings('aua')[0] } // NOTE: eventually this will be baked into the print service. - this.printer.compileRemoteTemplate({ - templateName: 'address-label', + this.printer.print({ + templateName: 'patron_address', contextData: templateData, printContext: 'default' - }).then( - response => { - console.log(response.contentType); - console.log(response.content); - this.printer.print({ - printContext: 'default', - contentType: response.contentType, - text: response.content, - showDialog: true - }); - } - ); + }); } } - diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.ts index 58910dddbb..d1ca609161 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.module.ts @@ -2,6 +2,7 @@ import {NgModule} from '@angular/core'; import {StaffCommonModule} from '@eg/staff/common.module'; import {SandboxRoutingModule} from './routing.module'; import {SandboxComponent} from './sandbox.component'; +import {SampleDataService} from '@eg/share/util/sample-data.service'; @NgModule({ declarations: [ @@ -12,6 +13,7 @@ import {SandboxComponent} from './sandbox.component'; SandboxRoutingModule, ], providers: [ + SampleDataService ] }) diff --git a/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js b/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js index d863844e3d..0364d2b0e6 100644 --- a/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js +++ b/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js @@ -616,7 +616,7 @@ function($scope , $q , egCore , ngToast) { $scope.template_changed = function() { $scope.print.load_failed = false; - egCore.print.getPrintTemplate($scope.print.template_name) + egCore.print.getPrintTemplate({template: $scope.print.template_name}) .then( function(html) { $scope.print.template_content = html; -- 2.11.0