]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/basic-admin-page.component.ts
LP1813647 Titles for Angular admin and splash page
[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}}"></eg-admin-page>
17     `
18 })
19
20 export class BasicAdminPageComponent implements OnInit {
21
22     idlClass: string;
23     classLabel: string;
24     persistKeyPfx: string;
25     readonlyFields = '';
26
27     constructor(
28         private route: ActivatedRoute,
29         private idl: IdlService
30     ) {
31     }
32
33     ngOnInit() {
34         let schema = this.route.snapshot.paramMap.get('schema');
35         if (!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; }
39         }
40         let table = this.route.snapshot.paramMap.get('table');
41         if (!table) {
42             const data = this.route.snapshot.data[0];
43             if (data) { table = data.table; }
44         }
45         const fullTable = schema + '.' + table;
46
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 = '';
58         }
59
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;
65         }
66
67
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;
73             }
74         });
75
76         if (!this.idlClass) {
77             throw new Error('Unable to find IDL class for table ' + fullTable);
78         }
79     }
80 }
81
82