@ -51,7 +51,7 @@
v - for = "(item, index) in sortedMonitorList"
v - for = "(item, index) in sortedMonitorList"
: key = "index"
: key = "index"
: monitor = "item"
: monitor = "item"
: isSearch= "searchText !== '' "
: showPathName= "filtersActive "
: isSelectMode = "selectMode"
: isSelectMode = "selectMode"
: isSelected = "isSelected"
: isSelected = "isSelected"
: select = "select"
: select = "select"
@ -117,31 +117,68 @@ export default {
} ,
} ,
/ * *
* Returns a sorted list of monitors based on the applied filters and search text .
*
* @ return { Array } The sorted list of monitors .
* /
sortedMonitorList ( ) {
sortedMonitorList ( ) {
let result = Object . values ( this . $root . monitorList ) ;
let result = Object . values ( this . $root . monitorList ) ;
/ / S i m p l e f i l t e r b y s e a r c h t e x t
result = result . filter ( monitor => {
/ / f i l t e r b y s e a r c h t e x t
/ / f i n d s m o n i t o r n a m e , t a g n a m e o r t a g v a l u e
/ / f i n d s m o n i t o r n a m e , t a g n a m e o r t a g v a l u e
let searchTextMatch = true ;
if ( this . searchText !== "" ) {
if ( this . searchText !== "" ) {
const loweredSearchText = this . searchText . toLowerCase ( ) ;
const loweredSearchText = this . searchText . toLowerCase ( ) ;
result = result . filter ( monitor => {
searchTextMatch =
return monitor . name . toLowerCase ( ) . includes ( loweredSearchText )
monitor . name . toLowerCase ( ) . includes ( loweredSearchText )
|| monitor . tags . find ( tag => tag . name . toLowerCase ( ) . includes ( loweredSearchText )
|| monitor . tags . find ( tag => tag . name . toLowerCase ( ) . includes ( loweredSearchText )
|| tag . value ? . toLowerCase ( ) . includes ( loweredSearchText ) ) ;
|| tag . value ? . toLowerCase ( ) . includes ( loweredSearchText ) ) ;
} ) ;
} else {
result = result . filter ( monitor => monitor . parent === null ) ;
}
}
/ / f i l t e r b y s t a t u s
let statusMatch = true ;
if ( this . filterState . status != null && this . filterState . status . length > 0 ) {
if ( monitor . id in this . $root . lastHeartbeatList && this . $root . lastHeartbeatList [ monitor . id ] ) {
monitor . status = this . $root . lastHeartbeatList [ monitor . id ] . status ;
}
statusMatch = this . filterState . status . includes ( monitor . status ) ;
}
/ / f i l t e r b y a c t i v e
let activeMatch = true ;
if ( this . filterState . active != null && this . filterState . active . length > 0 ) {
activeMatch = this . filterState . active . includes ( monitor . active ) ;
}
/ / f i l t e r b y t a g s
let tagsMatch = true ;
if ( this . filterState . tags != null && this . filterState . tags . length > 0 ) {
tagsMatch = monitor . tags . map ( tag => tag . tag _id ) / / c o n v e r t t o a r r a y o f t a g I D s
. filter ( monitorTagId => this . filterState . tags . includes ( monitorTagId ) ) / / p e r f o r m A r r a y I n t e r s a c t i o n b e t w e e n f i l t e r a n d m o n i t o r ' s t a g s
. length > 0 ;
}
/ / H i d e c h i l d r e n i f n o t f i l t e r i n g
let showChild = true ;
if ( this . filterState . status == null && this . filterState . active == null && this . filterState . tags == null && this . searchText === "" ) {
if ( monitor . parent !== null ) {
showChild = false ;
}
}
return searchTextMatch && statusMatch && activeMatch && tagsMatch && showChild ;
} ) ;
/ / F i l t e r r e s u l t b y a c t i v e s t a t e , w e i g h t a n d a l p h a b e t i c a l
/ / F i l t e r r e s u l t b y a c t i v e s t a t e , w e i g h t a n d a l p h a b e t i c a l
result . sort ( ( m1 , m2 ) => {
result . sort ( ( m1 , m2 ) => {
if ( m1 . active !== m2 . active ) {
if ( m1 . active !== m2 . active ) {
if ( m1 . active === 0 ) {
if ( m1 . active === false ) {
return 1 ;
return 1 ;
}
}
if ( m2 . active === 0 ) {
if ( m2 . active === false ) {
return - 1 ;
return - 1 ;
}
}
}
}
@ -159,27 +196,6 @@ export default {
return m1 . name . localeCompare ( m2 . name ) ;
return m1 . name . localeCompare ( m2 . name ) ;
} ) ;
} ) ;
if ( this . filterState . status != null && this . filterState . status . length > 0 ) {
result . map ( monitor => {
if ( monitor . id in this . $root . lastHeartbeatList && this . $root . lastHeartbeatList [ monitor . id ] ) {
monitor . status = this . $root . lastHeartbeatList [ monitor . id ] . status ;
}
} ) ;
result = result . filter ( monitor => this . filterState . status . includes ( monitor . status ) ) ;
}
if ( this . filterState . active != null && this . filterState . active . length > 0 ) {
result = result . filter ( monitor => this . filterState . active . includes ( monitor . active ) ) ;
}
if ( this . filterState . tags != null && this . filterState . tags . length > 0 ) {
result = result . filter ( monitor => {
return monitor . tags . map ( tag => tag . tag _id ) / / c o n v e r t t o a r r a y o f t a g I D s
. filter ( monitorTagId => this . filterState . tags . includes ( monitorTagId ) ) / / p e r f o r m A r r a y I n t e r s a c t i o n b e t w e e n f i l t e r a n d m o n i t o r ' s t a g s
. length > 0 ;
} ) ;
}
return result ;
return result ;
} ,
} ,
@ -233,6 +249,15 @@ export default {
this . selectAll = false ;
this . selectAll = false ;
this . selectedMonitors = { } ;
this . selectedMonitors = { } ;
}
}
} ,
/ * *
* Determines if any filters are active .
*
* @ return { boolean } True if any filter is active , false otherwise .
* /
filtersActive ( ) {
return this . filterState . status != null || this . filterState . active != null || this . filterState . tags != null || this . searchText !== "" ;
}
}
} ,
} ,
mounted ( ) {
mounted ( ) {