import { Router } from '@angular/router'; import { MdDialog } from '@angular/material'; import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core'; import { IPageChangeEvent } from '@covalent/core'; import { Component, AfterViewInit } from '@angular/core'; import { TdMediaService } from '@covalent/core'; import { LicensesService } from './resources/licenses'; import { LicenseFormComponent } from './forms/license.form.component'; 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/license.list.component.html' }) export class LicenseListComponent implements AfterViewInit { data: any[] = []; 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: 'Lics', tooltip: 'Initial/Available pack licenses' }, { name: 'menu', label: '' } ]; filteredData: any[] = this.data; filteredTotal: number = this.data.length; searchTerm: string = ''; fromRow: number = 1; currentPage: number = 1; pageSize: number = 10; sortBy: string = 'application_name'; sortOrder: TdDataTableSortingOrder = TdDataTableSortingOrder.Descending; filteredItems = this.data.length; 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(private _dataTableService: TdDataTableService, private media: TdMediaService, private router: Router, private dialog: MdDialog, private licenseForm: LicenseFormComponent, private licenses: LicensesService) { this.licenses.get().subscribe( list => { this.data = list; this.filter(); }, err => console.error(err) ); } ngOnInit(): void { this.filter(); } createPack() : void { var ref = this.dialog.open(LicenseFormComponent, { height: '50%', // can be px or % width: '40%', // can be px or % }); ref.componentInstance.isNew = true; ref.afterClosed().subscribe(result => { console.log(result); this.filter(); }); } editLicense(lic: any) : void { var ref = this.dialog.open(LicenseFormComponent, { height: '50%', // can be px or % width: '40%', // can be px or % }); ref.componentInstance.isNew = false; ref.componentInstance.data = lic; ref.afterClosed().subscribe(result => { console.log(result); this.filter(); }); } sort(sortEvent: ITdDataTableSortChangeEvent): void { this.sortBy = sortEvent.name; this.sortOrder = sortEvent.order; this.filter(); } search(searchTerm: string): void { this.searchTerm = searchTerm; this.filter(); } page(pagingEvent: IPageChangeEvent): void { this.fromRow = pagingEvent.fromRow; this.currentPage = pagingEvent.page; this.pageSize = pagingEvent.pageSize; this.filter(); } loadData() { } filter(): void { let newData: any[] = this.data; newData = this._dataTableService.filterData(newData, this.searchTerm, true); this.filteredTotal = newData.length; this.filteredItems = newData.length; newData = this._dataTableService.sortData(newData, this.sortBy, this.sortOrder); newData = this._dataTableService.pageData(newData, this.fromRow, this.currentPage * this.pageSize); this.filteredData = newData; } ngAfterViewInit(): void { this.media.broadcast(); } }