From 71ffbaaf7dbfdb9ad4deded0f7f62a639e6a1b13 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 17 May 2018 17:29:58 -0400 Subject: [PATCH] LP#1775466 ng-lint updates Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/app/core/event.service.ts | 34 ++++++++------- Open-ILS/src/eg2/src/app/core/idl.service.ts | 50 +++++++++++++--------- Open-ILS/src/eg2/src/app/core/store.service.ts | 25 +++++++---- .../app/staff/catalog/search-form.component.html | 4 +- 4 files changed, 65 insertions(+), 48 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/core/event.service.ts b/Open-ILS/src/eg2/src/app/core/event.service.ts index 33e3f84697..07b8c20fc1 100644 --- a/Open-ILS/src/eg2/src/app/core/event.service.ts +++ b/Open-ILS/src/eg2/src/app/core/event.service.ts @@ -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; } diff --git a/Open-ILS/src/eg2/src/app/core/idl.service.ts b/Open-ILS/src/eg2/src/app/core/idl.service.ts index f1051400d3..33625933d0 100644 --- a/Open-ILS/src/eg2/src/app/core/idl.service.ts +++ b/Open-ILS/src/eg2/src/app/core/idl.service.ts @@ -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); } diff --git a/Open-ILS/src/eg2/src/app/core/store.service.ts b/Open-ILS/src/eg2/src/app/core/store.service.ts index b4341a6750..822b99f9be 100644 --- a/Open-ILS/src/eg2/src/app/core/store.service.ts +++ b/Open-ILS/src/eg2/src/app/core/store.service.ts @@ -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}); } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html index 8589d58460..24ec4e6ba3 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html @@ -73,12 +73,12 @@ TODO focus search input
- -