LP#1775466 ng-lint updates
authorBill Erickson <berickxx@gmail.com>
Thu, 17 May 2018 21:29:58 +0000 (17:29 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 6 Jun 2018 20:59:39 +0000 (16:59 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/core/event.service.ts
Open-ILS/src/eg2/src/app/core/idl.service.ts
Open-ILS/src/eg2/src/app/core/store.service.ts
Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html

index 33e3f84..07b8c20 100644 (file)
@@ -1,23 +1,25 @@
 import {Injectable} from '@angular/core';
 
 export class EgEvent {
-    code        : number;
-    textcode    : string;
-    payload     : any;
-    desc        : string;
-    debug       : string;
-    note        : string;
-    servertime  : string;
-    ilsperm     : string;
-    ilspermloc  : number;
-    success     : Boolean = false;
+    code: number;
+    textcode: string;
+    payload: any;
+    desc: string;
+    debug: string;
+    note: string;
+    servertime: string;
+    ilsperm: string;
+    ilspermloc: number;
+    success: Boolean = false;
 
     toString(): string {
         let s = `Event: ${this.code}:${this.textcode} -> ${this.desc}`;
-        if (this.ilsperm)
+        if (this.ilsperm) {
             s += `  ${this.ilsperm}@${this.ilspermloc}`;
-        if (this.note)
+        }
+        if (this.note) {
             s += `\n${this.note}`;
+        }
         return s;
     }
 }
@@ -31,17 +33,17 @@ export class EgEventService {
     parse(thing: any): EgEvent {
 
         // All events have a textcode
-        if (thing && typeof thing == 'object' && 'textcode' in thing) {
+        if (thing && typeof thing === 'object' && 'textcode' in thing) {
 
-            let evt = new EgEvent();
+            const evt = new EgEvent();
 
-            ['textcode','payload','desc','note','servertime','ilsperm']
+            ['textcode', 'payload', 'desc', 'note', 'servertime', 'ilsperm']
                 .forEach(field => { evt[field] = thing[field]; });
 
             evt.debug = thing.stacktrace;
             evt.code = +(thing.ilsevent || -1);
             evt.ilspermloc = +(thing.ilspermloc || -1);
-            evt.success = thing.textcode == 'SUCCESS';
+            evt.success = thing.textcode === 'SUCCESS';
 
             return evt;
         }
index f105140..3362593 100644 (file)
@@ -23,9 +23,10 @@ export class EgIdlService {
     /**
      * Create a new IDL object instance.
      */
-    create(cls: string, seed?:any[]): EgIdlObject {
-        if (this.constructors[cls])
+    create(cls: string, seed?: any[]): EgIdlObject {
+        if (this.constructors[cls]) {
             return new this.constructors[cls](seed);
+        }
         throw new Error(`No such IDL class ${cls}`);
     }
 
@@ -42,15 +43,15 @@ export class EgIdlService {
          * Creates the class constructor and getter/setter
          * methods for each IDL class.
          */
-        let mkclass = (cls, fields) => {
+        const mkclass = (cls, fields) => {
             this.classes[cls].classname = cls;
 
             // This dance lets us encode each IDL object with the
             // EgIdlObject interface.  Useful for adding type restrictions
             // where desired for functions, etc.
-            let generator:any = ((): EgIdlObject => {
+            const generator: any = ((): EgIdlObject => {
 
-                var x:any = function(seed) {
+                const x: any = function(seed) {
                     this.a = seed || [];
                     this.classname = cls;
                     this._isfieldmapper = true;
@@ -58,9 +59,11 @@ export class EgIdlService {
 
                 fields.forEach(function(field, idx) {
                     x.prototype[field.name] = function(n) {
-                        if (arguments.length==1) this.a[idx] = n;
+                        if (arguments.length === 1) {
+                            this.a[idx] = n;
+                        }
                         return this.a[idx];
-                    }
+                    };
                 });
 
                 return x;
@@ -69,13 +72,14 @@ export class EgIdlService {
             this.constructors[cls] = generator();
 
             // global class constructors required for JSON_v1.js
-            // TODO: polluting the window namespace w/ every IDL class 
+            // TODO: polluting the window namespace w/ every IDL class
             // is less than ideal.
-            window[cls] = this.constructors[cls]; 
-        }
+            window[cls] = this.constructors[cls];
+        };
 
-        for (var cls in this.classes) 
-            mkclass(cls, this.classes[cls].fields);
+        Object.keys(this.classes).forEach(class_ => {
+            mkclass(class_, this.classes[class_].fields);
+        });
     }
 
     // Makes a deep copy of an EgIdlObject's / structures containing
@@ -84,10 +88,12 @@ export class EgIdlService {
     // @depth specifies the maximum number of steps through EgIdlObject'
     // we will traverse.
     clone(source: any, depth?: number): any {
-        if (depth === undefined) depth = 100;
+        if (depth === undefined) {
+            depth = 100;
+        }
 
-        var result;
-        if (typeof source == 'undefined' || source === null) {
+        let result;
+        if (typeof source === 'undefined' || source === null) {
             return source;
 
         } else if (source._isfieldmapper) {
@@ -95,19 +101,21 @@ export class EgIdlService {
             result = this.create(source.classname, this.clone(source.a, depth));
 
         } else {
-            if(Array.isArray(source)) {
+            if (Array.isArray(source)) {
                 result = [];
-            } else if(typeof source === 'object') { // source is not null
+            } else if (typeof source === 'object') { // source is not null
                 result = {};
             } else {
                 return source; // primitive
             }
 
-            for (var j in source) {
-                if (source[j] === null || typeof source[j] == 'undefined') {
+            for (const j in source) {
+                if (source[j] === null || typeof source[j] === 'undefined') {
                     result[j] = source[j];
-                } else if(source[j]._isfieldmapper) {
-                    if (depth) result[j] = this.clone(source[j], depth - 1);
+                } else if (source[j]._isfieldmapper) {
+                    if (depth) {
+                        result[j] = this.clone(source[j], depth - 1);
+                    }
                 } else {
                     result[j] = this.clone(source[j], depth);
                 }
index b4341a6..822b99f 100644 (file)
@@ -2,17 +2,16 @@
  * Store and retrieve data from various sources.
  */
 import {Injectable} from '@angular/core';
-import {Observable} from 'rxjs/Rx';
 import {CookieService} from 'ngx-cookie';
 
 @Injectable()
 export class EgStoreService {
-    
+
     // Base path for cookie-based storage.
     // Useful for limiting cookies to subsections of the application.
     // Store cookies globally by default.
     // Note cookies shared with /eg/staff must be stored at "/"
-    loginSessionBasePath: string = '/';
+    loginSessionBasePath = '/';
 
     // Set of keys whose values should disappear at logout.
     loginSessionKeys: string[] = [
@@ -25,10 +24,12 @@ export class EgStoreService {
     constructor(private cookieService: CookieService) {}
 
     private parseJson(valJson: string): any {
-        if (valJson == null || valJson == '') return null;
+        if (valJson === undefined || valJson === null || valJson === '') {
+            return null;
+        }
         try {
             return JSON.parse(valJson);
-        } catch(E) { 
+        } catch (E) {
             console.error(`Failure to parse JSON: ${E} => ${valJson}`);
             return null;
         }
@@ -48,7 +49,9 @@ export class EgStoreService {
     }
 
     setLocalItem(key: string, val: any, isJson?: Boolean): void {
-        if (!isJson) val = JSON.stringify(val);
+        if (!isJson) {
+            val = JSON.stringify(val);
+        }
         console.log(`${key} ${val}`);
         window.localStorage.setItem(key, val);
     }
@@ -58,12 +61,16 @@ export class EgStoreService {
     }
 
     setSessionItem(key: string, val: any, isJson?: Boolean): void {
-        if (!isJson) val = JSON.stringify(val);
+        if (!isJson) {
+            val = JSON.stringify(val);
+        }
         window.sessionStorage.setItem(key, val);
     }
 
-    setLoginSessionItem(key: string, val: any, isJson?:Boolean): void {
-        if (!isJson) val = JSON.stringify(val);
+    setLoginSessionItem(key: string, val: any, isJson?: Boolean): void {
+        if (!isJson) {
+            val = JSON.stringify(val);
+        }
         this.cookieService.put(key, val, {path : this.loginSessionBasePath});
     }
 
index 8589d58..24ec4e6 100644 (file)
@@ -73,12 +73,12 @@ TODO focus search input
     </div><!-- col -->
     <div class="col-lg-3">
       <div *ngIf="idx == 0" class="float-right">
-        <button class="btn btn-success" type="button"
+        <button class="btn btn-success mr-1" type="button"
           [disabled]="searchIsActive()"
           (click)="searchContext.pager.offset=0;searchByForm()">
           Search
         </button>
-        <button class="btn btn-warning" type="button"
+        <button class="btn btn-warning mr-1" type="button"
           [disabled]="searchIsActive()"
           (click)="searchContext.reset()">
           Clear Form