}
return new Promise((resolve, reject) => {
- const workstations =
+ const workstations =
this.store.getLocalItem('eg.workstation.all');
if (workstations) {
// Slightly better than a bare 't' or 'f'.
// Should probably add a global true/false string.
return Boolean(
- value === 't' || value === 1 ||
+ value === 't' || value === 1 ||
value === '1' || value === true
).toString();
import {Location} from '@angular/common';
import {environment} from '../../environments/environment';
import {Observable} from 'rxjs/Observable';
-import 'rxjs/add/observable/of'
+import 'rxjs/add/observable/of';
import {CookieService} from 'ngx-cookie';
import {IdlObject} from '@eg/core/idl.service';
import {PcrudService} from '@eg/core/pcrud.service';
export class LocaleService {
constructor(
- private ngLocation: Location,
+ private ngLocation: Location,
private cookieService: CookieService,
private pcrud: PcrudService) {
}
// Finally tack the path of the current page back onto the URL
// which is more friendly than forcing them back to the splash page.
- url += this.ngLocation.path()
-
+ url += this.ngLocation.path();
+
// Set a 10-year locale cookie to maintain compatibility
// with the AngularJS client.
// Cookie takes the form aa_bb instead of aa-BB
const cookie = code.replace(/-/, '_').toLowerCase();
- this.cookieService.put('eg_locale',
+ this.cookieService.put('eg_locale',
cookie, {path : '/', secure: true, expires: '+10y'});
window.location.href = url;
return environment.locales || [];
}
- // Returns i18n_l objects matching the locales supported
+ // Returns i18n_l objects matching the locales supported
// in the current environment.
supportedLocales(): Observable<IdlObject> {
const locales = this.supportedLocaleCodes();
// Extract the local from the URL.
// It's the last component of the base path.
// Note we don't extract it from the cookie since using cookies
- // to store the locale will not be necessary when AngularJS
+ // to store the locale will not be necessary when AngularJS
// is deprecated.
currentLocaleCode(): string {
const base = this.ngLocation.prepareExternalUrl('/');
export class ServerStoreService {
cache: {[key: string]: ServerSettingSummary};
-
+
constructor(
private net: NetService,
private auth: AuthService) {
}
setItem(key: string, value: any): Promise<any> {
-
+
if (!this.auth.token()) {
return Promise.reject('Auth required to apply settings');
}
if (Number(appliedCount) > 0) { // value applied
return this.cache[key] = value;
}
-
+
return Promise.reject(
- `No user or workstation setting type exists for: "${key}".\n` +
+ `No user or workstation setting type exists for: "${key}".\n` +
'Create a ws/user setting type or use setLocalItem() to ' +
'store the value locally.'
);
// Returns a set of key/value pairs for the requested settings
getItemBatch(keys: string[]): Promise<any> {
-
+
const values: any = {};
keys.forEach(key => {
if (this.cache[key]) {
if (!this.auth.token()) {
// Authtokens require for fetching server settings, but
- // calls to retrieve settings could potentially occur
+ // calls to retrieve settings could potentially occur
// before auth completes -- Ideally not, but just to be safe.
return Promise.resolve({});
}
serverKeys, this.auth.token()
).subscribe(
summary => {
- this.cache[summary.name] =
+ this.cache[summary.name] =
values[summary.name] = summary.value;
},
err => reject,
if (!isJson) {
val = JSON.stringify(val);
}
- this.cookieService.put(key, val,
+ this.cookieService.put(key, val,
{path : this.loginSessionBasePath, secure: true});
}
-import {Component, Input, OnInit, AfterViewInit,
+import {Component, Input, OnInit, AfterViewInit,
TemplateRef, ElementRef, AfterContentChecked} from '@angular/core';
import {GridContext, GridColumn, GridRowSelector,
GridColumnSet, GridDataSource} from './grid';
this.setTooltip();
}
- // Returns true if the contents of this cell exceed the
+ // Returns true if the contents of this cell exceed the
// boundaries of its container.
cellOverflows(): boolean {
let node = this.elm.nativeElement;
return false;
}
- // Tooltips are only applied to cells whose contents exceed
+ // Tooltips are only applied to cells whose contents exceed
// their container.
// Applying an empty string value prevents a tooltip from rendering.
setTooltip() {
if (this.cellOverflows()) {
- this.tooltipContent = this.column.cellTemplate ||
+ this.tooltipContent = this.column.cellTemplate ||
this.context.getRowColumnValue(this.row, this.column);
} else {
// No tooltip
// the selected fields will be hidden.
@Input() hideFields: string;
- // Allow the caller to jump directly to a specific page of
+ // Allow the caller to jump directly to a specific page of
// grid data.
@Input() pageOffset: number;
add(col: GridColumn) {
this.applyColumnDefaults(col);
-
- if (!this.insertColumn(col)) {
+
+ if (!this.insertColumn(col)) {
// Column was rejected as a duplicate.
- return;
+ return;
}
if (col.isIndex) { this.indexColumn = col; }
if (col.isAuto) {
if (this.getColByName(col.name)) {
- // New auto-generated column conflicts with existing
+ // New auto-generated column conflicts with existing
// column. Skip it.
return false;
} else {
for (let idx = 0; idx < this.columns.length; idx++) {
const testCol = this.columns[idx];
if (testCol.name === col.name) { // match found
- if (testCol.isAuto) {
+ if (testCol.isAuto) {
// new column takes precedence, remove the existing column.
this.columns.splice(idx, 1);
break;
title: string; // tooltip string
}
+export class GridColumnPersistConf {
+ name: string;
+ flex?: number;
+ sort?: number;
+ align?: string;
+}
+
+export class GridPersistConf {
+ version: number;
+ limit: number;
+ columns: GridColumnPersistConf[];
+}
+
export class GridContext {
pager: Pager;
format: FormatService;
constructor(
- idl: IdlService,
+ idl: IdlService,
org: OrgService,
store: ServerStoreService,
format: FormatService) {
}
}
- // This is called regardless of the presence of saved
+ // This is called regardless of the presence of saved
// settings so defaults can be applied.
this.columnSet.applyColumnSettings(columns);
});
if (!def.col.comparator) {
def.col.comparator = (a, b) => {
- if (a < b) { return -1; }
- if (a > b) { return 1; }
+ if (a < b) { return -1; }
+ if (a > b) { return 1; }
return 0;
};
}
}
}
-export class GridColumnPersistConf {
- name: string;
- flex?: number;
- sort?: number;
- align?: string;
-}
-
-export class GridPersistConf {
- version: number;
- limit: number;
- columns: GridColumnPersistConf[];
-}
-
// Actions apply to specific rows
export class GridToolbarAction {
}
}
- //
+ //
applyPermLimitOrgs(perms: string[]) {
if (!perms) {
// NOTE: If permLimitOrgs is useful in a non-staff context
// we need to change this to support non-staff perm checks.
this.perm.hasWorkPermAt(perms, true).then(permMap => {
- this.permLimitOrgs =
+ this.permLimitOrgs =
// safari-friendly version of Array.flat()
- Object.values(permMap).reduce((acc,val) => acc.concat(val), []);
+ Object.values(permMap).reduce((acc, val) => acc.concat(val), []);
});
}
if (this.permLimitOrgs) {
// Avoid showing org units where the user does
// not have the requested permission.
- orgs = orgs.filter(org =>
+ orgs = orgs.filter(org =>
this.permLimitOrgs.includes(org.id()));
}
ctx: ctx,
resolve: resolve,
reject: reject
- }
+ };
this.pending.push(pend);
processPending() {
const pstring = this.pending[0];
this.strings[pstring.key].resolver(pstring.ctx).then(
- txt => {
+ txt => {
pstring.resolve(txt);
this.pending.shift();
if (this.pending.length) {
/*
Tree Widget:
-<eg-tree
- [tree]="myTree"
- (nodeClicked)="nodeClicked($event)">
-</eg-tree>
+<eg-tree
+ [tree]="myTree"
+ (nodeClicked)="nodeClicked($event)">
+</eg-tree>
----
constructor() {
const rootNode = new TreeNode({
- id: 1,
- label: 'Root',
+ id: 1,
+ label: 'Root',
children: [
new TreeNode({id: 2, label: 'Child'}),
new TreeNode({id: 3, label: 'Child2'})
// Set by the tree.
selected: boolean;
- // Optional link to user-provided stuff.
+ // Optional link to user-provided stuff.
// This field is ignored by the tree.
callerData: any;
const nodes = [];
- const recurseTree =
+ const recurseTree =
(node: TreeNode, depth: number, hidden: boolean) => {
if (!node) { return; }
}
node.children.forEach(n => recurseTree(n, depth, !node.expanded));
- }
+ };
recurseTree(this.rootNode, 0, false);
return nodes;
if (start + size > pcount) {
start = pcount - size + 1;
- if (start < 1) { start = 1 };
+ if (start < 1) { start = 1; }
}
if (start + size > pcount) {
}
const table = schema + '.' + this.route.snapshot.paramMap.get('table');
- // Set the prefix to "server", "local", "workstation",
+ // Set the prefix to "server", "local", "workstation",
// extracted from the URL path.
this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
};
this.workstations.push(ws);
- this.store.setLocalItem('eg.workstation.all', this.workstations)
+ this.store.setLocalItem('eg.workstation.all', this.workstations);
this.newName = '';
// when registering our first workstation, mark it as the
// default and show it as selected in the ws selector.
this.renderer.selectRootElement('#username').focus();
this.workstations = this.store.getLocalItem('eg.workstation.all');
- this.args.workstation =
+ this.args.workstation =
this.store.getLocalItem('eg.workstation.default');
this.applyWorkstation();
}
err => {},
() => {
this.currentLocale = this.locales.filter(
- l => l.code() === this.locale.currentLocaleCode())[0]
+ l => l.code() === this.locale.currentLocaleCode())[0];
}
);
}
// Ditto includeOrgAncestors, but descendants.
@Input() includeOrgDescendants: boolean;
- // Optional grid persist key. This is the part of the key
+ // Optional grid persist key. This is the part of the key
// following eg.grid.
@Input() persistKey: string;
- // Optional path component to add to the generated grid persist key,
- // formatted as (for example):
+ // Optional path component to add to the generated grid persist key,
+ // formatted as (for example):
// 'eg.grid.admin.${persistKeyPfx}.config.billing_type'
@Input() persistKeyPfx: string;
this.idlClassDef = this.idl.classes[this.idlClass];
this.pkeyField = this.idlClassDef.pkey || 'id';
- this.translatableFields =
+ this.translatableFields =
this.idlClassDef.fields.filter(f => f.i18n).map(f => f.name);
if (!this.persistKey) {
- this.persistKey =
- 'admin.' +
- (this.persistKeyPfx ? this.persistKeyPfx + '.' : '') +
+ this.persistKey =
+ 'admin.' +
+ (this.persistKeyPfx ? this.persistKeyPfx + '.' : '') +
this.idlClassDef.table;
}
- // Limit the view org selector to orgs where the user has
+ // Limit the view org selector to orgs where the user has
// permacrud-encoded view permissions.
const pc = this.idlClassDef.permacrud;
if (pc && pc.retrieve) {
this.translateFieldIdx = 0;
}
- this.translator.idlObject =
+ this.translator.idlObject =
this.dataSource.data[this.translateRowIdx];
- this.translator.fieldName =
+ this.translator.fieldName =
this.translatableFields[this.translateFieldIdx];
- }
+ };
this.translator.prevString = () => {
this.translateFieldIdx = 0;
}
- this.translator.idlObject =
+ this.translator.idlObject =
this.dataSource.data[this.translateRowIdx];
- this.translator.fieldName =
+ this.translator.fieldName =
this.translatableFields[this.translateFieldIdx];
- }
+ };
- this.translator.open({size:'lg'});
- }
+ this.translator.open({size: 'lg'});
+ };
}
checkCreatePerms() {
this.existingTranslation = null;
this.pcrud.search('i18n', {
- translation: this.selectedLocale,
- fq_field : this.fqField(),
+ translation: this.selectedLocale,
+ fq_field : this.fqField(),
identity_value: this.identValue()
}).subscribe(tr => {
this.existingTranslation = tr;
}
translate() {
- if (!this.translatedValue) return;
+ if (!this.translatedValue) { return; }
+
+ let entry;
if (this.existingTranslation) {
- const entry = this.existingTranslation;
+ entry = this.existingTranslation;
entry.string(this.translatedValue);
this.pcrud.update(entry).toPromise().then(
return;
}
- const entry = this.idl.create('i18n');
+ entry = this.idl.create('i18n');
entry.fq_field(this.fqField());
entry.identity_value(this.identValue());
entry.translation(this.selectedLocale);
*/
// Route to AngularJS / TPAC catalog
- window.location.href =
+ window.location.href =
'/eg/staff/cat/catalog/results?query=' +
encodeURIComponent(this.catSearchQuery);
}