Skip to content

Commit 291f8fd

Browse files
committed
Allow filtering for spool id
1 parent 6d800b0 commit 291f8fd

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
@@ -486,6 +486,9 @@ export function cleanServiceGroups(groups) {
486486

487487
// technitium
488488
range,
489+
490+
// spoolman
491+
spoolIds
489492
} = cleanedService.widget;
490493

491494
let fieldsList = fields;
@@ -639,6 +642,9 @@ export function cleanServiceGroups(groups) {
639642
if (type === "vikunja") {
640643
if (enableTaskList !== undefined) cleanedService.widget.enableTaskList = !!enableTaskList;
641644
}
645+
if (type === "spoolman") {
646+
if (spoolIds !== undefined) cleanedService.widget.spoolIds = spoolIds;
647+
}
642648
}
643649

644650
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)