]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/basic-admin-page.component.ts
84219f13386ed9c0244f4e92cbe08dc31bf4877b
[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-staff-banner bannerText="{{classLabel}} Configuration" i18n-bannerText>
12       </eg-staff-banner>
13       <eg-admin-page persistKeyPfx="{{persistKeyPfx}}" idlClass="{{idlClass}}" readonlyFields="{{readonlyFields}}"></eg-admin-page>
14     `
15 })
16
17 export class BasicAdminPageComponent implements OnInit {
18
19     idlClass: string;
20     classLabel: string;
21     persistKeyPfx: string;
22     readonlyFields = '';
23
24     constructor(
25         private route: ActivatedRoute,
26         private idl: IdlService
27     ) {
28     }
29
30     ngOnInit() {
31         let schema = this.route.snapshot.paramMap.get('schema');
32         if (!schema) {
33             // Allow callers to pass the schema via static route data
34             const data = this.route.snapshot.data[0];
35             if (data) { schema = data.schema; }
36         }
37         let table = this.route.snapshot.paramMap.get('table');
38         if (!table) {
39             const data = this.route.snapshot.data[0];
40             if (data) { table = data.table; }
41         }
42         const fullTable = schema + '.' + table;
43
44         // Set the prefix to "server", "local", "workstation",
45         // extracted from the URL path.
46         // For admin pages that use none of these, avoid setting
47         // the prefix because that will cause it to double-up.
48         // e.g. eg.grid.acq.acq.cancel_reason
49         this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
50         const selfPrefixers = ['acq', 'booking'];
51         if (selfPrefixers.indexOf(this.persistKeyPfx) > -1) {
52             // ACQ is a special case, because unlike 'server', 'local',
53             // 'workstation', the schema ('acq') is the root of the path.
54             this.persistKeyPfx = '';
55         }
56
57         // Pass the readonlyFields param if available
58         if (this.route.snapshot.data[0].readonlyFields) {
59             this.readonlyFields = this.route.snapshot.data[0].readonlyFields;
60         }
61
62
63         Object.keys(this.idl.classes).forEach(class_ => {
64             const classDef = this.idl.classes[class_];
65             if (classDef.table === fullTable) {
66                 this.idlClass = class_;
67                 this.classLabel = classDef.label;
68             }
69         });
70
71         if (!this.idlClass) {
72             throw new Error('Unable to find IDL class for table ' + fullTable);
73         }
74     }
75 }
76
77