diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 8784443a..8acbe380 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -315,5 +315,10 @@ "uptime": "Uptime", "alerts": "Alerts", "time": "{{value, number(style: unit; unitDisplay: long;)}}" + }, + "octoprint": { + "job_status": "Job Status", + "file_name": "File Name", + "job_progress": "Progress" } } diff --git a/src/widgets/components.js b/src/widgets/components.js index 33d09eac..2ec00cf5 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -18,6 +18,7 @@ const components = { mastodon: dynamic(() => import("./mastodon/component")), npm: dynamic(() => import("./npm/component")), nzbget: dynamic(() => import("./nzbget/component")), + octoprint: dynamic(() => import("./octoprint/component")), ombi: dynamic(() => import("./ombi/component")), overseerr: dynamic(() => import("./overseerr/component")), pihole: dynamic(() => import("./pihole/component")), diff --git a/src/widgets/octoprint/component.jsx b/src/widgets/octoprint/component.jsx new file mode 100644 index 00000000..abaede78 --- /dev/null +++ b/src/widgets/octoprint/component.jsx @@ -0,0 +1,44 @@ +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; + + const { data: jobData, error: jobError } = useWidgetAPI(widget, "job"); + // const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted/missing"); + // const { data: queueData, error: queueError } = useWidgetAPI(widget, "queue/status"); + + if (jobError) { + return ; + } + + if (!jobData) { + return ( + + + + + + ); + } + + const progress = jobData.progress.completion + if (progress !== null) { + var progress_pct = jobData.progress.completion.toFixed(2) + " %" + } else { + var progress_pct = "-" + } + + return ( + + + + + + ); +} diff --git a/src/widgets/octoprint/widget.js b/src/widgets/octoprint/widget.js new file mode 100644 index 00000000..3a19800f --- /dev/null +++ b/src/widgets/octoprint/widget.js @@ -0,0 +1,15 @@ +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; +import { jsonArrayFilter } from "utils/proxy/api-helpers"; + +const widget = { + api: "{url}/api/{endpoint}", + proxyHandler: credentialedProxyHandler, + + mappings: { + "job": { + endpoint: "job", + } + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 7bad4013..e8e60854 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -13,6 +13,7 @@ import lidarr from "./lidarr/widget"; import mastodon from "./mastodon/widget"; import npm from "./npm/widget"; import nzbget from "./nzbget/widget"; +import octoprint from "./octoprint/widget"; import ombi from "./ombi/widget"; import overseerr from "./overseerr/widget"; import pihole from "./pihole/widget"; @@ -53,6 +54,7 @@ const widgets = { mastodon, npm, nzbget, + octoprint, ombi, overseerr, pihole,