From 44409f6bc1d21a7721257e390c3d5fc0c3ec99ad Mon Sep 17 00:00:00 2001 From: Don Reece Date: Fri, 4 Nov 2022 12:19:34 -0400 Subject: [PATCH] Modified to condense Channels + HD count to single API Call --- public/locales/en/common.json | 5 ++++ src/widgets/components.js | 1 + src/widgets/hdhomerun/component.jsx | 12 ++++---- src/widgets/hdhomerun/widget.js | 8 +----- src/widgets/octoprint/component.jsx | 44 +++++++++++++++++++++++++++++ src/widgets/octoprint/widget.js | 15 ++++++++++ src/widgets/widgets.js | 2 ++ 7 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 src/widgets/octoprint/component.jsx create mode 100644 src/widgets/octoprint/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index ea376069..73b4adda 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -313,5 +313,10 @@ "hdhomerun": { "channels": "Channels", "hd": "HD" + }, + "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 03d108dd..0e657b84 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -18,6 +18,7 @@ const components = { lidarr: dynamic(() => import("./lidarr/component")), mastodon: dynamic(() => import("./mastodon/component")), npm: dynamic(() => import("./npm/component")), + octoprint: dynamic(() => import("./octoprint/component")), nzbget: dynamic(() => import("./nzbget/component")), ombi: dynamic(() => import("./ombi/component")), overseerr: dynamic(() => import("./overseerr/component")), diff --git a/src/widgets/hdhomerun/component.jsx b/src/widgets/hdhomerun/component.jsx index 0f6485dd..9af8ca33 100644 --- a/src/widgets/hdhomerun/component.jsx +++ b/src/widgets/hdhomerun/component.jsx @@ -10,13 +10,12 @@ export default function Component({ service }) { const { widget } = service; const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup.json"); - const { data: hdData, error: hdError } = useWidgetAPI(widget, "hd"); - if (channelsError || hdError) { + if (channelsError) { return ; } - if (!channelsData || !hdData) { + if (!channelsData) { return ( @@ -25,10 +24,13 @@ export default function Component({ service }) { ); } +const hdChannels = channelsData?.filter((channel) => channel.HD === 1); + return ( - - + + + ); } diff --git a/src/widgets/hdhomerun/widget.js b/src/widgets/hdhomerun/widget.js index fff75dda..e94198a8 100644 --- a/src/widgets/hdhomerun/widget.js +++ b/src/widgets/hdhomerun/widget.js @@ -8,13 +8,7 @@ const widget = { mappings: { "lineup.json": { endpoint: "lineup.json", - }, - hd: { - endpoint: "lineup.json", - map: (data) => ({ - have: jsonArrayFilter(data, (item) => item?.HD === 1).length, - }), - }, + } }, }; diff --git a/src/widgets/octoprint/component.jsx b/src/widgets/octoprint/component.jsx new file mode 100644 index 00000000..6719743c --- /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 47218a1f..0aeb4b2e 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -14,6 +14,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"; @@ -54,6 +55,7 @@ const widgets = { mastodon, npm, nzbget, + octoprint, ombi, overseerr, pihole,