rsanchez
2017-03-19 280daa7f3f858ecfef9c91ffd5dea1007f021048
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { Router, ActivatedRoute } from '@angular/router';
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 } 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: 'menu', label: '' }
  ];
  pack_menu_options : any[] = [{
    command: 'edit',
    name: 'Edit'
  },{
    command: 'cancel',
    name: 'Cancel'
  }]
  
  constructor(_dataTableService: TdDataTableService,
    private media: TdMediaService,
    private router: Router,
    private route: ActivatedRoute,
    private dialog: MdDialog,
    private $L: LocaleService,
    private packForm: PackFormComponent,
    private packs: PacksService) {
      super(_dataTableService);
      this.packs.get().subscribe(
        (list : any[]) => {
          this.data = list;
          this.refresh();
        },
        (err: any) => console.error(err)
      );
  }
  packAction(action: any) {
    console.log(action.command);
  }
  isActionAvailable(pack : any) : boolean {
    return true;
  }
  showLicenses(pack: any) : void {
    this.router.navigate([`${pack.id}/licenses`], {relativeTo: this.route});
  }
  create() : void {
    this.router.navigate([`create`], {relativeTo: this.route});
  }
  edit(pack: any) : void {
    this.router.navigate([`edit/${pack.id}`], {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.media.broadcast();
  }
}