From a6e1ace2b6bdba8c08a4acfa42433f3ac073b747 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Tue, 21 Mar 2017 10:16:22 +0000
Subject: [PATCH] #3527 feature - Added all catalogs and working fine

---
 securis/src/main/webapp/src/app/forms/licensetype.form.component.ts |   59 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/securis/src/main/webapp/src/app/forms/licensetype.form.component.ts b/securis/src/main/webapp/src/app/forms/licensetype.form.component.ts
index 03d66e2..2a459cd 100644
--- a/securis/src/main/webapp/src/app/forms/licensetype.form.component.ts
+++ b/securis/src/main/webapp/src/app/forms/licensetype.form.component.ts
@@ -10,26 +10,25 @@
 import { FormBase, IComboOption } from './base';
 import { ActivatedRoute, Router } from '@angular/router';
 
-var app_example = { 
-	code: 'CICS',
-  creation_timestamp: 1418384439000,
-  description: 'Wellbore integrity analysis software',
+var lt_example = { 
   id: 1,
-  license_filename: 'config_server.lic',
-  name: 'CurisIntegrity',
-  metadata: 
-   [ { key: 'max_docs',
-       value: '250000',
-       readonly: true,
-       mandatory: true } ] 
+  code: 'CI01',
+  name: 'CI ConfigServer ext',
+  application_id: 1,
+  application_name: 'CurisIntegrity',
+  creation_timestamp: 1418384535000,
+  description: 'CI ConfigServer with extended mode and 50 lines',
+  metadata: [ { key: 'max_docs', value: '250000', mandatory: true } ] 
 }
+
 
 @Component({
   selector: 'licensetype-form',
   templateUrl: 'src/app/forms/licensetype.form.html'
 })
 export class LicenseTypeFormComponent extends FormBase {
-
+  
+  allApplications: IComboOption[];
   constructor(private http: Http,
               private licenseTypes: LicenseTypesService,
               private applications: ApplicationsService,
@@ -41,17 +40,47 @@
     super($L, router, route, toaster, licenseTypes, $L.get('license type'), dialogs);
   }
 
- 
+  private _prepareMetadata(metadata : any[]) : any[] {
+    metadata.forEach((md : any) => {
+        if (md.value !== null && md.value !== '') {
+          md.readonly = true;
+        }
+      });
+    return metadata;
+  }
+
+  changeApplication(event: any) : void{
+    console.log(event);
+    this.applications.get(this.data.application_id)
+        .map(app_data => this._prepareMetadata(app_data.metadata))
+        .subscribe(
+          metadata => this.data.metadata = metadata,
+          err => console.error('Error loading application metadata')
+        );
+  }
+
+
+
+  loadCombos() : void {
+      this.applications.get()
+        .map(list => list.map((app : any) => <IComboOption>{id: app.id, label: `(${app.code}) ${app.name}`}))
+        .subscribe(
+          data => this.allApplications = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
+          err => console.error('Error loading applications')
+        );
+  }
+
   goBack(): void {
     this.router.navigate([`licensetypes`]);
   }
 
   init() : void {
+    this.loadCombos();
     super.setFirstFocus();
     super.reset();
-    super.prepareInitialData('licenseTypeId', {
+    super.prepareInitialData('licensetypeId', {
       metadata: []
-    });
+    }, (data) => this._prepareMetadata(data.metadata));
   }
  
   ngAfterViewInit(): void {

--
Gitblit v1.3.2