@@ -6,7 +6,7 @@ const logger = require("@core/logger")(module);
66const destinationGroupList = require ( "./destinationgroup-list" ) ;
77const mongoSingle = require ( "@core/mongo-single" ) ;
88
9- module . exports = async ( groupIndex = 0 , showExcluded = false ) => {
9+ module . exports = async ( groupIndex = - 1 , showExcluded = false ) => {
1010 let config ;
1111 try {
1212 config = await configGet ( ) ;
@@ -29,8 +29,23 @@ module.exports = async (groupIndex = 0, showExcluded = false) => {
2929 const routesCollection = await mongoCollection ( "routes" ) ;
3030 const crosspoints = await routesCollection . find ( ) . toArray ( ) ;
3131
32+ // check limited groups
33+ const limitDestinationGroups = config . limitDestinationGroups . sort ( ( a , b ) => {
34+ return a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) ) ;
35+ } ) ;
36+
37+ let filteredGroups ;
38+ if ( limitDestinationGroups . length > 0 ) {
39+ filteredGroups = groups . filter ( ( g ) =>
40+ limitDestinationGroups . some ( ( label ) => label . toLowerCase ( ) === g . label . toLowerCase ( ) )
41+ ) ;
42+ }
43+ else {
44+ filteredGroups = groups ;
45+ }
46+
3247 const outputArray = {
33- groups : groups . map ( ( g ) => {
48+ groups : filteredGroups . map ( ( g ) => {
3449 return {
3550 label : g . label ,
3651 index : g . index ,
@@ -43,56 +58,63 @@ module.exports = async (groupIndex = 0, showExcluded = false) => {
4358 destinations : [ ] ,
4459 } ;
4560
46- // calculate excluded sources
47- // not that this field is an array of strings - so we call toString() on each check later on. Grrrrr.
48- const excludedDestinations = config [ "excludeDestinations" ] ? config [ "excludeDestinations" ] : [ ] ;
61+ // check that selected group is in the filteredGroups
62+ if ( filteredGroups . some (
63+ ( l ) => l . label . toLowerCase ( ) === groups [ groupIndex ] . label . toLowerCase ( )
64+ ) ) {
4965
50- const buttonsFixed = groups [ groupIndex ] ?. fixed ?? false ;
66+ // calculate excluded sources
67+ // not that this field is an array of strings - so we call toString() on each check later on. Grrrrr.
68+ const excludedDestinations = config [ "excludeDestinations" ] ? config [ "excludeDestinations" ] : [ ] ;
5169
52- groups [ groupIndex ] ?. [ "value" ] . forEach ( ( destinationIndex , order ) => {
70+ const buttonsFixed = groups [ groupIndex ] ?. fixed ?? false ;
5371
54- // pull out all sources routed across all levels
55- let sourceLabel = undefined ;
56- let sourceIndex = undefined ;
72+ console . log ( `showing group index ${ groupIndex } ` ) ;
5773
58- if ( crosspoints ?. [ destinationIndex ] ?. levels ) {
59- const uniqueSources = [ ...new Set ( Object . values ( crosspoints ?. [ destinationIndex ] ?. levels ) ) ] ;
74+ groups [ groupIndex ] ?. [ "value" ] . forEach ( ( destinationIndex , order ) => {
6075
61- if ( uniqueSources . length > 1 ) {
62- sourceIndex = - 1 ;
63- sourceLabel = "** MULTIPLE **" ;
64- }
65- else if ( uniqueSources . length === 1 ) {
66- sourceIndex = uniqueSources [ 0 ] ;
67- sourceLabel = sources ?. [ sourceIndex ] ?. name ;
68- }
69- }
76+ // pull out all sources routed across all levels
77+ let sourceLabel = undefined ;
78+ let sourceIndex = undefined ;
7079
71- const isExcluded = excludedDestinations . includes ( destinationIndex ?. toString ( ) ) ;
72-
73- const indexText = config [ "showNumber" ] === false ? "" : destinationIndex + 1 ;
74-
75- if ( ! isExcluded || showExcluded ) {
76- outputArray [ "destinations" ] . push ( {
77- index : destinationIndex ,
78- label : destinations ?. [ destinationIndex ] ?. name ,
79- description : destinations ?. [ destinationIndex ] ?. description ,
80- fixed : buttonsFixed ,
81- sourceIndex : sourceIndex ,
82- sourceLabel : sourceLabel ,
83- indexText : indexText ,
84- hidden : isExcluded ,
85- order : order ,
86- isLocked : config . destinationLocks ?. [ destinationIndex ] ?? false ,
87- icon : icons [ destinationIndex ] ? icons [ destinationIndex ] : null ,
88-
89- iconColor : iconColors [ destinationIndex ] ? iconColors [ destinationIndex ] : "#ffffff" ,
90- } ) ;
91- }
92- } ) ;
80+ if ( crosspoints ?. [ destinationIndex ] ?. levels ) {
81+ const uniqueSources = [ ...new Set ( Object . values ( crosspoints ?. [ destinationIndex ] ?. levels ) ) ] ;
9382
94- // sort by order field
95- outputArray [ "destinations" ] . sort ( ( a , b ) => ( a . order > b . order ? 1 : - 1 ) ) ;
83+ if ( uniqueSources . length > 1 ) {
84+ sourceIndex = - 1 ;
85+ sourceLabel = "** MULTIPLE **" ;
86+ }
87+ else if ( uniqueSources . length === 1 ) {
88+ sourceIndex = uniqueSources [ 0 ] ;
89+ sourceLabel = sources ?. [ sourceIndex ] ?. name ;
90+ }
91+ }
9692
93+ const isExcluded = excludedDestinations . includes ( destinationIndex ?. toString ( ) ) ;
94+
95+ const indexText = config [ "showNumber" ] === false ? "" : destinationIndex + 1 ;
96+
97+ if ( ! isExcluded || showExcluded ) {
98+ outputArray [ "destinations" ] . push ( {
99+ index : destinationIndex ,
100+ label : destinations ?. [ destinationIndex ] ?. name ,
101+ description : destinations ?. [ destinationIndex ] ?. description ,
102+ fixed : buttonsFixed ,
103+ sourceIndex : sourceIndex ,
104+ sourceLabel : sourceLabel ,
105+ indexText : indexText ,
106+ hidden : isExcluded ,
107+ order : order ,
108+ isLocked : config . destinationLocks ?. [ destinationIndex ] ?? false ,
109+ icon : icons [ destinationIndex ] ? icons [ destinationIndex ] : null ,
110+
111+ iconColor : iconColors [ destinationIndex ] ? iconColors [ destinationIndex ] : "#ffffff" ,
112+ } ) ;
113+ }
114+ } ) ;
115+
116+ // sort by order field
117+ outputArray [ "destinations" ] . sort ( ( a , b ) => ( a . order > b . order ? 1 : - 1 ) ) ;
118+ }
97119 return outputArray ;
98120} ;
0 commit comments