rsanchez
2017-03-22 60c65f2110f65221bc3a71b2887667e78c53c53e
securis/src/main/webapp/src/app/listing/pack.list.component.ts
....@@ -1,4 +1,5 @@
11 import { Router, ActivatedRoute } from '@angular/router';
2
+import { ToastsManager } from 'ng2-toastr/ng2-toastr';
23 import { MdDialog, MdDialogConfig } from '@angular/material';
34 import {
45 ITdDataTableColumn,
....@@ -10,7 +11,7 @@
1011 import { IPageChangeEvent } from '@covalent/core';
1112 import { Component, ViewChild, AfterViewInit } from '@angular/core';
1213 import { TdMediaService } from '@covalent/core';
13
-import { PacksService } from '../resources/packs';
14
+import { PacksService, PACK_ACTIONS } from '../resources/packs';
1415 import { PackFormComponent } from '../forms/pack.form.component';
1516 import { LocaleService } from '../common/i18n';
1617 import { ListingBase } from './base';
....@@ -57,17 +58,11 @@
5758 { name: 'licensetype_code', label: 'License type' },
5859 { name: 'organization_name', label: 'Organization' },
5960 { name: 'used_licenses', label: 'Licenses', tooltip: 'Initial/Available pack licenses' },
61
+ { name: 'status', label: 'Status', tooltip: 'Pack status' },
6062 { name: 'menu', label: '' }
6163 ];
6264
63
- pack_menu_options : any[] = [{
64
- command: 'edit',
65
- name: 'Edit'
66
- },{
67
- command: 'cancel',
68
- name: 'Cancel'
69
- }]
70
-
65
+ pack_menu_options = PACK_ACTIONS;
7166
7267 constructor(_dataTableService: TdDataTableService,
7368 private media: TdMediaService,
....@@ -75,25 +70,30 @@
7570 private route: ActivatedRoute,
7671 private dialog: MdDialog,
7772 private $L: LocaleService,
73
+ private toaster: ToastsManager,
7874 private packForm: PackFormComponent,
7975 private packs: PacksService) {
8076 super(_dataTableService);
81
- this.packs.get().subscribe(
82
- (list : any[]) => {
83
- this.data = list;
84
- this.refresh();
85
- },
86
- (err: any) => console.error(err)
87
- );
8877 }
8978
90
-
91
- packAction(action: any) {
92
- console.log(action.command);
79
+ reload() : void {
80
+ this.packs.get().subscribe(
81
+ (list : any[]) => {
82
+ this.data = list;
83
+ this.refresh();
84
+ },
85
+ (err: any) => console.error(err)
86
+ );
9387 }
9488
95
- isActionAvailable(pack : any) : boolean {
96
- return true;
89
+ packAction(action: string, pack: any) {
90
+ return this.packs[action](pack.id).subscribe(
91
+ (actionResponse : any) => {
92
+ this.toaster.success(this.$L.get('Action "{}" executed successfully', action));
93
+ this.reload();
94
+ },
95
+ (err : any) => this.toaster.error(this.$L.get('Action "{}" failed', action))
96
+ );
9797 }
9898
9999 showLicenses(pack: any) : void {
....@@ -115,8 +115,8 @@
115115 }
116116
117117 ngAfterViewInit(): void {
118
+ this.reload();
118119 this.media.broadcast();
119
-
120120 }
121121 }
122122