}
shrinkColumn(col: EgGridColumn) {
- if (col.flex > 1) col.flex--;
+ if (col.flex > 1) { col.flex--; }
}
}
return;
}
- let col = new EgGridColumn();
+ const col = new EgGridColumn();
col.name = this.name;
col.path = this.path;
col.label = this.label;
ngOnInit() {}
onColumnDragEnter($event: any, col: any) {
- if (this.dragColumn && this.dragColumn.name != col.name)
+ if (this.dragColumn && this.dragColumn.name !== col.name) {
col.isDragTarget = true;
+ }
$event.preventDefault();
}
sortOneColumn(col: EgGridColumn) {
let dir = 'ASC';
- let sort = this.gridContext.dataSource.sort;
+ const sort = this.gridContext.dataSource.sort;
- if (sort.length && sort[0].name == col.name && sort[0].dir == 'ASC') {
+ if (sort.length && sort[0].name === col.name && sort[0].dir === 'ASC') {
dir = 'DESC';
}
// Returns true if the provided column is sorting in the
// specified direction.
isColumnSorting(col: EgGridColumn, dir: string): boolean {
- let sort = this.gridContext.dataSource.sort.filter(c => c.name == col.name)[0];
- return sort && sort.dir == dir;
+ const sort = this.gridContext.dataSource.sort.filter(c => c.name === col.name)[0];
+ return sort && sort.dir === dir;
}
handleBatchSelect($event) {
}
selectAll() {
- let rows = this.gridContext.dataSource.getPageOfRows(this.gridContext.pager);
- let indexes = rows.map(r => this.gridContext.getRowIndex(r));
+ const rows = this.gridContext.dataSource.getPageOfRows(this.gridContext.pager);
+ const indexes = rows.map(r => this.gridContext.getRowIndex(r));
this.gridContext.rowSelector.select(indexes);
}
allRowsAreSelected(): boolean {
- let rows = this.gridContext.dataSource.getPageOfRows(this.gridContext.pager);
- let indexes = rows.map(r => this.gridContext.getRowIndex(r));
+ const rows = this.gridContext.dataSource.getPageOfRows(this.gridContext.pager);
+ const indexes = rows.map(r => this.gridContext.getRowIndex(r));
return this.gridContext.rowSelector.contains(indexes);
}
}
return;
}
- let action = new EgGridToolbarAction();
+ const action = new EgGridToolbarAction();
action.label = this.label;
action.action = this.action;
return;
}
- let btn = new EgGridToolbarButton();
+ const btn = new EgGridToolbarButton();
btn.label = this.label;
btn.action = this.action;
this.gridContext.gridToCsv().then(csv => {
console.log(csv);
- var blob = new Blob([csv], {type : 'text/plain'});
- let win: any = window;
+ const blob = new Blob([csv], {type : 'text/plain'});
+ const win: any = window; // avoid TS errors
this.csvExportUrl = this.sanitizer.bypassSecurityTrustUrl(
(win.URL || win.webkitURL).createObjectURL(blob)
);
import {Component, Input, OnInit, AfterViewInit, EventEmitter, OnDestroy,
HostListener, ViewEncapsulation} from '@angular/core';
-import {Subscription} from "rxjs/Subscription";
+import {Subscription} from 'rxjs/Subscription';
import {EgIdlService} from '@eg/core/idl.service';
import {EgOrgService} from '@eg/core/org.service';
import {EgStoreService} from '@eg/core/store.service';
this.context.mainLabel = this.mainLabel;
this.context.idlClass = this.idlClass;
this.context.dataSource = this.dataSource;
- this.context.persistKey = this.persistKey
+ this.context.persistKey = this.persistKey;
this.context.isSortable = this.isSortable === true;
this.context.isMultiSortable = this.isMultiSortable === true;
this.context.disableMultiSelect = this.disableMultiSelect === true;
// Not using @HostListener because it only works globally.
onGridKeyDown(evt: KeyboardEvent) {
- switch(evt.key) {
+ switch (evt.key) {
case 'ArrowUp':
this.context.selectPreviousRow();
evt.stopPropagation();
}
onRowClick($event: any, row: any, idx: number) {
- let index = this.context.getRowIndex(row);
+ const index = this.context.getRowIndex(row);
if (this.context.disableMultiSelect) {
this.context.selectOneRow(index);
} else if ($event.ctrlKey || $event.metaKey /* mac command */) {
- if (this.context.toggleSelectOneRow(index))
+ if (this.context.toggleSelectOneRow(index)) {
this.context.lastSelectedIndex = index;
+ }
} else if ($event.shiftKey) {
// TODO shift range click
import {EgStoreService} from '@eg/core/store.service';
import {EgOrgService} from '@eg/core/org.service';
import {EgIdlObject} from '@eg/core/idl.service';
-import {NgbTypeahead, NgbTypeaheadSelectItemEvent}
- from '@ng-bootstrap/ng-bootstrap';
+import {NgbTypeahead, NgbTypeaheadSelectItemEvent} from '@ng-bootstrap/ng-bootstrap';
// Use a unicode char for spacing instead of ASCII=32 so the browser
// won't collapse the nested display entries down to a single space.
-const PAD_SPACE: string = ' '; // U+2007
+const PAD_SPACE = ' '; // U+2007
interface OrgDisplay {
id: number;
@ViewChild('instance') instance: NgbTypeahead;
// Placeholder text for selector input
- @Input() placeholder: string = '';
+ @Input() placeholder = '';
@Input() stickySetting: string;
// Org unit field displayed in the selector
- @Input() displayField: string = 'shortname';
+ @Input() displayField = 'shortname';
// Apply a default org unit value when none is set.
// First tries workstation org unit, then user home org unit.
// An onChange event WILL be generated when a default is applied.
- @Input() applyDefault: boolean = false;
+ @Input() applyDefault = false;
// List of org unit IDs to exclude from the selector
@Input() set hideOrgs(ids: number[]) {
- if (ids) this.hidden = ids;
+ if (ids) { this.hidden = ids; }
}
// List of org unit IDs to disable in the selector
@Input() set disableOrgs(ids: number[]) {
- if (ids) this.disabled = ids;
+ if (ids) { this.disabled = ids; }
}
// Apply an org unit value at load time.
// This will NOT result in an onChange event.
@Input() set initialOrg(org: EgIdlObject) {
- if (org) this.startOrg = org;
+ if (org) { this.startOrg = org; }
}
// Apply an org unit value by ID at load time.
// This will NOT result in an onChange event.
@Input() set initialOrgId(id: number) {
- if (id) this.startOrg = this.org.get(id);
+ if (id) { this.startOrg = this.org.get(id); }
}
// Modify the selected org unit via data binding.
// This WILL result in an onChange event firing.
@Input() set applyOrg(org: EgIdlObject) {
- if (org) this.selected = this.formatForDisplay(org);
+ if (org) {
+ this.selected = this.formatForDisplay(org);
+ }
}
// Modify the selected org unit by ID via data binding.
// This WILL result in an onChange event firing.
@Input() set applyOrgId(id: number) {
- if (id) this.selected = this.formatForDisplay(this.org.get(id));
+ if (id) {
+ this.selected = this.formatForDisplay(this.org.get(id));
+ }
}
// Emitted when the org unit value is changed via the selector.
// Find orgs matching the search term
return org[this.displayField]()
- .toLowerCase().indexOf(term.toLowerCase()) > -1
+ .toLowerCase().indexOf(term.toLowerCase()) > -1;
}).filter(org => { // Exclude hidden orgs
- return this.hidden.filter(
- id => {return org.id() == id}).length == 0;
+ return this.hidden.filter(id => org.id() === id).length === 0;
- }).map(org => {return this.formatForDisplay(org)})
+ }).map(org => this.formatForDisplay(org));
})
);
}
if (this.key) {
this.strings.register({
key: this.key,
- resolver: (ctx:any) => this.current(ctx)
+ resolver: (ctx: any) => this.current(ctx)
});
}
}
// hopefully we can retire the EgString* code entirely once
// in-code translations are supported (Ang6?)
current(ctx?: any): Promise<string> {
- if (ctx) this.ctx = ctx;
+ if (ctx) { this.ctx = ctx; }
return new Promise(resolve => {
setTimeout(() => resolve(this.elm.nativeElement.textContent));
});
import {Injectable} from '@angular/core';
interface EgStringAssignment {
- key: string, // keyboard command
- resolver: (ctx:any) => Promise<string>
-};
+ key: string; // keyboard command
+ resolver: (ctx: any) => Promise<string>;
+}
@Injectable()
export class EgStringService {
- strings: {[key:string] : EgStringAssignment} = {};
+ strings: {[key: string]: EgStringAssignment} = {};
constructor() {}
}
interpolate(key: string, ctx?: any): Promise<string> {
- if (!this.strings[key])
+ if (!this.strings[key]) {
return Promise.reject('No Such String');
+ }
return this.strings[key].resolver(ctx);
}
// track the most recent timeout event
timeout: any;
- constructor(private toast: EgToastService) {
+ constructor(private toast: EgToastService) {
}
ngOnInit() {
import {Injectable, EventEmitter} from '@angular/core';
export interface EgToastMessage {
- text: string,
- style: string
-};
+ text: string;
+ style: string;
+}
@Injectable()
export class EgToastService {
import {EgStringService} from '@eg/share/string/string.service';
import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
import {EgDateSelectComponent} from '@eg/share/date-select/date-select.component';
-import {EgLinkTableComponent, EgLinkTableLinkComponent}
- from '@eg/staff/share/link-table/link-table.component';
+import {EgLinkTableComponent, EgLinkTableLinkComponent} from '@eg/staff/share/link-table/link-table.component';
/**
* Imports the EG common modules and adds modules common to all staff UI's.
.then(list => this.workstations = list || [])
.then(list => this.store.getItem('eg.workstation.default'))
.then(defWs => this.args.workstation = defWs)
- .then(noOp => this.applyWorkstation())
+ .then(noOp => this.applyWorkstation());
}
applyWorkstation() {
- let wanted = this.route.snapshot.queryParamMap.get('workstation');
- if (!wanted) return; // use the default
+ const wanted = this.route.snapshot.queryParamMap.get('workstation');
+ if (!wanted) { return; } // use the default
- let exists = this.workstations.filter(w => w.name == wanted)[0];
+ const exists = this.workstations.filter(w => w.name === wanted)[0];
if (exists) {
this.args.workstation = wanted;
} else {
handleSubmit() {
// post-login URL
- let url: string = this.auth.redirectUrl || '/staff/splash';
- let workstation: string = this.args.workstation;
+ const url: string = this.auth.redirectUrl || '/staff/splash';
+ const workstation: string = this.args.workstation;
this.auth.login(this.args).then(
ok => {
this.auth.redirectUrl = null;
- if (this.auth.workstationState == EgAuthWsState.NOT_FOUND_SERVER) {
+ if (this.auth.workstationState === EgAuthWsState.NOT_FOUND_SERVER) {
// User attempted to login with a workstation that is
// unknown to the server. Redirect to the WS admin page.
this.router.navigate(
// ^-- = this.ngLocation.prepareExternalUrl('/staff');
// Not sure how to get the path without params... using this for now.
- let path = state.url.split('?')[0]
- if (path == '/staff/login') return Observable.of(true);
+ const path = state.url.split('?')[0];
+ if (path === '/staff/login') {
+ return Observable.of(true);
+ }
- let observable: Observable<any>
+ const observable: Observable<any>
= Observable.create(o => this.observer = o);
this.auth.testAuthToken().then(
this.auth.verifyWorkstation().then(
wsOk => {
this.loadStartupData()
- .then(ok => this.observer.complete())
+ .then(ok => this.observer.complete());
},
wsNotOk => this.handleInvalidWorkstation(path)
);
import {Component, Input, OnInit, AfterViewInit, Host} from '@angular/core';
interface LinkTableLink {
- label: string,
- url?: string,
- routerLink?: string
+ label: string;
+ url?: string;
+ routerLink?: string;
}
@Component({
ngAfterViewInit() {
// table-ize the links
- let rowCount = Math.ceil(this.links.length / this.columnCount);
+ const rowCount = Math.ceil(this.links.length / this.columnCount);
this.colWidth = Math.floor(12 / this.columnCount); // Bootstrap 12-grid
- for (let col = 0; col < this.columnCount; col++)
+ for (let col = 0; col < this.columnCount; col++) {
this.colList.push(col);
+ }
// Modifying values in AfterViewInit without other activity
// happening can result in the modified values not getting
@Input() username: string;
@Input() password: string;
- @Input() loginType: string = 'temp';
+ @Input() loginType = 'temp';
@Input() successMessage: string;
@Input() failMessage: string;
- constructor(
+ constructor(
private modal: NgbModal, // required for passing to parent
private renderer: Renderer2,
private toast: EgToastService,
}
login(): Promise<any> {
- if (!(this.username && this.password))
+ if (!(this.username && this.password)) {
return Promise.reject('Missing Params');
+ }
return this.auth.login(
{ username : this.username,
// Fetch the user object
this.auth.testAuthToken().then(
- ok => {
+ ok2 => {
this.close();
this.toast.success(this.successMessage);
}
}
searchCatalog(): void {
- if (!this.catSearchQuery) return;
+ if (!this.catSearchQuery) { return; }
this.router.navigate(
['/staff/catalog/search'],
import {EgAuthService, EgAuthWsState} from '@eg/core/auth.service';
import {EgNetService} from '@eg/core/net.service';
import {EgAccessKeyService} from '@eg/share/accesskey/accesskey.service';
-import {EgAccessKeyInfoComponent}
- from '@eg/share/accesskey/accesskey-info.component';
+import {EgAccessKeyInfoComponent} from '@eg/share/accesskey/accesskey-info.component';
const LOGIN_PATH = '/staff/login';
const WS_BASE_PATH = '/staff/admin/workstation/workstations/';
// Fires on all in-app router navigation, but not initial page load.
this.router.events.subscribe(routeEvent => {
if (routeEvent instanceof NavigationEnd) {
- //console.debug(`EgStaffComponent routing to ${routeEvent.url}`);
+ // console.debug(`EgStaffComponent routing to ${routeEvent.url}`);
this.preventForbiddenNavigation(routeEvent.url);
}
});
// If the expired authtoken was identified locally (i.e.
// in this browser tab) notify all tabs of imminent logout.
- if (!expireEvent.viaExternal) this.auth.broadcastLogout();
+ if (!expireEvent.viaExternal) {
+ this.auth.broadcastLogout();
+ }
console.debug('Auth session has expired. Redirecting to login');
this.auth.redirectUrl = this.router.url;
});
});
- this.route.data.subscribe((data: {staffResolver : any}) => {
+ this.route.data.subscribe((data: {staffResolver: any}) => {
// Data fetched via EgStaffResolver is available here.
});
preventForbiddenNavigation(url: string): void {
// No auth checks needed for login page.
- if (url.startsWith(LOGIN_PATH)) return;
+ if (url.startsWith(LOGIN_PATH)) {
+ return;
+ }
// We lost our authtoken, go back to the login page.
- if (!this.auth.token())
+ if (!this.auth.token()) {
this.router.navigate([LOGIN_PATH]);
+ }
// No workstation checks needed for workstation admin page.
- if (url.startsWith(WS_BASE_PATH)) return;
+ if (url.startsWith(WS_BASE_PATH)) {
+ return;
+ }
- if (this.auth.workstationState != EgAuthWsState.VALID)
+ if (this.auth.workstationState !== EgAuthWsState.VALID) {
this.router.navigate([WS_MANAGE_PATH]);
+ }
}
/**