rsanchez
2017-03-22 60c65f2110f65221bc3a71b2887667e78c53c53e
securis/src/main/webapp/src/app/listing/license.list.component.ts
....@@ -5,9 +5,10 @@
55 import { Component, AfterViewInit, ViewChild } from '@angular/core';
66 import { TdMediaService } from '@covalent/core';
77 import { Location } from '@angular/common';
8
+import { ToastsManager } from 'ng2-toastr/ng2-toastr';
89
910 import { LocaleService } from '../common/i18n';
10
-import { LicensesService } from '../resources/licenses';
11
+import { LicensesService, LICENSE_ACTIONS } from '../resources/licenses';
1112 import { PacksService } from '../resources/packs';
1213 import { LicenseFormComponent } from '../forms/license.form.component';
1314 import { ListingBase } from './base';
....@@ -43,22 +44,30 @@
4344 { name: 'menu', label: '' }
4445 ];
4546
46
- license_menu_options : any[] = [{
47
- icon: 'edit',
48
- command: 'edit',
49
- name: 'Edit'
50
- },{
51
- icon: 'cancel',
52
- command: 'cancel',
53
- name: 'Cancel'
54
- }]
47
+ license_menu_options = LICENSE_ACTIONS;
5548
56
- licenseAction(action: any) {
57
- console.log(action.command);
49
+ licenseAction(action: string, license: any) {
50
+ return this.licenses[action](license.id).subscribe(
51
+ (actionResponse : any) => {
52
+ this.toaster.success(this.$L.get('Action "{}" executed successfully', action));
53
+ this.reload(this.pack.id);
54
+ },
55
+ (err : any) => this.toaster.error(this.$L.get('Action "{}" failed', action))
56
+ );
5857 }
5958
60
- isActionAvailable(pack : any) : boolean {
61
- return true;
59
+ reload(packId: number) : void {
60
+ this.licenses.getByPack(packId).subscribe(
61
+ list => {
62
+ this.data = list;
63
+ this.refresh();
64
+ },
65
+ err => console.error(err)
66
+ );
67
+ }
68
+
69
+ isActionAvailable(action: string, license : any) : boolean {
70
+ return this.licenses.isActionAvailable(action, license);
6271 }
6372
6473 constructor( _dataTableService: TdDataTableService,
....@@ -66,6 +75,7 @@
6675 private $L: LocaleService,
6776 private router: Router,
6877 private location: Location,
78
+ private toaster: ToastsManager,
6979 private route: ActivatedRoute,
7080 private dialog: MdDialog,
7181 private licenseForm: LicenseFormComponent,
....@@ -75,22 +85,6 @@
7585 }
7686
7787 ngOnInit(): void {
78
- this.route.params.subscribe(params => {
79
- var packId = +params['packId']; // (+) converts string 'id' to a number
80
- this.licenses.getByPack(packId).subscribe(
81
- list => {
82
- this.data = list;
83
- this.refresh();
84
- },
85
- err => console.error(err)
86
- );
87
- this.packs.get(packId).subscribe(
88
- packData => {
89
- this.pack = packData;
90
- },
91
- err => console.error(err)
92
- );
93
- });
9488 }
9589
9690 goBack() : void {
....@@ -111,7 +105,16 @@
111105
112106 ngAfterViewInit(): void {
113107 this.media.broadcast();
114
-
108
+ this.route.params.subscribe(params => {
109
+ var packId = +params['packId']; // (+) converts string 'id' to a number
110
+ this.reload(packId);
111
+ this.packs.get(packId).subscribe(
112
+ packData => {
113
+ this.pack = packData;
114
+ },
115
+ err => console.error(err)
116
+ );
117
+ });
115118 }
116119 }
117120