11import { ChangeDetectionStrategy , ChangeDetectorRef , Component } from '@angular/core' ;
2- import { MonitoringStatus , MonitoringStatusLine } from 'app/model/monitoring.model' ;
2+ import { MonitoringStatus , MonitoringStatusLine , MonitoringStatusLineUtil } from 'app/model/monitoring.model' ;
3+ import { Column , ColumnType , Filter } from 'app/shared/table/data-table.component' ;
34import { forkJoin , Observable } from 'rxjs' ;
45import { finalize , tap } from 'rxjs/operators' ;
56import { Global , Service } from '../../../../model/service.model' ;
@@ -20,7 +21,8 @@ export class ServiceListComponent {
2021 services : Array < Service > ;
2122 profiles : any ;
2223 goroutines : any ;
23- filteredStatusLines : Array < MonitoringStatusLine > ;
24+ columns : Array < Column < MonitoringStatusLine > > ;
25+ filteredStatusLines : Filter < MonitoringStatusLine > ;
2426 globals : Array < Global > = [ ] ;
2527 globalStatus : Global ;
2628 globalVersion : Global ;
@@ -33,6 +35,67 @@ export class ServiceListComponent {
3335 ) {
3436 this . loading = true ;
3537
38+ this . columns = [
39+ < Column < MonitoringStatusLine > > {
40+ name : 'common_type' ,
41+ selector : ( c : MonitoringStatusLine ) => c . type
42+ } ,
43+ < Column < MonitoringStatusLine > > {
44+ name : 'common_service' ,
45+ selector : ( c : MonitoringStatusLine ) => c . service
46+ } ,
47+ < Column < MonitoringStatusLine > > {
48+ name : 'common_component' ,
49+ selector : ( c : MonitoringStatusLine ) => c . component
50+ } ,
51+ < Column < MonitoringStatusLine > > {
52+ name : 'common_hostname' ,
53+ selector : ( c : MonitoringStatusLine ) => c . hostname
54+ } ,
55+ < Column < MonitoringStatusLine > > {
56+ name : 'common_status' ,
57+ type : ColumnType . LABEL ,
58+ selector : ( c : MonitoringStatusLine ) => {
59+ return {
60+ class : MonitoringStatusLineUtil . color ( c ) ,
61+ value : c . status
62+ } ;
63+ }
64+ } ,
65+ < Column < MonitoringStatusLine > > {
66+ name : 'common_value' ,
67+ selector : ( c : MonitoringStatusLine ) => c . value
68+ } ,
69+ < Column < MonitoringStatusLine > > {
70+ name : 'common_consumer' ,
71+ selector : ( c : MonitoringStatusLine ) => c . consumer
72+ } ,
73+ < Column < MonitoringStatusLine > > {
74+ name : 'common_session' ,
75+ selector : ( c : MonitoringStatusLine ) => c . session
76+ }
77+ ] ;
78+
79+ this . filteredStatusLines = f => {
80+ const lowerFilter = f . toLowerCase ( ) ;
81+ return ( line : MonitoringStatusLine ) => {
82+ if ( f === 'NOTICE' ) {
83+ return line . status . indexOf ( 'AL' ) !== - 1 || line . status . indexOf ( 'WARN' ) !== - 1 ;
84+ }
85+ if ( f === 'AL' || f === 'WARN' || f === 'OK' ) {
86+ return line . status . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ;
87+ }
88+ return line . status . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ||
89+ line . component . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ||
90+ line . value . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ||
91+ line . type . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ||
92+ ( line . service && line . service . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ) ||
93+ ( line . hostname && line . hostname . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ) ||
94+ ( line . session && line . session . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ) ||
95+ ( line . consumer && line . consumer . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ) ;
96+ }
97+ } ;
98+
3699 forkJoin (
37100 this . refreshProfiles ( ) ,
38101 this . refreshStatus ( ) ,
@@ -81,7 +144,6 @@ export class ServiceListComponent {
81144 refreshStatus ( ) : Observable < any > {
82145 return this . _monitoringService . getStatus ( ) . pipe ( tap ( r => {
83146 this . status = r ;
84- this . filterChange ( ) ;
85147 } ) ) ;
86148 }
87149
@@ -118,33 +180,4 @@ export class ServiceListComponent {
118180 this . goroutines = data ;
119181 } ) ) ;
120182 }
121-
122- filterChange ( ) : void {
123- if ( ! this . filter ) {
124- this . filteredStatusLines = this . status . lines ;
125- return ;
126- }
127-
128- if ( this . filter === 'NOTICE' ) {
129- this . filteredStatusLines = this . status . lines . filter ( line => {
130- return line . status . indexOf ( 'AL' ) !== - 1 || line . status . indexOf ( 'WARN' ) !== - 1
131- } ) ;
132- return
133- }
134-
135- if ( this . filter === 'AL' || this . filter === 'WARN' || this . filter === 'OK' ) {
136- this . filteredStatusLines = this . status . lines . filter ( line => {
137- return line . status . indexOf ( this . filter ) !== - 1
138- } ) ;
139- return
140- }
141-
142- const lowerFilter = this . filter . toLowerCase ( ) ;
143-
144- this . filteredStatusLines = this . status . lines . filter ( line => {
145- return line . status . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ||
146- line . component . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1 ||
147- line . value . toLowerCase ( ) . indexOf ( lowerFilter ) !== - 1
148- } ) ;
149- }
150183}
0 commit comments