]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/basic-admin-page.component.ts
LP#1847800 / LP#1834687: secondary admin pages: config_field attribute in IDL
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / admin / basic-admin-page.component.ts
1 import {Component, OnInit} from '@angular/core';
2 import {ActivatedRoute} from '@angular/router';
3 import {IdlService} from '@eg/core/idl.service';
4
5 /**
6  * Generic IDL class editor page.
7  */
8
9 @Component({
10     template: `
11       <eg-title i18n-prefix prefix="{{classLabel}} Administration">
12       </eg-title>
13       <eg-staff-banner bannerText="{{classLabel}} Configuration" i18n-bannerText>
14       </eg-staff-banner>
15       <eg-admin-page persistKeyPfx="{{persistKeyPfx}}" idlClass="{{idlClass}}"
16         readonlyFields="{{readonlyFields}}"
17         [disableOrgFilter]="disableOrgFilter"></eg-admin-page>
18     `
19 })
20
21 export class BasicAdminPageComponent implements OnInit {
22
23     idlClass: string;
24     classLabel: string;
25     persistKeyPfx: string;
26     readonlyFields = '';
27
28     // Tell the admin page to disable and hide the automagic org unit filter
29     disableOrgFilter: boolean;
30
31     constructor(
32         private route: ActivatedRoute,
33         private idl: IdlService
34     ) {
35     }
36
37     ngOnInit() {
38         let schema = this.route.snapshot.paramMap.get('schema');
39         if (!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; }
43         }
44         let table = this.route.snapshot.paramMap.get('table');
45         if (!table) {
46             const data = this.route.snapshot.data[0];
47             if (data) { table = data.table; }
48         }
49         const fullTable = schema + '.' + table;
50
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 = '';
62         }
63
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];
68
69             if (data.readonlyFields) {
70                 this.readonlyFields = data.readonlyFields;
71             }
72
73             if (data.disableOrgFilter) {
74                 this.disableOrgFilter = true;
75             }
76         }
77
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;
83             }
84         });
85
86         if (!this.idlClass) {
87             throw new Error('Unable to find IDL class for table ' + fullTable);
88         }
89     }
90 }
91
92