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 readonlyFields="{{readonlyFields}}"
17 [disableOrgFilter]="disableOrgFilter"></eg-admin-page>
21 export class BasicAdminPageComponent implements OnInit {
25 persistKeyPfx: string;
28 // Tell the admin page to disable and hide the automagic org unit filter
29 disableOrgFilter: boolean;
32 private route: ActivatedRoute,
33 private idl: IdlService
38 let schema = this.route.snapshot.paramMap.get('schema');
40 // Allow callers to pass the schema via static route data
41 const data = this.route.snapshot.data[0];
42 if (data) { schema = data.schema; }
44 let table = this.route.snapshot.paramMap.get('table');
46 const data = this.route.snapshot.data[0];
47 if (data) { table = data.table; }
49 const fullTable = schema + '.' + table;
51 // Set the prefix to "server", "local", "workstation",
52 // extracted from the URL path.
53 // For admin pages that use none of these, avoid setting
54 // the prefix because that will cause it to double-up.
55 // e.g. eg.grid.acq.acq.cancel_reason
56 this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
57 const selfPrefixers = ['acq', 'booking'];
58 if (selfPrefixers.indexOf(this.persistKeyPfx) > -1) {
59 // ACQ is a special case, because unlike 'server', 'local',
60 // 'workstation', the schema ('acq') is the root of the path.
61 this.persistKeyPfx = '';
64 // Pass the readonlyFields param if available
65 if (this.route.snapshot.data && this.route.snapshot.data[0]) {
66 // snapshot.data is a HASH.
67 const data = this.route.snapshot.data[0];
69 if (data.readonlyFields) {
70 this.readonlyFields = data.readonlyFields;
73 if (data.disableOrgFilter) {
74 this.disableOrgFilter = true;
78 Object.keys(this.idl.classes).forEach(class_ => {
79 const classDef = this.idl.classes[class_];
80 if (classDef.table === fullTable) {
81 this.idlClass = class_;
82 this.classLabel = classDef.label;
87 throw new Error('Unable to find IDL class for table ' + fullTable);