"defaultProject": "eg",
"schematics": {
"@schematics/angular:component": {
- "prefix": "app",
+ "prefix": "eg",
"styleext": "css"
},
"@schematics/angular:directive": {
- "prefix": "app"
+ "prefix": "eg"
}
}
-}
\ No newline at end of file
+}
})
export class EgBaseModule {}
-
+
/**
* Modules, services, and components used by all apps.
- */
+ */
import {CommonModule, DatePipe, CurrencyPipe} from '@angular/common';
import {NgModule, ModuleWithProviders} from '@angular/core';
import {RouterModule} from '@angular/router';
private orgList: EgIdlObject[] = [];
private orgTree: EgIdlObject; // root node + children
- private orgMap: {[id:number] : EgIdlObject} = {};
+ private orgMap: {[id: number]: EgIdlObject} = {};
private settingsCache: OrgSettingsBatch = {};
constructor(
* Unset filter options are ignored.
*/
filterList(filter: OrgFilter, asId?: boolean): any[] {
- let list = [];
+ const list = [];
this.list().forEach(org => {
- let chu = filter.canHaveUsers;
+ const chu = filter.canHaveUsers;
if (chu && !this.canHaveUsers(org)) { return; }
if (chu === false && this.canHaveUsers(org)) { return; }
- let chv = filter.canHaveVolumes;
+ const chv = filter.canHaveVolumes;
if (chv && !this.canHaveVolumes(org)) { return; }
if (chv === false && this.canHaveVolumes(org)) { return; }
- let ov = filter.opacVisible;
+ const ov = filter.opacVisible;
if (ov && !this.opacVisible(org)) { return; }
if (ov === false && this.opacVisible(org)) { return; }
- if (filter.inList && filter.inList.indexOf(org.id()) == -1) {
+ if (filter.inList && !filter.inList.includes(org.id())) {
return;
}
- if (filter.notInList && filter.notInList.indexOf(org.id()) > -1) {
+ if (filter.notInList && filter.notInList.includes(org.id())) {
return;
}
ancestors(nodeOrId: EgOrgNodeOrId, asId?: boolean): any[] {
let node = this.get(nodeOrId);
if (!node) { return []; }
- let nodes = [node];
- while( (node = this.get(node.parent_ou()))) {
+ const nodes = [node];
+ while ( (node = this.get(node.parent_ou())) ) {
nodes.push(node);
}
if (asId) {
// list of org_unit objects or IDs for me + descendants
descendants(nodeOrId: EgOrgNodeOrId, asId?: boolean): any[] {
- let node = this.get(nodeOrId);
+ const node = this.get(nodeOrId);
if (!node) { return []; }
- let nodes = [];
+ const nodes = [];
const descend = (n) => {
nodes.push(n);
n.children().forEach(descend);
- }
+ };
descend(node);
if (asId) {
return nodes.map(n => n.id());
// list of org_unit objects or IDs for ancestors + me + descendants
fullPath(nodeOrId: EgOrgNodeOrId, asId?: boolean): any[] {
- let list = this.ancestors(nodeOrId, false).concat(
+ const list = this.ancestors(nodeOrId, false).concat(
this.descendants(nodeOrId, false).slice(1));
if (asId) {
return list.map(n => n.id());
if (!node) { node = this.orgTree; }
node.children(
node.children.sort((a, b) => {
- return a[sortField]() < b[sortField]() ? -1 : 1
+ return a[sortField]() < b[sortField]() ? -1 : 1;
})
);
node.children.forEach(n => this.sortTree(n));
* Return the list of settings /not/ pulled from cache.
*/
private settingsFromCache(names: string[], target: any) {
- let cacheKeys = Object.keys(this.settingsCache);
+ const cacheKeys = Object.keys(this.settingsCache);
cacheKeys.forEach(key => {
- let matchIdx = names.indexOf(key);
+ const matchIdx = names.indexOf(key);
if (matchIdx > -1) {
target[key] = this.settingsCache[key];
names.splice(matchIdx, 1);
private settingsFromNet(orgId: number,
names: string[], auth?: string): Promise<any> {
- let settings = {};
+ const settings = {};
return new Promise((resolve, reject) => {
this.net.request(
'open-ils.actor',
).subscribe(
blob => {
Object.keys(blob).forEach(key => {
- let val = blob[key]; // null or hash
+ const val = blob[key]; // null or hash
settings[key] = val ? val.value : null;
});
resolve(settings);
settings(names: string[],
orgId?: number, anonymous?: boolean): Promise<OrgSettingsBatch> {
- let settings = {};
+ const settings = {};
let auth: string = null;
let useCache = false;
if (this.auth.user()) {
if (orgId) {
- useCache = Number(orgId) == Number(this.auth.user().ws_ou());
+ useCache = Number(orgId) === Number(this.auth.user().ws_ou());
} else {
orgId = this.auth.user().ws_ou();
useCache = true;
'open-ils.actor.user.has_work_perm_at.batch',
this.auth.token(), permNames
).toPromise().then(resp => {
- var answer: HasPermAtResult = {};
+ const answer: HasPermAtResult = {};
permNames.forEach(perm => {
- var orgs = [];
+ const orgs = [];
resp[perm].forEach(oneOrg => {
orgs = orgs.concat(this.org.descendants(oneOrg, asId));
});
// workstation required
hasWorkPermHere(permNames: string[]): Promise<HasPermHereResult> {
- let wsId: number = +this.auth.user().wsid();
+ const wsId: number = +this.auth.user().wsid();
- if (!wsId)
+ if (!wsId) {
return Promise.reject('hasWorkPermHere requires a workstation');
+ }
return this.hasWorkPermAt(permNames, true).then(resp => {
- let answer: HasPermHereResult = {};
+ const answer: HasPermHereResult = {};
Object.keys(resp).forEach(perm => {
answer[perm] = resp[perm].indexOf(wsId) > -1;
});
ActivatedRouteSnapshot} from '@angular/router';
import {EgIdlService} from '@eg/core/idl.service';
import {EgOrgService} from '@eg/core/org.service';
-
+
@Injectable()
export class EgBaseResolver implements Resolve<Promise<void>> {
constructor(
- private router: Router,
+ private router: Router,
private idl: EgIdlService,
private org: EgOrgService,
) {}
/**
* Loads pre-auth data common to all applications.
- * No auth token is available at this level. When needed, auth is
+ * No auth token is available at this level. When needed, auth is
* enforced by application/group-specific resolvers at lower levels.
*/
resolve(
- route: ActivatedRouteSnapshot,
+ route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Promise<void> {
console.debug('EgBaseResolver:resolve()');
-import {NgModule} from '@angular/core';
+import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
-import {EgBaseResolver} from './resolver.service';
-import {WelcomeComponent} from './welcome.component';
+import {EgBaseResolver} from './resolver.service';
+import {WelcomeComponent} from './welcome.component';
/**
* Avoid loading all application JS up front by lazy-loading sub-modules.
{ path: '',
component: WelcomeComponent
}, {
- path: 'staff',
+ path: 'staff',
resolve : {startup : EgBaseResolver},
loadChildren: './staff/staff.module#EgStaffModule'
}
private elm: ElementRef,
private printer: EgPrintService
) {}
-
+
ngOnInit() {
this.printer.onPrintRequest$.subscribe(
printReq => this.handlePrintRequest(printReq));
} else {
*/
window.print();
- //}
+ // }
}
/*
import {Injectable, EventEmitter, TemplateRef} from '@angular/core';
export interface EgPrintRequest {
- template: TemplateRef<any>,
- contextData: any,
- printContext: string
+ template: TemplateRef<any>;
+ contextData: any;
+ printContext: string;
}
@Injectable()
/**
- * Plays audio files (alerts, generally) by key name. Each sound uses a
- * dot-path to indicate the sound.
+ * Plays audio files (alerts, generally) by key name. Each sound uses a
+ * dot-path to indicate the sound.
*
* For example:
*
* /audio/notifications/warning/checkout.wav
* /audio/notifications/warning.wav
*
- * Files are only played when sounds are configured to play via
+ * Files are only played when sounds are configured to play via
* workstation settings.
*/
import {Injectable, EventEmitter} from '@angular/core';
export class EgAudioService {
// map of requested audio path to resolved path
- private urlCache: {[path:string] : string} = {};
+ private urlCache: {[path: string]: string} = {};
constructor(private store: EgStoreService) {}
}
playUrl(path: string, origPath: string): void {
- //console.debug(`audio: playUrl(${path}, ${origPath})`);
+ // console.debug(`audio: playUrl(${path}, ${origPath})`);
this.store.getItem('eg.audio.disable').then(audioDisabled => {
- if (audioDisabled) return;
-
- let url = this.urlCache[path] ||
+ if (audioDisabled) { return; }
+
+ const url = this.urlCache[path] ||
AUDIO_BASE_URL + path.replace(/\./g, '/') + '.wav';
- let player = new Audio(url);
+ const player = new Audio(url);
player.onloadeddata = () => {
this.urlCache[origPath] = url;
player.onerror = () => {
// Unable to play path at the requested URL.
-
+
if (!path.match(/\./)) {
// all fall-through options have been exhausted.
// No path to play.
console.warn(
- "No suitable URL found for path '" + origPath + "'");
+ `No suitable URL found for path "${origPath}"`);
return;
}
// Fall through to the next (more generic) option
path = path.replace(/\.[^\.]+$/, '');
this.playUrl(path, origPath);
- }
+ };
});
}
}
@Injectable()
export class EgFormatService {
- dateFormat: string = 'shortDate';
- dateTimeFormat: string = 'short';
+ dateFormat = 'shortDate';
+ dateTimeFormat = 'short';
wsOrgTimezone: string = OpenSRF.tz;
constructor(
* Create a human-friendly display version of any field type.
*/
transform(params: EgFormatParams): string {
- let value = params.value;
+ const value = params.value;
- if ( value === undefined
- || value === null
- || value === ''
- || Number.isNaN(value)) return '';
+ if ( value === undefined
+ || value === null
+ || value === ''
+ || Number.isNaN(value)) {
+ return '';
+ }
let datatype = params.datatype;
}
}
- switch(datatype) {
+ switch (datatype) {
case 'org_unit':
- let orgField = params.orgField || 'shortname';
- let org = this.org.get(value);
+ const orgField = params.orgField || 'shortname';
+ const org = this.org.get(value);
return org ? org[orgField]() : '';
case 'timestamp':
- let date = new Date(value);
- let fmt = this.dateFormat || 'shortDate';
+ const date = new Date(value);
+ const fmt = this.dateFormat || 'shortDate';
if (params.datePlusTime) {
fmt = this.dateTimeFormat || 'short';
}
})
export class WelcomeComponent implements OnInit {
-
ngOnInit() {
}
}
"directive-selector": [
true,
"attribute",
- "app",
+ "eg",
"camelCase"
],
"component-selector": [
true,
"element",
- "app",
+ "eg",
"kebab-case"
],
"use-input-property-decorator": true,