Skip to content

Commit a6f6860

Browse files
committed
ross-ultix: add ability to limit groups
1 parent ad2c0a4 commit a6f6860

File tree

6 files changed

+147
-82
lines changed

6 files changed

+147
-82
lines changed

src/modules/ross-ultrix/client/panels/ConfigPanel.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@ export default function ConfigPanel() {
109109
fullWidth
110110
/>
111111
</Grid>
112+
<Grid item xs={12}>
113+
<BugConfigFormChipInput
114+
name="limitSourceGroups"
115+
label="Source groups to show"
116+
control={control}
117+
defaultValue={panelConfig.data.limitSourceGroups}
118+
sort={true}
119+
error={errors.limitSourceGroups}
120+
fullWidth
121+
/>
122+
</Grid>
123+
<Grid item xs={12}>
124+
<BugConfigFormChipInput
125+
name="limitDestinationGroups"
126+
label="Destination groups to show"
127+
control={control}
128+
defaultValue={panelConfig.data.limitDestinationGroups}
129+
sort={true}
130+
error={errors.limitDestinationGroups}
131+
fullWidth
132+
/>
133+
</Grid>
112134
<Grid item xs={12}>
113135
<BugConfigFormChipInput
114136
name="excludeSources"

src/modules/ross-ultrix/container/services/destination-list.js

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const logger = require("@core/logger")(module);
66
const destinationGroupList = require("./destinationgroup-list");
77
const 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
};

src/modules/ross-ultrix/container/services/source-list.js

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,23 @@ module.exports = async (destinationIndex = null, groupIndex = 0, showExcluded =
2424
const groups = await sourceGroupList();
2525
const routesCollection = await mongoCollection("routes");
2626

27+
// check limited groups
28+
const limitSourceGroups = config.limitSourceGroups.sort((a, b) => {
29+
return a.toLowerCase().localeCompare(b.toLowerCase());
30+
});
31+
32+
let filteredGroups;
33+
if (limitSourceGroups.length > 0) {
34+
filteredGroups = groups.filter((g) =>
35+
limitSourceGroups.some((label) => label.toLowerCase() === g.label.toLowerCase())
36+
);
37+
}
38+
else {
39+
filteredGroups = groups;
40+
}
41+
2742
const outputArray = {
28-
groups: groups.map((g) => {
43+
groups: filteredGroups.map((g) => {
2944
return {
3045
label: g.label,
3146
index: g.index,
@@ -37,43 +52,47 @@ module.exports = async (destinationIndex = null, groupIndex = 0, showExcluded =
3752
}),
3853
sources: [],
3954
};
55+
// check that selected group is in the filteredGroups
56+
if (filteredGroups.some(
57+
(l) => l.label.toLowerCase() === groups[groupIndex].label.toLowerCase()
58+
)) {
4059

41-
// calculate excluded sources
42-
// not that this field is an array of strings - so we call toString() on each check later on. Grrrrr.
43-
const excludedSources = config["excludeSources"] ? config["excludeSources"] : [];
44-
45-
const buttonsFixed = groups[groupIndex]?.fixed ?? false;
60+
// calculate excluded sources
61+
// not that this field is an array of strings - so we call toString() on each check later on. Grrrrr.
62+
const excludedSources = config["excludeSources"] ? config["excludeSources"] : [];
4663

47-
// get get existing routes from the db
48-
const crosspoints = await routesCollection.findOne({ destination: parseInt(destinationIndex) });
64+
const buttonsFixed = groups[groupIndex]?.fixed ?? false;
4965

50-
let selectedSources = [];
51-
if (crosspoints?.levels) {
52-
selectedSources = Object.values(crosspoints?.levels) ?? [];
53-
}
54-
55-
groups[groupIndex]?.["value"].forEach((sourceIndex, order) => {
66+
// get get existing routes from the db
67+
const crosspoints = await routesCollection.findOne({ destination: parseInt(destinationIndex) });
5668

57-
// check it's not excluded or if it's a selected source - in which case we'll show it anyway
58-
const isExcluded = excludedSources.includes(sourceIndex?.toString());
59-
const isSelected = selectedSources.includes(sourceIndex);
60-
if (!isExcluded || showExcluded) {
61-
outputArray["sources"].push({
62-
index: sourceIndex,
63-
label: sources[sourceIndex]?.name,
64-
fixed: buttonsFixed,
65-
description: sources[sourceIndex]?.description,
66-
selected: isSelected,
67-
hidden: isExcluded,
68-
order: order,
69-
icon: icons[sourceIndex] ? icons[sourceIndex] : null,
70-
iconColor: iconColors[sourceIndex] ? iconColors[sourceIndex] : "#ffffff",
71-
});
69+
let selectedSources = [];
70+
if (crosspoints?.levels) {
71+
selectedSources = Object.values(crosspoints?.levels) ?? [];
7272
}
73-
})
7473

75-
// sort by order field
76-
outputArray["sources"].sort((a, b) => (a.order > b.order ? 1 : -1));
74+
groups[groupIndex]?.["value"].forEach((sourceIndex, order) => {
7775

76+
// check it's not excluded or if it's a selected source - in which case we'll show it anyway
77+
const isExcluded = excludedSources.includes(sourceIndex?.toString());
78+
const isSelected = selectedSources.includes(sourceIndex);
79+
if (!isExcluded || showExcluded) {
80+
outputArray["sources"].push({
81+
index: sourceIndex,
82+
label: sources[sourceIndex]?.name,
83+
fixed: buttonsFixed,
84+
description: sources[sourceIndex]?.description,
85+
selected: isSelected,
86+
hidden: isExcluded,
87+
order: order,
88+
icon: icons[sourceIndex] ? icons[sourceIndex] : null,
89+
iconColor: iconColors[sourceIndex] ? iconColors[sourceIndex] : "#ffffff",
90+
});
91+
}
92+
})
93+
94+
// sort by order field
95+
outputArray["sources"].sort((a, b) => (a.order > b.order ? 1 : -1));
96+
}
7897
return outputArray;
7998
};

src/modules/ross-ultrix/container/workers/worker-database.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const main = async () => {
1919
// Connect to the db
2020
await mongoDb.connect(workerData.id);
2121

22-
await mongoSingle.clear("destinations");
23-
await mongoSingle.clear("sources");
24-
await mongoSingle.clear("groups");
22+
// await mongoSingle.clear("destinations");
23+
// await mongoSingle.clear("sources");
24+
// await mongoSingle.clear("groups");
2525

2626
while (true) {
2727
await fetchDestinations(workerData);

src/modules/ross-ultrix/container/workers/worker-swp08.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const main = async () => {
7676
// await mongoCreateIndex(routesCollection, "timestamp", { expireAfterSeconds: 480 });
7777

7878
// remove previous values
79-
routesCollection.deleteMany({});
79+
// routesCollection.deleteMany({});
8080

8181
while (true) {
8282
try {

src/modules/ross-ultrix/module.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"capabilities": ["video-router"],
66
"memory": 100,
77
"notes": "",
8-
"version": "0.1.13",
8+
"version": "0.2.1",
99
"icon": "mdiMatrix",
1010
"author": "Geoff House",
1111
"license": "Apache-2.0",
@@ -27,6 +27,8 @@
2727
"uiPort": "8080",
2828
"useTake": false,
2929
"showAll": false,
30+
"limitSourceGroups": [],
31+
"limitDestinationGroups": [],
3032
"sourceIconColors": [],
3133
"destinationIconColors": [],
3234
"destinationLocks": [],

0 commit comments

Comments
 (0)