| .. | .. |
|---|
| 1 | 1 | import { Router, ActivatedRoute } from '@angular/router'; |
|---|
| 2 | +import { ToastsManager } from 'ng2-toastr/ng2-toastr'; |
|---|
| 2 | 3 | import { MdDialog, MdDialogConfig } from '@angular/material'; |
|---|
| 3 | 4 | import { |
|---|
| 4 | 5 | ITdDataTableColumn, |
|---|
| .. | .. |
|---|
| 10 | 11 | import { IPageChangeEvent } from '@covalent/core'; |
|---|
| 11 | 12 | import { Component, ViewChild, AfterViewInit } from '@angular/core'; |
|---|
| 12 | 13 | import { TdMediaService } from '@covalent/core'; |
|---|
| 13 | | -import { PacksService } from '../resources/packs'; |
|---|
| 14 | +import { PacksService, PACK_ACTIONS } from '../resources/packs'; |
|---|
| 14 | 15 | import { PackFormComponent } from '../forms/pack.form.component'; |
|---|
| 15 | 16 | import { LocaleService } from '../common/i18n'; |
|---|
| 16 | 17 | import { ListingBase } from './base'; |
|---|
| .. | .. |
|---|
| 57 | 58 | { name: 'licensetype_code', label: 'License type' }, |
|---|
| 58 | 59 | { name: 'organization_name', label: 'Organization' }, |
|---|
| 59 | 60 | { name: 'used_licenses', label: 'Licenses', tooltip: 'Initial/Available pack licenses' }, |
|---|
| 61 | + { name: 'status', label: 'Status', tooltip: 'Pack status' }, |
|---|
| 60 | 62 | { name: 'menu', label: '' } |
|---|
| 61 | 63 | ]; |
|---|
| 62 | 64 | |
|---|
| 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; |
|---|
| 71 | 66 | |
|---|
| 72 | 67 | constructor(_dataTableService: TdDataTableService, |
|---|
| 73 | 68 | private media: TdMediaService, |
|---|
| .. | .. |
|---|
| 75 | 70 | private route: ActivatedRoute, |
|---|
| 76 | 71 | private dialog: MdDialog, |
|---|
| 77 | 72 | private $L: LocaleService, |
|---|
| 73 | + private toaster: ToastsManager, |
|---|
| 78 | 74 | private packForm: PackFormComponent, |
|---|
| 79 | 75 | private packs: PacksService) { |
|---|
| 80 | 76 | 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 | | - ); |
|---|
| 88 | 77 | } |
|---|
| 89 | 78 | |
|---|
| 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 | + ); |
|---|
| 93 | 87 | } |
|---|
| 94 | 88 | |
|---|
| 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 | + ); |
|---|
| 97 | 97 | } |
|---|
| 98 | 98 | |
|---|
| 99 | 99 | showLicenses(pack: any) : void { |
|---|
| .. | .. |
|---|
| 115 | 115 | } |
|---|
| 116 | 116 | |
|---|
| 117 | 117 | ngAfterViewInit(): void { |
|---|
| 118 | + this.reload(); |
|---|
| 118 | 119 | this.media.broadcast(); |
|---|
| 119 | | - |
|---|
| 120 | 120 | } |
|---|
| 121 | 121 | } |
|---|
| 122 | 122 | |
|---|