| .. | .. |
|---|
| 1 | 1 | import { Router, ActivatedRoute } from '@angular/router'; |
|---|
| 2 | +import { Location } from '@angular/common'; |
|---|
| 2 | 3 | import { ToastsManager } from 'ng2-toastr/ng2-toastr'; |
|---|
| 3 | 4 | import { MdDialog, MdDialogConfig } from '@angular/material'; |
|---|
| 4 | 5 | import { |
|---|
| .. | .. |
|---|
| 11 | 12 | import { IPageChangeEvent } from '@covalent/core'; |
|---|
| 12 | 13 | import { Component, ViewChild, AfterViewInit } from '@angular/core'; |
|---|
| 13 | 14 | import { TdMediaService } from '@covalent/core'; |
|---|
| 14 | | -import { PacksService, PACK_ACTIONS } from '../resources/packs'; |
|---|
| 15 | +import { PacksService, PACK_ACTIONS, PacksFilter } from '../resources/packs'; |
|---|
| 15 | 16 | import { PackFormComponent } from '../forms/pack.form.component'; |
|---|
| 16 | 17 | import { LocaleService } from '../common/i18n'; |
|---|
| 17 | 18 | import { ListingBase } from './base'; |
|---|
| 18 | 19 | |
|---|
| 19 | | - |
|---|
| 20 | +/** |
|---|
| 20 | 21 | var pack_example = { |
|---|
| 21 | 22 | id: 7, |
|---|
| 22 | 23 | code: 'DX250000', |
|---|
| .. | .. |
|---|
| 45 | 46 | preactivation_valid_period: 70, |
|---|
| 46 | 47 | renew_valid_period: 0, |
|---|
| 47 | 48 | } |
|---|
| 48 | | - |
|---|
| 49 | +*/ |
|---|
| 49 | 50 | @Component({ |
|---|
| 50 | 51 | selector: 'pack-list', |
|---|
| 51 | 52 | templateUrl: 'src/app/listing/pack.list.component.html' |
|---|
| .. | .. |
|---|
| 63 | 64 | ]; |
|---|
| 64 | 65 | |
|---|
| 65 | 66 | pack_menu_options = PACK_ACTIONS; |
|---|
| 67 | + filter_description : string; |
|---|
| 68 | + prevUrl : string = null; |
|---|
| 66 | 69 | |
|---|
| 67 | 70 | constructor(_dataTableService: TdDataTableService, |
|---|
| 68 | 71 | private media: TdMediaService, |
|---|
| .. | .. |
|---|
| 76 | 79 | super(_dataTableService); |
|---|
| 77 | 80 | } |
|---|
| 78 | 81 | |
|---|
| 79 | | - reload() : void { |
|---|
| 80 | | - this.packs.get().subscribe( |
|---|
| 82 | + reload(filter?: PacksFilter) : void { |
|---|
| 83 | + this.prepareFilteredBehavior(filter); |
|---|
| 84 | + this.packs.get(filter).subscribe( |
|---|
| 81 | 85 | (list : any[]) => { |
|---|
| 82 | 86 | this.data = list; |
|---|
| 83 | 87 | this.refresh(); |
|---|
| 84 | 88 | }, |
|---|
| 85 | 89 | (err: any) => console.error(err) |
|---|
| 86 | 90 | ); |
|---|
| 91 | + } |
|---|
| 92 | + |
|---|
| 93 | + goBack() : void { |
|---|
| 94 | + if (this.prevUrl) { |
|---|
| 95 | + this.router.navigate([this.prevUrl]); |
|---|
| 96 | + } |
|---|
| 97 | + } |
|---|
| 98 | + |
|---|
| 99 | + prepareFilteredBehavior(filter: PacksFilter) { |
|---|
| 100 | + if (!filter) { |
|---|
| 101 | + this.filter_description = ''; |
|---|
| 102 | + this.prevUrl = null; |
|---|
| 103 | + } else { |
|---|
| 104 | + if (!!filter.applicationId) { |
|---|
| 105 | + this.filter_description = `Application: ${filter.name}`; |
|---|
| 106 | + this.prevUrl = 'applications'; |
|---|
| 107 | + } else if (!!filter.organizationId) { |
|---|
| 108 | + this.filter_description = `Organization: ${filter.name}`; |
|---|
| 109 | + this.prevUrl = 'organizations'; |
|---|
| 110 | + } else if (!!filter.licenseTypeId) { |
|---|
| 111 | + this.filter_description = `License type: ${filter.name}`; |
|---|
| 112 | + this.prevUrl = 'licensetypes'; |
|---|
| 113 | + } else { |
|---|
| 114 | + this.filter_description = ''; |
|---|
| 115 | + this.prevUrl = null; |
|---|
| 116 | + } |
|---|
| 117 | + } |
|---|
| 87 | 118 | } |
|---|
| 88 | 119 | |
|---|
| 89 | 120 | packAction(action: string, pack: any) { |
|---|
| .. | .. |
|---|
| 113 | 144 | this.sortOrder = sortEvent.order; |
|---|
| 114 | 145 | this.refresh(); |
|---|
| 115 | 146 | } |
|---|
| 116 | | - |
|---|
| 147 | + |
|---|
| 117 | 148 | ngAfterViewInit(): void { |
|---|
| 118 | | - this.reload(); |
|---|
| 119 | 149 | this.media.broadcast(); |
|---|
| 150 | + this.route.queryParams.subscribe(params => { |
|---|
| 151 | + let filter = params as PacksFilter; |
|---|
| 152 | + this.reload(filter); |
|---|
| 153 | + }); |
|---|
| 120 | 154 | } |
|---|
| 121 | 155 | } |
|---|
| 122 | | - |
|---|
| 156 | + |
|---|