Skip to content

Commit 3ebb6e9

Browse files
fgeckshamoon
authored andcommitted
Allow filtering for spool id
1 parent b08f1d5 commit 3ebb6e9

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

docs/widgets/services/spoolman.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ description: Spoolman Widget Configuration
55

66
Learn more about [Spoolman](https://github.com/Donkie/Spoolman).
77

8-
4 spools are displayed by default. If more than 4 spools are configured in spoolman you can use the filamentNames configuration option to filter for spools by their filament name.
8+
4 spools are displayed by default. If more than 4 spools are configured in spoolman you can use the spoolIds configuration option to filter for spools by their id.
99

1010
```yaml
1111
widget:
1212
type: spoolman
1313
url: http://spoolman.host.or.ip
14-
filamentNames:
15-
- orange
16-
- blue
14+
spoolIds:
15+
- 1
16+
- 4
1717
```

src/utils/config/service-helpers.js

+6
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ export function cleanServiceGroups(groups) {
492492

493493
// technitium
494494
range,
495+
496+
// spoolman
497+
spoolIds
495498
} = cleanedService.widget;
496499

497500
let fieldsList = fields;
@@ -653,6 +656,9 @@ export function cleanServiceGroups(groups) {
653656
if (metrics) cleanedService.widget.metrics = metrics;
654657
if (refreshInterval) cleanedService.widget.refreshInterval = refreshInterval;
655658
}
659+
if (type === "spoolman") {
660+
if (spoolIds !== undefined) cleanedService.widget.spoolIds = spoolIds;
661+
}
656662
}
657663

658664
return cleanedService;

src/widgets/spoolman/component.jsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default function Component({ service }) {
1010

1111
const { data: spoolData, error: spoolError } = useWidgetAPI(widget, "spools");
1212

13-
// Helper to handle filtering based on filamentNames
14-
const filterSpools = (data, filamentNames) => {
15-
if (!filamentNames || filamentNames.length === 0) return data; // No filtering if no filamentNames
16-
const limitedfilamentNames = filamentNames.slice(0, 4); // Limit to 4 names
17-
return data.filter(spool => limitedfilamentNames.includes(spool.filament.name));
13+
// Helper to handle filtering based on spoolIds
14+
const filterSpools = (data, spoolIds) => {
15+
if (!spoolIds || spoolIds.length === 0) return data; // No filtering if no spoolIds
16+
const limitedspoolIds = spoolIds.slice(0, 4); // Limit to 4 names
17+
return data.filter(spool => spoolIds.includes(spool.id));
1818
};
1919

2020
// Helper to limit spoolData length
@@ -50,7 +50,7 @@ export default function Component({ service }) {
5050
}
5151

5252
// Filter and limit spools
53-
let filteredSpoolData = filterSpools(spoolData, widget.filamentNames);
53+
let filteredSpoolData = filterSpools(spoolData, widget.spoolIds);
5454
filteredSpoolData = limitSpoolData(filteredSpoolData);
5555

5656
// Render filtered and limited spools

0 commit comments

Comments
 (0)