import { Router, ActivatedRoute } from '@angular/router'; import { ToastsManager } from 'ng2-toastr/ng2-toastr'; import { MdDialog, MdDialogConfig } from '@angular/material'; import { ITdDataTableColumn, ITdDataTableSortChangeEvent, TdDataTableService, TdDataTableSortingOrder, TdPagingBarComponent } from '@covalent/core'; import { IPageChangeEvent } from '@covalent/core'; import { Component, ViewChild, AfterViewInit } from '@angular/core'; import { TdMediaService } from '@covalent/core'; import { PacksService, PACK_ACTIONS } from '../resources/packs'; import { PackFormComponent } from '../forms/pack.form.component'; import { LocaleService } from '../common/i18n'; import { ListingBase } from './base'; var pack_example = { id: 7, code: 'DX250000', status: 'AC', application_name: 'Doxr', created_by_id: 'admin', created_by_name: 'Administrator (admin)', creation_timestamp: 1440597540000, end_valid_date: 2051222400000, init_valid_date: 1440547200000, license_preactivation: true, license_type_id: 5, licensetype_code: 'DXL3', metadata: [ { key: 'max_docs', value: '250000', readonly: true, mandatory: true, pack_id: 7 } ], num_activations: 7, num_available: -2, num_creations: 7, num_licenses: 5, organization_id: 2, organization_name: 'CurisTec', preactivation_valid_period: 70, renew_valid_period: 0, } @Component({ selector: 'pack-list', templateUrl: 'src/app/listing/pack.list.component.html' }) export class PackListComponent extends ListingBase implements AfterViewInit { columns: ITdDataTableColumn[] = [ { name: 'code', label: 'Code', tooltip: 'License pack code' }, { name: 'application_name', label: 'App name' }, { name: 'licensetype_code', label: 'License type' }, { name: 'organization_name', label: 'Organization' }, { name: 'used_licenses', label: 'Licenses', tooltip: 'Initial/Available pack licenses' }, { name: 'status', label: 'Status', tooltip: 'Pack status' }, { name: 'menu', label: '' } ]; pack_menu_options = PACK_ACTIONS; constructor(_dataTableService: TdDataTableService, private media: TdMediaService, private router: Router, private route: ActivatedRoute, private dialog: MdDialog, private $L: LocaleService, private toaster: ToastsManager, private packForm: PackFormComponent, private packs: PacksService) { super(_dataTableService); } reload() : void { this.packs.get().subscribe( (list : any[]) => { this.data = list; this.refresh(); }, (err: any) => console.error(err) ); } packAction(action: string, pack: any) { return this.packs[action](pack.id).subscribe( (actionResponse : any) => { this.toaster.success(this.$L.get('Action "{}" executed successfully', action)); this.reload(); }, (err : any) => this.toaster.error(this.$L.get('Action "{}" failed', action)) ); } showLicenses(pack: any) : void { this.router.navigate([`${pack.id}/licenses`], {relativeTo: this.route}); } create() : void { this.router.navigate([`create`], {relativeTo: this.route}); } edit(packId: number) : void { this.router.navigate([`edit/${packId}`], {relativeTo: this.route}); } sort(sortEvent: ITdDataTableSortChangeEvent): void { this.sortBy = sortEvent.name === 'used_licenses' ? 'num_available' : sortEvent.name; this.sortOrder = sortEvent.order; this.refresh(); } ngAfterViewInit(): void { this.reload(); this.media.broadcast(); } }