LP1825851 lint user/berick/lp1825851-server-generated-print-templates-more-wip
authorBill Erickson <berickxx@gmail.com>
Fri, 12 Jul 2019 19:01:00 +0000 (15:01 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 12 Jul 2019 19:01:00 +0000 (15:01 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/core/idl.service.ts
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
Open-ILS/src/eg2/src/app/share/print/print.component.ts
Open-ILS/src/eg2/src/app/share/util/sample-data.service.ts
Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts
Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts

index 468ae2d..21ec24a 100644 (file)
@@ -167,25 +167,25 @@ export class IdlService {
             return obj.map(item => this.toHash(item));
         }
 
-        const fieldNames = obj._isfieldmapper ? 
+        const fieldNames = obj._isfieldmapper ?
             Object.keys(this.classes[obj.classname].field_map) :
             Object.keys(obj);
 
         const hash: any = {};
         fieldNames.forEach(field => {
 
-            var val = this.toHash(
-                typeof obj[field] === 'function' ?  obj[field]() : obj[field], 
+            const val = this.toHash(
+                typeof obj[field] === 'function' ?  obj[field]() : obj[field],
                 flatten
             );
 
             if (val === undefined) { return; }
 
-            if (flatten && val !== null && 
+            if (flatten && val !== null &&
                 typeof val === 'object' && !Array.isArray(val)) {
 
                 Object.keys(val).forEach(key => {
-                    let fname = field + '.' + key;
+                    const fname = field + '.' + key;
                     hash[fname] = val[key];
                 });
 
index 6995043..84b89d8 100644 (file)
@@ -3,7 +3,7 @@
  *  <!-- see also <eg-combobox-entry> -->
  * </eg-combobox>
  */
-import {Component, OnInit, Input, Output, ViewChild, 
+import {Component, OnInit, Input, Output, ViewChild,
     TemplateRef, EventEmitter, ElementRef} from '@angular/core';
 import {Observable, of, Subject} from 'rxjs';
 import {map, tap, reduce, mergeMap, mapTo, debounceTime, distinctUntilChanged, merge, filter} from 'rxjs/operators';
index f9238aa..ff1c3ed 100644 (file)
@@ -69,7 +69,7 @@ export class PrintComponent implements OnInit {
             this.template = printReq.template;
             this.context = {$implicit: printReq.contextData};
             return Promise.resolve();
-        } 
+        }
 
         let promise;
 
@@ -86,15 +86,15 @@ export class PrintComponent implements OnInit {
                     printReq.contentType = response.contentType;
                 },
                 err => {
-                    console.error("Error compiling template", printReq);
+                    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"));
+            console.error('Cannot find template', printReq);
+            return Promise.reject(new Error('Cannot find print template'));
         }
 
         return promise.then(() => {
index 66f840c..d159d6d 100644 (file)
@@ -71,16 +71,16 @@ const DATA = {
         {barcode: '208897239009'}
     ],
     mwde: [
-        {title: "Sinidos sinfónicos : an orchestral sampler"},
-        {title: "Piano concerto, op. 38"},
-        {title: "Critical entertainments : music old and new"},
-        {title: "Piano concerto in C major, op. 39"},
-        {title: "Double concerto in A minor, op. 102 ; Variations on a theme by Haydn, op. 56a ; Tragic overture, op. 81"},
-        {title: "Trombone concerto (1991) subject: american"},
-        {title: "Violin concerto no. 2 ; Six duos (from 44 Duos)"},
-        {title: "Piano concerto no. 1 (1926) ; Rhapsody, op. 1 (1904)"},
-        {title: "Piano concertos 2 & 3 & the devil makes me?"},
-        {title: "Composition student recital, April 6, 2000, Huntington University / composition students of Daniel Bédard"},
+        {title: 'Sinidos sinfónicos : an orchestral sampler'},
+        {title: 'Piano concerto, op. 38'},
+        {title: 'Critical entertainments : music old and new'},
+        {title: 'Piano concerto in C major, op. 39'},
+        {title: 'Double concerto in A minor, op. 102 ; Variations on a theme by Haydn, op. 56a ; Tragic overture, op. 81'},
+        {title: 'Trombone concerto (1991) subject: american'},
+        {title: 'Violin concerto no. 2 ; Six duos (from 44 Duos)'},
+        {title: 'Piano concerto no. 1 (1926) ; Rhapsody, op. 1 (1904)'},
+        {title: 'Piano concertos 2 & 3 & the devil makes me?'},
+        {title: 'Composition student recital, April 6, 2000, Huntington University / composition students of Daniel Bédard'},
     ]
 };
 
@@ -96,7 +96,7 @@ export class SampleDataService {
 
     listOfThings(idlClass: string, count: number = 1): IdlObject[] {
         if (!(idlClass in DATA)) {
-            throw new Error(`No sample data for class ${idlClass}"`);
+            throw new Error(`No sample data for class ${idlClass}'`);
         }
 
         const things: IdlObject[] = [];
index f5f7936..379a1d2 100644 (file)
@@ -48,7 +48,7 @@ export class PrintTemplateComponent implements OnInit {
     sampleData: any = {
         patron_address: {},
         holds_for_bib: {}
-    }
+    };
 
     constructor(
         private route: ActivatedRoute,
@@ -82,8 +82,8 @@ export class PrintTemplateComponent implements OnInit {
         // Classes for which sample data exists
         const classes = ['au', 'ac', 'aua', 'ahr', 'acp', 'mwde'];
         const samples: any = {};
-        classes.forEach(class_ => samples[class_] = 
-            this.idl.toHash(this.samples.listOfThings(class_, 10)))
+        classes.forEach(class_ => samples[class_] =
+            this.idl.toHash(this.samples.listOfThings(class_, 10)));
 
         // Wide holds are hashes instead of IDL objects.
         // Add fields as needed.
@@ -120,7 +120,8 @@ export class PrintTemplateComponent implements OnInit {
         return document.getElementById('template-preview-pane');
     }
 
-    //orgOnChange(org: IdlObject) {
+    // TODO should the ngModelChange handler fire for org-family-select
+    // even whn no values have changed?
     orgOnChange(family: OrgFamily) {
         if (!this.arrayEquals(this.selectedOrgs, family.orgIds)) {
             this.selectedOrgs = family.orgIds;
@@ -128,11 +129,12 @@ export class PrintTemplateComponent implements OnInit {
         }
     }
 
+    // TODO move to shared utility
     arrayEquals(arr1: any[], arr2: any[]): boolean {
         if (arr1.length !== arr2.length) {
             return false;
         }
-        for (var i = 0; i < arr1.length; i++) {
+        for (let i = 0; i < arr1.length; i++) {
             if (arr1[i] !== arr2[i]) {
                 return false;
             }
@@ -155,17 +157,17 @@ export class PrintTemplateComponent implements OnInit {
         this.templateSelector.applyEntryId(null);
         this.compiledContent = '';
 
-        return this.pcrud.search('cpt', 
+        return this.pcrud.search('cpt',
             {
                 owner: this.selectedOrgs,
                 locale: this.localeCode
             }, {
-                select: {cpt: ['id', 'label', 'owner']}, 
+                select: {cpt: ['id', 'label', 'owner']},
                 order_by: {cpt: 'label'}
             }
         ).pipe(map(tmpl => {
             this.templateCache[tmpl.id()] = tmpl;
-            this.entries.push({id: tmpl.id(), label: tmpl.label()})
+            this.entries.push({id: tmpl.id(), label: tmpl.label()});
             return tmpl;
         }));
     }
@@ -193,12 +195,12 @@ export class PrintTemplateComponent implements OnInit {
     }
 
     refreshPreview() {
-        if (!this.sampleJson) return;
+        if (!this.sampleJson) { return; }
         this.compiledContent = '';
 
         let data;
         try {
-            data = JSON.parse(this.sampleJson);  
+            data = JSON.parse(this.sampleJson);
             this.invalidJson = false;
         } catch (E) {
             this.invalidJson = true;
@@ -210,7 +212,7 @@ export class PrintTemplateComponent implements OnInit {
             printContext: 'default' // required, has no impact here
 
         }).then(response => {
-            
+
             this.compiledContent = response.content;
             if (response.contentType === 'text/html') {
                 this.container().innerHTML = response.content;
@@ -224,7 +226,7 @@ export class PrintTemplateComponent implements OnInit {
     applyChanges() {
         this.container().innerHTML = '';
         this.pcrud.update(this.template).toPromise()
-            .then(() =>this.refreshPreview());
+            .then(() => this.refreshPreview());
     }
 
     openEditDialog() {
@@ -243,9 +245,9 @@ export class PrintTemplateComponent implements OnInit {
         tmpl.id(null);
         this.editDialog.setRecord(tmpl);
         this.editDialog.mode = 'create';
-        this.editDialog.open({size: 'lg'}).toPromise().then(tmpl => {
+        this.editDialog.open({size: 'lg'}).toPromise().then(newTmpl => {
             this.setTemplateInfo().toPromise()
-                .then(_ => this.selectTemplate(tmpl.id()));
+                .then(_ => this.selectTemplate(newTmpl.id()));
 
         });
     }
@@ -255,7 +257,7 @@ export class PrintTemplateComponent implements OnInit {
             if (!confirmed) { return; }
             this.pcrud.remove(this.template).toPromise().then(_ => {
                 this.setTemplateInfo().toPromise()
-                    .then(_ => this.selectTemplate(null));
+                    .then(x => this.selectTemplate(null));
             });
         });
     }
index 505a501..64397d7 100644 (file)
@@ -274,7 +274,7 @@ export class SandboxComponent implements OnInit {
         const templateData = {
             patron:  this.samples.listOfThings('au')[0],
             address: this.samples.listOfThings('aua')[0]
-        }
+        };
 
         // NOTE: eventually this will be baked into the print service.
         this.printer.print({
index d6988dc..eb670d0 100644 (file)
@@ -404,7 +404,7 @@ export class HoldsGridComponent implements OnInit {
         pager.offset = 0;
         pager.limit = null;
 
-        if (this.gridDataSource.sort.length == 0) {
+        if (this.gridDataSource.sort.length === 0) {
             this.gridDataSource.sort = this.defaultSort;
         }