| .. | .. |
|---|
| 1 | | -import { Router } from '@angular/router'; |
|---|
| 1 | +import { LocaleService } from './common/i18n'; |
|---|
| 2 | +import { ActivatedRoute, Router } from '@angular/router'; |
|---|
| 2 | 3 | import { MdDialog, MdDialogConfig } from '@angular/material'; |
|---|
| 3 | 4 | import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core'; |
|---|
| 4 | 5 | import { IPageChangeEvent } from '@covalent/core'; |
|---|
| 5 | 6 | import { Component, AfterViewInit } from '@angular/core'; |
|---|
| 6 | 7 | import { TdMediaService } from '@covalent/core'; |
|---|
| 7 | 8 | import { LicensesService } from './resources/licenses'; |
|---|
| 9 | +import { PacksService } from './resources/packs'; |
|---|
| 10 | + |
|---|
| 8 | 11 | import { LicenseFormComponent } from './forms/license.form.component'; |
|---|
| 9 | 12 | |
|---|
| 10 | 13 | var lic_example = { activation_code: '19fa8d30-29cb-4b59-81b5-3837af8204b6', |
|---|
| .. | .. |
|---|
| 34 | 37 | }) |
|---|
| 35 | 38 | export class LicenseListComponent implements AfterViewInit { |
|---|
| 36 | 39 | data: any[] = []; |
|---|
| 40 | + pack: any = null; |
|---|
| 37 | 41 | columns: ITdDataTableColumn[] = [ |
|---|
| 38 | | - { name: 'code', label: 'Code', tooltip: 'License pack code' }, |
|---|
| 39 | | - { name: 'application_name', label: 'App name' }, |
|---|
| 40 | | - { name: 'licensetype_code', label: 'License type' }, |
|---|
| 41 | | - { name: 'organization_name', label: 'Organization' }, |
|---|
| 42 | | - { name: 'used_licenses', label: 'Lics', tooltip: 'Initial/Available pack licenses' }, |
|---|
| 42 | + { name: 'code', label: 'Code', tooltip: 'License code' }, |
|---|
| 43 | + { name: 'full_name', label: 'User name' }, |
|---|
| 44 | + { name: 'email', label: 'User email' }, |
|---|
| 45 | + { name: 'expiration_date', label: 'Expiration date' }, |
|---|
| 46 | + { name: 'status', label: 'Status' }, |
|---|
| 43 | 47 | { name: 'menu', label: '' } |
|---|
| 44 | 48 | ]; |
|---|
| 45 | 49 | |
|---|
| .. | .. |
|---|
| 50 | 54 | fromRow: number = 1; |
|---|
| 51 | 55 | currentPage: number = 1; |
|---|
| 52 | 56 | pageSize: number = 10; |
|---|
| 53 | | - sortBy: string = 'application_name'; |
|---|
| 57 | + sortBy: string = 'expiration_date'; |
|---|
| 54 | 58 | sortOrder: TdDataTableSortingOrder = TdDataTableSortingOrder.Descending; |
|---|
| 55 | 59 | filteredItems = this.data.length; |
|---|
| 56 | 60 | license_menu_options : any[] = [{ |
|---|
| .. | .. |
|---|
| 73 | 77 | |
|---|
| 74 | 78 | constructor(private _dataTableService: TdDataTableService, |
|---|
| 75 | 79 | private media: TdMediaService, |
|---|
| 80 | + private $L: LocaleService, |
|---|
| 76 | 81 | private router: Router, |
|---|
| 82 | + private route: ActivatedRoute, |
|---|
| 77 | 83 | private dialog: MdDialog, |
|---|
| 78 | 84 | private licenseForm: LicenseFormComponent, |
|---|
| 79 | | - private licenses: LicensesService) { |
|---|
| 80 | | - this.licenses.get().subscribe( |
|---|
| 81 | | - list => { |
|---|
| 82 | | - this.data = list; |
|---|
| 83 | | - this.filter(); |
|---|
| 84 | | - }, |
|---|
| 85 | | - err => console.error(err) |
|---|
| 86 | | - ); |
|---|
| 85 | + private licenses: LicensesService, |
|---|
| 86 | + private packs: PacksService) { |
|---|
| 87 | 87 | } |
|---|
| 88 | 88 | |
|---|
| 89 | 89 | ngOnInit(): void { |
|---|
| 90 | | - this.filter(); |
|---|
| 90 | + this.route.params.subscribe(params => { |
|---|
| 91 | + var packId = +params['id']; // (+) converts string 'id' to a number |
|---|
| 92 | + this.licenses.getByPack(packId).subscribe( |
|---|
| 93 | + list => { |
|---|
| 94 | + this.data = list; |
|---|
| 95 | + this.filter(); |
|---|
| 96 | + }, |
|---|
| 97 | + err => console.error(err) |
|---|
| 98 | + ); |
|---|
| 99 | + this.packs.get(packId).subscribe( |
|---|
| 100 | + packData => { |
|---|
| 101 | + this.pack = packData; |
|---|
| 102 | + }, |
|---|
| 103 | + err => console.error(err) |
|---|
| 104 | + ); |
|---|
| 105 | + }); |
|---|
| 106 | + } |
|---|
| 107 | + |
|---|
| 108 | + isLicenseExpired(lic: any): boolean { |
|---|
| 109 | + return lic.expiration_date < (new Date().getTime()); |
|---|
| 91 | 110 | } |
|---|
| 92 | 111 | |
|---|
| 93 | 112 | createLicense() : void { |
|---|