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-staff-banner bannerText="{{classLabel}} Configuration" i18n-bannerText>
13 <eg-admin-page persistKeyPfx="{{persistKeyPfx}}" idlClass="{{idlClass}}" readonlyFields="{{readonlyFields}}"></eg-admin-page>
17 export class BasicAdminPageComponent implements OnInit {
21 persistKeyPfx: string;
25 private route: ActivatedRoute,
26 private idl: IdlService
31 let schema = this.route.snapshot.paramMap.get('schema');
33 // Allow callers to pass the schema via static route data
34 const data = this.route.snapshot.data[0];
35 if (data) { schema = data.schema; }
37 let table = this.route.snapshot.paramMap.get('table');
39 const data = this.route.snapshot.data[0];
40 if (data) { table = data.table; }
42 const fullTable = schema + '.' + table;
44 // Set the prefix to "server", "local", "workstation",
45 // extracted from the URL path.
46 // For admin pages that use none of these, avoid setting
47 // the prefix because that will cause it to double-up.
48 // e.g. eg.grid.acq.acq.cancel_reason
49 this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
50 const selfPrefixers = ['acq', 'booking'];
51 if (selfPrefixers.indexOf(this.persistKeyPfx) > -1) {
52 // ACQ is a special case, because unlike 'server', 'local',
53 // 'workstation', the schema ('acq') is the root of the path.
54 this.persistKeyPfx = '';
57 // Pass the readonlyFields param if available
58 if (this.route.snapshot.data &&
59 this.route.snapshot.data.length &&
60 this.route.snapshot.data[0].readonlyFields) {
61 this.readonlyFields = this.route.snapshot.data[0].readonlyFields;
65 Object.keys(this.idl.classes).forEach(class_ => {
66 const classDef = this.idl.classes[class_];
67 if (classDef.table === fullTable) {
68 this.idlClass = class_;
69 this.classLabel = classDef.label;
74 throw new Error('Unable to find IDL class for table ' + fullTable);