mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-03 05:53:40 +01:00
Feature: Spoolman Widget (#3959)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
4a3a4c846e
commit
94bbcbe1fb
15
docs/widgets/services/spoolman.md
Normal file
15
docs/widgets/services/spoolman.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
title: Spoolman
|
||||||
|
description: Spoolman Widget Configuration
|
||||||
|
---
|
||||||
|
|
||||||
|
Learn more about [Spoolman](https://github.com/Donkie/Spoolman).
|
||||||
|
|
||||||
|
4 spools are displayed by default. If more than 4 spools are configured in spoolman you can use the spoolIds configuration option to control which are displayed.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
widget:
|
||||||
|
type: spoolman
|
||||||
|
url: http://spoolman.host.or.ip
|
||||||
|
spoolIds: [1, 2, 3, 4] # optional
|
||||||
|
```
|
@ -138,6 +138,7 @@ nav:
|
|||||||
- widgets/services/scrutiny.md
|
- widgets/services/scrutiny.md
|
||||||
- widgets/services/sonarr.md
|
- widgets/services/sonarr.md
|
||||||
- widgets/services/speedtest-tracker.md
|
- widgets/services/speedtest-tracker.md
|
||||||
|
- widgets/services/spoolman.md
|
||||||
- widgets/services/stash.md
|
- widgets/services/stash.md
|
||||||
- widgets/services/stocks.md
|
- widgets/services/stocks.md
|
||||||
- widgets/services/swagdashboard.md
|
- widgets/services/swagdashboard.md
|
||||||
|
@ -998,5 +998,8 @@
|
|||||||
"progressing": "Progressing",
|
"progressing": "Progressing",
|
||||||
"missing": "Missing",
|
"missing": "Missing",
|
||||||
"suspended": "Suspended"
|
"suspended": "Suspended"
|
||||||
|
},
|
||||||
|
"spoolman": {
|
||||||
|
"loading": "Loading"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,6 +492,9 @@ export function cleanServiceGroups(groups) {
|
|||||||
|
|
||||||
// technitium
|
// technitium
|
||||||
range,
|
range,
|
||||||
|
|
||||||
|
// spoolman
|
||||||
|
spoolIds,
|
||||||
} = cleanedService.widget;
|
} = cleanedService.widget;
|
||||||
|
|
||||||
let fieldsList = fields;
|
let fieldsList = fields;
|
||||||
@ -653,6 +656,9 @@ export function cleanServiceGroups(groups) {
|
|||||||
if (metrics) cleanedService.widget.metrics = metrics;
|
if (metrics) cleanedService.widget.metrics = metrics;
|
||||||
if (refreshInterval) cleanedService.widget.refreshInterval = refreshInterval;
|
if (refreshInterval) cleanedService.widget.refreshInterval = refreshInterval;
|
||||||
}
|
}
|
||||||
|
if (type === "spoolman") {
|
||||||
|
if (spoolIds !== undefined) cleanedService.widget.spoolIds = spoolIds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cleanedService;
|
return cleanedService;
|
||||||
|
@ -111,6 +111,7 @@ const components = {
|
|||||||
scrutiny: dynamic(() => import("./scrutiny/component")),
|
scrutiny: dynamic(() => import("./scrutiny/component")),
|
||||||
sonarr: dynamic(() => import("./sonarr/component")),
|
sonarr: dynamic(() => import("./sonarr/component")),
|
||||||
speedtest: dynamic(() => import("./speedtest/component")),
|
speedtest: dynamic(() => import("./speedtest/component")),
|
||||||
|
spoolman: dynamic(() => import("./spoolman/component")),
|
||||||
stash: dynamic(() => import("./stash/component")),
|
stash: dynamic(() => import("./stash/component")),
|
||||||
stocks: dynamic(() => import("./stocks/component")),
|
stocks: dynamic(() => import("./stocks/component")),
|
||||||
strelaysrv: dynamic(() => import("./strelaysrv/component")),
|
strelaysrv: dynamic(() => import("./strelaysrv/component")),
|
||||||
|
63
src/widgets/spoolman/component.jsx
Normal file
63
src/widgets/spoolman/component.jsx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
import Container from "components/services/widget/container";
|
||||||
|
import Block from "components/services/widget/block";
|
||||||
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
|
export default function Component({ service }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { widget } = service;
|
||||||
|
|
||||||
|
// eslint-disable-next-line prefer-const
|
||||||
|
let { data: spoolData, error: spoolError } = useWidgetAPI(widget, "spools");
|
||||||
|
|
||||||
|
if (spoolError) {
|
||||||
|
return <Container service={service} error={spoolError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!spoolData) {
|
||||||
|
const nBlocksGuess = widget.spoolIds?.length ?? 4;
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
{[...Array(nBlocksGuess)].map((_, i) => (
|
||||||
|
// eslint-disable-next-line react/no-array-index-key
|
||||||
|
<Block key={i} label="spoolman.loading" />
|
||||||
|
))}
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spoolData.error || spoolData.message) {
|
||||||
|
return <Container service={service} error={spoolData?.error ?? spoolData} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spoolData.length === 0) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="spoolman.noSpools" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (widget.spoolIds?.length) {
|
||||||
|
spoolData = spoolData.filter((spool) => widget.spoolIds.includes(spool.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spoolData.length > 4) {
|
||||||
|
spoolData = spoolData.slice(0, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
{spoolData.map((spool) => (
|
||||||
|
<Block
|
||||||
|
key={spool.id}
|
||||||
|
label={spool.filament.name}
|
||||||
|
value={t("common.percent", {
|
||||||
|
value: (spool.remaining_weight / spool.initial_weight) * 100,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
14
src/widgets/spoolman/widget.js
Normal file
14
src/widgets/spoolman/widget.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/api/v1/{endpoint}",
|
||||||
|
proxyHandler: credentialedProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
spools: {
|
||||||
|
endpoint: "spool",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
@ -102,6 +102,7 @@ import sabnzbd from "./sabnzbd/widget";
|
|||||||
import scrutiny from "./scrutiny/widget";
|
import scrutiny from "./scrutiny/widget";
|
||||||
import sonarr from "./sonarr/widget";
|
import sonarr from "./sonarr/widget";
|
||||||
import speedtest from "./speedtest/widget";
|
import speedtest from "./speedtest/widget";
|
||||||
|
import spoolman from "./spoolman/widget";
|
||||||
import stash from "./stash/widget";
|
import stash from "./stash/widget";
|
||||||
import stocks from "./stocks/widget";
|
import stocks from "./stocks/widget";
|
||||||
import strelaysrv from "./strelaysrv/widget";
|
import strelaysrv from "./strelaysrv/widget";
|
||||||
@ -237,6 +238,7 @@ const widgets = {
|
|||||||
scrutiny,
|
scrutiny,
|
||||||
sonarr,
|
sonarr,
|
||||||
speedtest,
|
speedtest,
|
||||||
|
spoolman,
|
||||||
stash,
|
stash,
|
||||||
stocks,
|
stocks,
|
||||||
strelaysrv,
|
strelaysrv,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user