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;
}
}
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;
}
/**
* 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}`);
}
* 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;
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;
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
// @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) {
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);
}
* 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[] = [
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;
}
}
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);
}
}
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});
}
</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