1 import {Component, OnInit} from '@angular/core';
2 import {ActivatedRoute, ParamMap} from '@angular/router';
3 import {IdlService} from '@eg/core/idl.service';
4 import {Observable} from 'rxjs';
5 import {tap, switchMap} from 'rxjs/operators';
8 * Generic IDL class editor page.
13 <ng-container *ngIf="idlClass">
14 <eg-title i18n-prefix prefix="{{classLabel}} Administration">
16 <eg-staff-banner bannerText="{{classLabel}} Configuration" i18n-bannerText>
18 <eg-admin-page persistKeyPfx="{{persistKeyPfx}}" idlClass="{{idlClass}}"
19 configLinkBasePath="{{configLinkBasePath}}"
20 readonlyFields="{{readonlyFields}}"
21 [disableOrgFilter]="disableOrgFilter"></eg-admin-page>
26 export class BasicAdminPageComponent implements OnInit {
30 persistKeyPfx: string;
32 configLinkBasePath = '/staff/admin';
34 // Tell the admin page to disable and hide the automagic org unit filter
35 disableOrgFilter: boolean;
37 private getParams$: Observable<ParamMap>;
38 private getRouteData$: Observable<any>;
39 private getParentUrl$: Observable<any>;
41 private schema: string;
42 private table: string;
45 private route: ActivatedRoute,
46 private idl: IdlService
51 this.getParams$ = this.route.paramMap
53 this.schema = params.get('schema');
54 this.table = params.get('table');
57 this.getRouteData$ = this.route.data
58 .pipe(tap(routeData => {
59 const data = routeData[0];
62 // Schema and table can both be passed
63 // by either param or data
65 this.schema = data['schema'];
68 this.table = data['table'];
70 this.disableOrgFilter = data['disableOrgFilter'];
71 this.readonlyFields = data['readonlyFields'];
76 this.getParentUrl$ = this.route.parent.url
77 .pipe(tap(parentUrl => {
78 // Set the prefix to "server", "local", "workstation",
79 // extracted from the URL path.
80 // For admin pages that use none of these, avoid setting
81 // the prefix because that will cause it to double-up.
82 // e.g. eg.grid.acq.acq.cancel_reason
83 this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
84 const selfPrefixers = ['acq', 'action_trigger', 'booking'];
85 if (selfPrefixers.indexOf(this.persistKeyPfx) > -1) {
86 // selfPrefixers, unlike 'server', 'local', and
87 // 'workstation', are the root of the path.
88 this.persistKeyPfx = '';
90 this.configLinkBasePath += '/' + this.persistKeyPfx;
94 this.getParentUrl$.subscribe();
96 switchMap(() => this.getRouteData$)
98 const fullTable = this.schema + '.' + this.table;
100 Object.keys(this.idl.classes).forEach(class_ => {
101 const classDef = this.idl.classes[class_];
102 if (classDef.table === fullTable) {
103 this.idlClass = class_;
104 this.classLabel = classDef.label;
108 if (!this.idlClass) {
109 throw new Error('Unable to find IDL class for table ' + fullTable);