import { ActivatedRoute, Router } from '@angular/router'; import { MdDialog, MdDialogConfig } from '@angular/material'; import { TdDataTableService, TdPagingBarComponent, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core'; import { IPageChangeEvent } from '@covalent/core'; import { Component, AfterViewInit, ViewChild } from '@angular/core'; import { TdMediaService } from '@covalent/core'; import { Location } from '@angular/common'; import { LocaleService } from '../common/i18n'; import { LicensesService } from '../resources/licenses'; import { PacksService } from '../resources/packs'; import { LicenseFormComponent } from '../forms/license.form.component'; import { ListingBase } from './base'; var lic_example = { activation_code: '19fa8d30-29cb-4b59-81b5-3837af8204b6', code: 'CISA02-494-1', code_suffix: 1, created_by_id: '_client', creation_timestamp: 1447848747000, email: 'ccalvo@curisit.net', expiration_date: 1450440747000, full_name: 'César SA', id: 110, licenseData: '{"appCode":"CISA","appName":"CurisIntegrity SA","licenseCode":"CISA02-494-1","activationCode":"19fa8d30-29cb-4b59-81b5-3837af8204b6","expirationDate":1450440746790,"arch":"x86_64","osName":"Mac OS X","macAddresses":["60-03-08-95-AE-D0","B6-2B-33-E9-64-2D"],"crcLogo":"10f6379e0e1c00ebc403160307e3c5d0aba0727c9cae0bf1ac7cd19d84fdc80f","metadata":{"maxWellLifeLines":"50","simulationModes":"A1,A2,N1,QL"},"signature":"Tejun4bNbknxOyEmPaO/fGfGhv4URhVON/7bESxbODFWMJYKQqOPHrDiSUMlf6RbfWSVg2Dry8bY1WX881QGjTkBaHeDJKCy1EaJBwJ2nv9TYSMOiRj0eqMNYWE9/oLpvufHylAkPUpZwXVkSzTxmN+RvWa2Xt4Fu7xN+4PDHV4t7PSq7QwsFlD9ArgYC6Vx+zuL9WZANBtJ2gU/gKOE0CU0KjsB49RGQSFS/G27+H/YuDkCiQq7PC7VdVwYONQ2HO91fyPvInIrzDC5+sWHcUAqSCop//8klMy03hWl6VvAlaSP7kNM3KadyqXIJ3tx4Jwm1W+gBb3tngHzVCpYmw=="}', modification_timestamp: 1447848747000, pack_code: 'CISA02', pack_id: 18, request_data: '{"appCode":"CISA","activationCode":"19fa8d30-29cb-4b59-81b5-3837af8204b6","arch":"x86_64","osName":"Mac OS X","macAddresses":["60-03-08-95-AE-D0","B6-2B-33-E9-64-2D"],"crcLogo":"10f6379e0e1c00ebc403160307e3c5d0aba0727c9cae0bf1ac7cd19d84fdc80f"}', status: 'AC' } @Component({ selector: 'license-list', templateUrl: 'src/app/listing/license.list.component.html' }) export class LicenseListComponent extends ListingBase implements AfterViewInit { pack: any = null; columns: ITdDataTableColumn[] = [ { name: 'code', label: 'Code', tooltip: 'License code' }, { name: 'full_name', label: 'User name' }, { name: 'email', label: 'User email' }, { name: 'expiration_date', label: 'Expiration date' }, { name: 'status', label: 'Status' }, { name: 'menu', label: '' } ]; license_menu_options : any[] = [{ icon: 'edit', command: 'edit', name: 'Edit' },{ icon: 'cancel', command: 'cancel', name: 'Cancel' }] licenseAction(action: any) { console.log(action.command); } isActionAvailable(pack : any) : boolean { return true; } constructor( _dataTableService: TdDataTableService, private media: TdMediaService, private $L: LocaleService, private router: Router, private location: Location, private route: ActivatedRoute, private dialog: MdDialog, private licenseForm: LicenseFormComponent, private licenses: LicensesService, private packs: PacksService) { super(_dataTableService); } ngOnInit(): void { this.route.params.subscribe(params => { var packId = +params['packId']; // (+) converts string 'id' to a number this.licenses.getByPack(packId).subscribe( list => { this.data = list; this.refresh(); }, err => console.error(err) ); this.packs.get(packId).subscribe( packData => { this.pack = packData; }, err => console.error(err) ); }); } goBack() : void { this.router.navigate([`packs`]); } isLicenseExpired(lic: any): boolean { return lic.expiration_date < (new Date().getTime()); } create() : void { this.router.navigate([`packs/${this.pack.id}/licenses/create`]); } edit(licId: number | string) : void { this.router.navigate([`packs/${this.pack.id}/licenses/edit/${licId}`]); } ngAfterViewInit(): void { this.media.broadcast(); } }