From 60c65f2110f65221bc3a71b2887667e78c53c53e Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Wed, 22 Mar 2017 17:44:16 +0000
Subject: [PATCH] #3527 fix - Added pack/license actions and a lot of bugfixing

---
 securis/src/main/webapp/src/app/listing/license.list.component.ts |   65 +++++++++++++++++---------------
 1 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/securis/src/main/webapp/src/app/listing/license.list.component.ts b/securis/src/main/webapp/src/app/listing/license.list.component.ts
index 4783054..843f985 100644
--- a/securis/src/main/webapp/src/app/listing/license.list.component.ts
+++ b/securis/src/main/webapp/src/app/listing/license.list.component.ts
@@ -5,9 +5,10 @@
 import { Component, AfterViewInit, ViewChild } from '@angular/core';
 import { TdMediaService } from '@covalent/core';
 import { Location } from '@angular/common';
+import { ToastsManager } from 'ng2-toastr/ng2-toastr';
 
 import { LocaleService } from '../common/i18n';
-import { LicensesService } from '../resources/licenses';
+import { LicensesService, LICENSE_ACTIONS } from '../resources/licenses';
 import { PacksService } from '../resources/packs';
 import { LicenseFormComponent } from '../forms/license.form.component';
 import { ListingBase } from './base';
@@ -43,22 +44,30 @@
     { name: 'menu', label: '' }
   ];
 
-  license_menu_options : any[] = [{
-    icon: 'edit',
-    command: 'edit',
-    name: 'Edit'
-  },{
-    icon: 'cancel',
-    command: 'cancel',
-    name: 'Cancel'
-  }]
+  license_menu_options = LICENSE_ACTIONS;
   
-  licenseAction(action: any) {
-    console.log(action.command);
+  licenseAction(action: string, license: any) {
+    return this.licenses[action](license.id).subscribe(
+      (actionResponse : any) => {
+        this.toaster.success(this.$L.get('Action "{}" executed successfully', action));
+        this.reload(this.pack.id);
+      },
+      (err : any) => this.toaster.error(this.$L.get('Action "{}" failed', action))
+    );
   }
 
-  isActionAvailable(pack : any) : boolean {
-    return true;
+  reload(packId: number) : void  {
+      this.licenses.getByPack(packId).subscribe(
+        list => {
+          this.data = list;
+          this.refresh();
+        },
+        err => console.error(err)
+      );
+  }
+
+  isActionAvailable(action: string, license : any) : boolean {
+    return this.licenses.isActionAvailable(action, license);
   }
 
   constructor( _dataTableService: TdDataTableService,
@@ -66,6 +75,7 @@
     private $L: LocaleService,
     private router: Router,
     private location: Location,
+    private toaster: ToastsManager,
     private route: ActivatedRoute,
     private dialog: MdDialog,
     private licenseForm: LicenseFormComponent,
@@ -75,22 +85,6 @@
   }
 
   ngOnInit(): void {
-    this.route.params.subscribe(params => {
-        var packId = +params['packId']; // (+) converts string 'id' to a number
-        this.licenses.getByPack(packId).subscribe(
-          list => {
-            this.data = list;
-            this.refresh();
-          },
-          err => console.error(err)
-        );
-        this.packs.get(packId).subscribe(
-          packData => {
-            this.pack = packData;
-          },
-          err => console.error(err)
-        );
-      });
   }
 
   goBack() : void {
@@ -111,7 +105,16 @@
 
   ngAfterViewInit(): void {
     this.media.broadcast();
-
+    this.route.params.subscribe(params => {
+        var packId = +params['packId']; // (+) converts string 'id' to a number
+        this.reload(packId);
+        this.packs.get(packId).subscribe(
+          packData => {
+            this.pack = packData;
+          },
+          err => console.error(err)
+        );
+      });
   }
 }
 

--
Gitblit v1.3.2