rsanchez
2017-03-21 a6e1ace2b6bdba8c08a4acfa42433f3ac073b747
securis/src/main/webapp/src/app/forms/licensetype.form.component.ts
....@@ -10,26 +10,25 @@
1010 import { FormBase, IComboOption } from './base';
1111 import { ActivatedRoute, Router } from '@angular/router';
1212
13
-var app_example = {
14
- code: 'CICS',
15
- creation_timestamp: 1418384439000,
16
- description: 'Wellbore integrity analysis software',
13
+var lt_example = {
1714 id: 1,
18
- license_filename: 'config_server.lic',
19
- name: 'CurisIntegrity',
20
- metadata:
21
- [ { key: 'max_docs',
22
- value: '250000',
23
- readonly: true,
24
- mandatory: true } ]
15
+ code: 'CI01',
16
+ name: 'CI ConfigServer ext',
17
+ application_id: 1,
18
+ application_name: 'CurisIntegrity',
19
+ creation_timestamp: 1418384535000,
20
+ description: 'CI ConfigServer with extended mode and 50 lines',
21
+ metadata: [ { key: 'max_docs', value: '250000', mandatory: true } ]
2522 }
23
+
2624
2725 @Component({
2826 selector: 'licensetype-form',
2927 templateUrl: 'src/app/forms/licensetype.form.html'
3028 })
3129 export class LicenseTypeFormComponent extends FormBase {
32
-
30
+
31
+ allApplications: IComboOption[];
3332 constructor(private http: Http,
3433 private licenseTypes: LicenseTypesService,
3534 private applications: ApplicationsService,
....@@ -41,17 +40,47 @@
4140 super($L, router, route, toaster, licenseTypes, $L.get('license type'), dialogs);
4241 }
4342
44
-
43
+ private _prepareMetadata(metadata : any[]) : any[] {
44
+ metadata.forEach((md : any) => {
45
+ if (md.value !== null && md.value !== '') {
46
+ md.readonly = true;
47
+ }
48
+ });
49
+ return metadata;
50
+ }
51
+
52
+ changeApplication(event: any) : void{
53
+ console.log(event);
54
+ this.applications.get(this.data.application_id)
55
+ .map(app_data => this._prepareMetadata(app_data.metadata))
56
+ .subscribe(
57
+ metadata => this.data.metadata = metadata,
58
+ err => console.error('Error loading application metadata')
59
+ );
60
+ }
61
+
62
+
63
+
64
+ loadCombos() : void {
65
+ this.applications.get()
66
+ .map(list => list.map((app : any) => <IComboOption>{id: app.id, label: `(${app.code}) ${app.name}`}))
67
+ .subscribe(
68
+ data => this.allApplications = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
69
+ err => console.error('Error loading applications')
70
+ );
71
+ }
72
+
4573 goBack(): void {
4674 this.router.navigate([`licensetypes`]);
4775 }
4876
4977 init() : void {
78
+ this.loadCombos();
5079 super.setFirstFocus();
5180 super.reset();
52
- super.prepareInitialData('licenseTypeId', {
81
+ super.prepareInitialData('licensetypeId', {
5382 metadata: []
54
- });
83
+ }, (data) => this._prepareMetadata(data.metadata));
5584 }
5685
5786 ngAfterViewInit(): void {