| .. | .. |
|---|
| 5 | 5 | import { Component, AfterViewInit, ViewChild } from '@angular/core'; |
|---|
| 6 | 6 | import { TdMediaService } from '@covalent/core'; |
|---|
| 7 | 7 | import { Location } from '@angular/common'; |
|---|
| 8 | +import { ToastsManager } from 'ng2-toastr/ng2-toastr'; |
|---|
| 8 | 9 | |
|---|
| 9 | 10 | import { LocaleService } from '../common/i18n'; |
|---|
| 10 | | -import { LicensesService } from '../resources/licenses'; |
|---|
| 11 | +import { LicensesService, LICENSE_ACTIONS } from '../resources/licenses'; |
|---|
| 11 | 12 | import { PacksService } from '../resources/packs'; |
|---|
| 12 | 13 | import { LicenseFormComponent } from '../forms/license.form.component'; |
|---|
| 13 | 14 | import { ListingBase } from './base'; |
|---|
| .. | .. |
|---|
| 43 | 44 | { name: 'menu', label: '' } |
|---|
| 44 | 45 | ]; |
|---|
| 45 | 46 | |
|---|
| 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; |
|---|
| 55 | 48 | |
|---|
| 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 | + ); |
|---|
| 58 | 57 | } |
|---|
| 59 | 58 | |
|---|
| 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); |
|---|
| 62 | 71 | } |
|---|
| 63 | 72 | |
|---|
| 64 | 73 | constructor( _dataTableService: TdDataTableService, |
|---|
| .. | .. |
|---|
| 66 | 75 | private $L: LocaleService, |
|---|
| 67 | 76 | private router: Router, |
|---|
| 68 | 77 | private location: Location, |
|---|
| 78 | + private toaster: ToastsManager, |
|---|
| 69 | 79 | private route: ActivatedRoute, |
|---|
| 70 | 80 | private dialog: MdDialog, |
|---|
| 71 | 81 | private licenseForm: LicenseFormComponent, |
|---|
| .. | .. |
|---|
| 75 | 85 | } |
|---|
| 76 | 86 | |
|---|
| 77 | 87 | 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 | | - }); |
|---|
| 94 | 88 | } |
|---|
| 95 | 89 | |
|---|
| 96 | 90 | goBack() : void { |
|---|
| .. | .. |
|---|
| 111 | 105 | |
|---|
| 112 | 106 | ngAfterViewInit(): void { |
|---|
| 113 | 107 | 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 | + }); |
|---|
| 115 | 118 | } |
|---|
| 116 | 119 | } |
|---|
| 117 | 120 | |
|---|