1 import {Component, OnInit} from '@angular/core';
2 import {ActivatedRoute} from '@angular/router';
3 import {IdlService} from '@eg/core/idl.service';
6 * Generic IDL class editor page.
11 <eg-title i18n-prefix prefix="{{classLabel}} Administration">
13 <eg-staff-banner bannerText="{{classLabel}} Configuration" i18n-bannerText>
15 <eg-admin-page persistKeyPfx="{{persistKeyPfx}}" idlClass="{{idlClass}}"
16 configLinkBasePath="{{configLinkBasePath}}"
17 readonlyFields="{{readonlyFields}}"
18 [disableOrgFilter]="disableOrgFilter"></eg-admin-page>
22 export class BasicAdminPageComponent implements OnInit {
26 persistKeyPfx: string;
28 configLinkBasePath = '/staff/admin';
30 // Tell the admin page to disable and hide the automagic org unit filter
31 disableOrgFilter: boolean;
34 private route: ActivatedRoute,
35 private idl: IdlService
40 let schema = this.route.snapshot.paramMap.get('schema');
42 // Allow callers to pass the schema via static route data
43 const data = this.route.snapshot.data[0];
44 if (data) { schema = data.schema; }
46 let table = this.route.snapshot.paramMap.get('table');
48 const data = this.route.snapshot.data[0];
49 if (data) { table = data.table; }
51 const fullTable = schema + '.' + table;
53 // Set the prefix to "server", "local", "workstation",
54 // extracted from the URL path.
55 // For admin pages that use none of these, avoid setting
56 // the prefix because that will cause it to double-up.
57 // e.g. eg.grid.acq.acq.cancel_reason
58 this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
59 const selfPrefixers = ['acq', 'action_trigger', 'booking'];
60 if (selfPrefixers.indexOf(this.persistKeyPfx) > -1) {
61 // selfPrefixers, unlike 'server', 'local', and
62 // 'workstation', are the root of the path.
63 this.persistKeyPfx = '';
65 this.configLinkBasePath += '/' + this.persistKeyPfx;
68 // Pass the readonlyFields param if available
69 if (this.route.snapshot.data && this.route.snapshot.data[0]) {
70 // snapshot.data is a HASH.
71 const data = this.route.snapshot.data[0];
73 if (data.readonlyFields) {
74 this.readonlyFields = data.readonlyFields;
77 if (data.disableOrgFilter) {
78 this.disableOrgFilter = true;
82 Object.keys(this.idl.classes).forEach(class_ => {
83 const classDef = this.idl.classes[class_];
84 if (classDef.table === fullTable) {
85 this.idlClass = class_;
86 this.classLabel = classDef.label;
91 throw new Error('Unable to find IDL class for table ' + fullTable);