rsanchez
2017-06-07 89a0646d18da6f3290a883121e38f4086a6fb37e
securis/src/main/webapp/src/app/listing/pack.list.component.ts
....@@ -1,4 +1,5 @@
11 import { Router, ActivatedRoute } from '@angular/router';
2
+import { Location } from '@angular/common';
23 import { ToastsManager } from 'ng2-toastr/ng2-toastr';
34 import { MdDialog, MdDialogConfig } from '@angular/material';
45 import {
....@@ -11,12 +12,12 @@
1112 import { IPageChangeEvent } from '@covalent/core';
1213 import { Component, ViewChild, AfterViewInit } from '@angular/core';
1314 import { TdMediaService } from '@covalent/core';
14
-import { PacksService, PACK_ACTIONS } from '../resources/packs';
15
+import { PacksService, PACK_ACTIONS, PacksFilter } from '../resources/packs';
1516 import { PackFormComponent } from '../forms/pack.form.component';
1617 import { LocaleService } from '../common/i18n';
1718 import { ListingBase } from './base';
1819
19
-
20
+/**
2021 var pack_example = {
2122 id: 7,
2223 code: 'DX250000',
....@@ -45,7 +46,7 @@
4546 preactivation_valid_period: 70,
4647 renew_valid_period: 0,
4748 }
48
-
49
+*/
4950 @Component({
5051 selector: 'pack-list',
5152 templateUrl: 'src/app/listing/pack.list.component.html'
....@@ -63,6 +64,8 @@
6364 ];
6465
6566 pack_menu_options = PACK_ACTIONS;
67
+ filter_description : string;
68
+ prevUrl : string = null;
6669
6770 constructor(_dataTableService: TdDataTableService,
6871 private media: TdMediaService,
....@@ -76,14 +79,42 @@
7679 super(_dataTableService);
7780 }
7881
79
- reload() : void {
80
- this.packs.get().subscribe(
82
+ reload(filter?: PacksFilter) : void {
83
+ this.prepareFilteredBehavior(filter);
84
+ this.packs.get(filter).subscribe(
8185 (list : any[]) => {
8286 this.data = list;
8387 this.refresh();
8488 },
8589 (err: any) => console.error(err)
8690 );
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
+ }
87118 }
88119
89120 packAction(action: string, pack: any) {
....@@ -113,10 +144,13 @@
113144 this.sortOrder = sortEvent.order;
114145 this.refresh();
115146 }
116
-
147
+
117148 ngAfterViewInit(): void {
118
- this.reload();
119149 this.media.broadcast();
150
+ this.route.queryParams.subscribe(params => {
151
+ let filter = params as PacksFilter;
152
+ this.reload(filter);
153
+ });
120154 }
121155 }
122
-
156
+