LP1825851 Print template failure warnings
authorBill Erickson <berickxx@gmail.com>
Thu, 1 Aug 2019 20:35:41 +0000 (16:35 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 8 Aug 2019 19:47:31 +0000 (15:47 -0400)
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 <berickxx@gmail.com>
Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/common.module.ts
Open-ILS/src/eg2/src/app/share/print/print.component.html
Open-ILS/src/eg2/src/app/share/print/print.component.ts
Open-ILS/src/eg2/src/app/share/print/print.service.ts
Open-ILS/src/eg2/src/app/staff/common.module.ts

index ead50f1..af1f2b0 100644 (file)
@@ -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
             ]
         };
     }
index 12d05bc..823b5d8 100644 (file)
@@ -3,6 +3,16 @@ Global print container.
 There should only be one print component active in a page.
 -->
 
+<ng-template #notFound let-name="name" i18n>
+No activate template found named "{{name}}"
+</ng-template>
+<eg-string key='eg.print.template.not_found' [template]="notFound"></eg-string>
+
+<ng-template #notWorking let-name="name" let-id="id" i18n>
+Error generating print content for template name="{{name}}" / id="{{id}}"
+</ng-template>
+<eg-string key='eg.print.template.error' [template]="notWorking"></eg-string>
+
 <div id='eg-print-container'>
   <!-- container for inline template compilation -->
   <ng-container *ngIf="template">
index ff1c3ed..20c0567 100644 (file)
@@ -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'));
                 }
index abba31c..25ef206 100644 (file)
@@ -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);
index 969ca37..12c0ff1 100644 (file)
@@ -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
             ]
         };
     }