]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/basic-admin-page.component.ts
LP1809288: Add workstation grid settings for booking admin
[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-staff-banner bannerText="{{classLabel}} Configuration" i18n-bannerText>
12       </eg-staff-banner>
13       <eg-admin-page persistKeyPfx="{{persistKeyPfx}}" idlClass="{{idlClass}}"></eg-admin-page>
14     `
15 })
16
17 export class BasicAdminPageComponent implements OnInit {
18
19     idlClass: string;
20     classLabel: string;
21     persistKeyPfx: string;
22
23     constructor(
24         private route: ActivatedRoute,
25         private idl: IdlService
26     ) {
27     }
28
29     ngOnInit() {
30         let schema = this.route.snapshot.paramMap.get('schema');
31         if (!schema) {
32             // Allow callers to pass the schema via static route data
33             const data = this.route.snapshot.data[0];
34             if (data) { schema = data.schema; }
35         }
36         const table = schema + '.' + this.route.snapshot.paramMap.get('table');
37
38         // Set the prefix to "server", "local", "workstation",
39         // extracted from the URL path.
40         this.persistKeyPfx = this.route.snapshot.parent.url[0].path;
41         if (this.persistKeyPfx === 'acq') {
42             // ACQ is a special case, becaus unlike 'server', 'local',
43             // 'workstation', the schema ('acq') is the root of the path.
44             this.persistKeyPfx = '';
45         }
46
47         Object.keys(this.idl.classes).forEach(class_ => {
48             const classDef = this.idl.classes[class_];
49             if (classDef.table === table) {
50                 this.idlClass = class_;
51                 this.classLabel = classDef.label;
52             }
53         });
54
55         if (!this.idlClass) {
56             throw new Error('Unable to find IDL class for table ' + table);
57         }
58     }
59 }
60
61