From 339b46280dbd1f51183c0954336f8284fce8873f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 1 Aug 2019 16:35:41 -0400 Subject: [PATCH] LP1825851 Print template failure warnings Display error toasts when an attempt is made to a server-generated print template and no active template can be found or the template generation failed. This required moving String and Toast components/services into the base module so they could be used by the print components/services. Signed-off-by: Bill Erickson Signed-off-by: Kyle Huckins Signed-off-by: Galen Charlton --- Open-ILS/src/eg2/src/app/common.module.ts | 13 ++++++++++- .../src/app/share/print/print.component.html | 10 ++++++++ .../src/app/share/print/print.component.ts | 23 ++++++++++++++++++- .../eg2/src/app/share/print/print.service.ts | 6 +++-- .../src/eg2/src/app/staff/common.module.ts | 12 +--------- 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/common.module.ts b/Open-ILS/src/eg2/src/app/common.module.ts index ead50f1e54..af1f2b0705 100644 --- a/Open-ILS/src/eg2/src/app/common.module.ts +++ b/Open-ILS/src/eg2/src/app/common.module.ts @@ -26,6 +26,11 @@ import {PromptDialogComponent} from '@eg/share/dialog/prompt.component'; import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component'; import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; import {BoolDisplayComponent} from '@eg/share/util/bool.component'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {ToastComponent} from '@eg/share/toast/toast.component'; +import {StringComponent} from '@eg/share/string/string.component'; +import {StringService} from '@eg/share/string/string.service'; + @NgModule({ declarations: [ @@ -36,6 +41,8 @@ import {BoolDisplayComponent} from '@eg/share/util/bool.component'; PromptDialogComponent, ProgressInlineComponent, ProgressDialogComponent, + ToastComponent, + StringComponent, BoolDisplayComponent ], imports: [ @@ -61,6 +68,8 @@ import {BoolDisplayComponent} from '@eg/share/util/bool.component'; ProgressInlineComponent, ProgressDialogComponent, BoolDisplayComponent, + ToastComponent, + StringComponent ] }) @@ -72,7 +81,9 @@ export class EgCommonModule { ngModule: EgCommonModule, providers: [ HatchService, - PrintService + PrintService, + StringService, + ToastService ] }; } diff --git a/Open-ILS/src/eg2/src/app/share/print/print.component.html b/Open-ILS/src/eg2/src/app/share/print/print.component.html index 12d05bcbcf..823b5d8c18 100644 --- a/Open-ILS/src/eg2/src/app/share/print/print.component.html +++ b/Open-ILS/src/eg2/src/app/share/print/print.component.html @@ -3,6 +3,16 @@ Global print container. There should only be one print component active in a page. --> + +No activate template found named "{{name}}" + + + + +Error generating print content for template name="{{name}}" / id="{{id}}" + + +
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 ff1c3ed1f4..20c056721d 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 @@ -3,6 +3,8 @@ 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'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {StringService} from '@eg/share/string/string.service'; @Component({ selector: 'eg-print', @@ -30,6 +32,8 @@ export class PrintComponent implements OnInit { private store: StoreService, private serverStore: ServerStoreService, private hatch: HatchService, + private toast: ToastService, + private strings: StringService, private printer: PrintService) { this.isPrinting = false; this.printQueue = []; @@ -86,7 +90,24 @@ export class PrintComponent implements OnInit { printReq.contentType = response.contentType; }, err => { - console.error('Error compiling template', printReq); + + if (err && err.notFound) { + + this.strings.interpolate( + 'eg.print.template.not_found', + {name: printReq.templateName} + ).then(msg => this.toast.danger(msg)); + + } else { + + console.error('Print generation failed', printReq); + + this.strings.interpolate( + 'eg.print.template.error', + {name: printReq.templateName, id: printReq.templateId} + ).then(msg => this.toast.danger(msg)); + } + return Promise.reject(new Error( 'Error compiling server-hosted print template')); } diff --git a/Open-ILS/src/eg2/src/app/share/print/print.service.ts b/Open-ILS/src/eg2/src/app/share/print/print.service.ts index abba31c331..25ef20606e 100644 --- a/Open-ILS/src/eg2/src/app/share/print/print.service.ts +++ b/Open-ILS/src/eg2/src/app/share/print/print.service.ts @@ -90,9 +90,11 @@ export class PrintService { content: xhttp.responseText, contentType: this.getResponseHeader('content-type') }); - } else { - reject('Error compiling print template'); + } else if (this.status === 404) { + console.error('No active template found: ', printReq); + reject({notFound: true}); } + reject({}); } }; xhttp.open('POST', PRINT_TEMPLATE_PATH, true); diff --git a/Open-ILS/src/eg2/src/app/staff/common.module.ts b/Open-ILS/src/eg2/src/app/staff/common.module.ts index 969ca379aa..12c0ff164c 100644 --- a/Open-ILS/src/eg2/src/app/staff/common.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/common.module.ts @@ -9,10 +9,6 @@ import {AccessKeyDirective} from '@eg/share/accesskey/accesskey.directive'; import {AccessKeyService} from '@eg/share/accesskey/accesskey.service'; import {AccessKeyInfoComponent} from '@eg/share/accesskey/accesskey-info.component'; import {OpChangeComponent} from '@eg/staff/share/op-change/op-change.component'; -import {ToastService} from '@eg/share/toast/toast.service'; -import {ToastComponent} from '@eg/share/toast/toast.component'; -import {StringComponent} from '@eg/share/string/string.component'; -import {StringService} from '@eg/share/string/string.service'; import {TitleComponent} from '@eg/share/title/title.component'; import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; import {BucketDialogComponent} from '@eg/staff/share/buckets/bucket-dialog.component'; @@ -32,8 +28,6 @@ import {DatetimeValidatorDirective} from '@eg/share/validators/datetime_validato OrgFamilySelectComponent, AccessKeyDirective, AccessKeyInfoComponent, - ToastComponent, - StringComponent, TitleComponent, OpChangeComponent, FmRecordEditorComponent, @@ -57,8 +51,6 @@ import {DatetimeValidatorDirective} from '@eg/share/validators/datetime_validato OrgFamilySelectComponent, AccessKeyDirective, AccessKeyInfoComponent, - ToastComponent, - StringComponent, TitleComponent, OpChangeComponent, FmRecordEditorComponent, @@ -77,9 +69,7 @@ export class StaffCommonModule { ngModule: StaffCommonModule, providers: [ // Export staff-wide services AccessKeyService, - AudioService, - StringService, - ToastService + AudioService ] }; } -- 2.43.2