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