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}}"></eg-admin-page>
20 export class BasicAdminPageComponent implements OnInit {
24 persistKeyPfx: string;
28 private route: ActivatedRoute,
29 private idl: IdlService
34 let schema = this.route.snapshot.paramMap.get('schema');
36 // Allow callers to pass the schema via static route data
37 const data = this.route.snapshot.data[0];
38 if (data) { schema = data.schema; }
40 let table = this.route.snapshot.paramMap.get('table');
42 const data = this.route.snapshot.data[0];
43 if (data) { table = data.table; }
45 const fullTable = schema + '.' + table;
47 // Set the prefix to "server", "local", "workstation",
48 // extracted from the URL path.
49 // For admin pages that use none of these, avoid setting
50 // the prefix because that will cause it to double-up.
51 // e.g. eg.grid.acq.acq.cancel_reason
52 this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
53 const selfPrefixers = ['acq', 'booking'];
54 if (selfPrefixers.indexOf(this.persistKeyPfx) > -1) {
55 // ACQ is a special case, because unlike 'server', 'local',
56 // 'workstation', the schema ('acq') is the root of the path.
57 this.persistKeyPfx = '';
60 // Pass the readonlyFields param if available
61 if (this.route.snapshot.data &&
62 this.route.snapshot.data.length &&
63 this.route.snapshot.data[0].readonlyFields) {
64 this.readonlyFields = this.route.snapshot.data[0].readonlyFields;
68 Object.keys(this.idl.classes).forEach(class_ => {
69 const classDef = this.idl.classes[class_];
70 if (classDef.table === fullTable) {
71 this.idlClass = class_;
72 this.classLabel = classDef.label;
77 throw new Error('Unable to find IDL class for table ' + fullTable);