]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/basic-admin-page.component.ts
LP1847800 Admin grids support config_field links
[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         configLinkBasePath="{{configLinkBasePath}}"
17         readonlyFields="{{readonlyFields}}"
18         [disableOrgFilter]="disableOrgFilter"></eg-admin-page>
19     `
20 })
21
22 export class BasicAdminPageComponent implements OnInit {
23
24     idlClass: string;
25     classLabel: string;
26     persistKeyPfx: string;
27     readonlyFields = '';
28     configLinkBasePath = '/staff/admin';
29
30     // Tell the admin page to disable and hide the automagic org unit filter
31     disableOrgFilter: boolean;
32
33     constructor(
34         private route: ActivatedRoute,
35         private idl: IdlService
36     ) {
37     }
38
39     ngOnInit() {
40         let schema = this.route.snapshot.paramMap.get('schema');
41         if (!schema) {
42             // Allow callers to pass the schema via static route data
43             const data = this.route.snapshot.data[0];
44             if (data) { schema = data.schema; }
45         }
46         let table = this.route.snapshot.paramMap.get('table');
47         if (!table) {
48             const data = this.route.snapshot.data[0];
49             if (data) { table = data.table; }
50         }
51         const fullTable = schema + '.' + table;
52
53         // Set the prefix to "server", "local", "workstation",
54         // extracted from the URL path.
55         // For admin pages that use none of these, avoid setting
56         // the prefix because that will cause it to double-up.
57         // e.g. eg.grid.acq.acq.cancel_reason
58         this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
59         const selfPrefixers = ['acq', 'booking'];
60         if (selfPrefixers.indexOf(this.persistKeyPfx) > -1) {
61             // ACQ is a special case, because unlike 'server', 'local',
62             // 'workstation', the schema ('acq') is the root of the path.
63             this.persistKeyPfx = '';
64         } else {
65             this.configLinkBasePath += '/' + this.persistKeyPfx;
66         }
67
68         // Pass the readonlyFields param if available
69         if (this.route.snapshot.data && this.route.snapshot.data[0]) {
70             // snapshot.data is a HASH.
71             const data = this.route.snapshot.data[0];
72
73             if (data.readonlyFields) {
74                 this.readonlyFields = data.readonlyFields;
75             }
76
77             if (data.disableOrgFilter) {
78                 this.disableOrgFilter = true;
79             }
80         }
81
82         Object.keys(this.idl.classes).forEach(class_ => {
83             const classDef = this.idl.classes[class_];
84             if (classDef.table === fullTable) {
85                 this.idlClass = class_;
86                 this.classLabel = classDef.label;
87             }
88         });
89
90         if (!this.idlClass) {
91             throw new Error('Unable to find IDL class for table ' + fullTable);
92         }
93     }
94 }
95
96