Modified to condense Channels + HD count to single API Call
This commit is contained in:
parent
cee4173077
commit
44409f6bc1
@ -313,5 +313,10 @@
|
|||||||
"hdhomerun": {
|
"hdhomerun": {
|
||||||
"channels": "Channels",
|
"channels": "Channels",
|
||||||
"hd": "HD"
|
"hd": "HD"
|
||||||
|
},
|
||||||
|
"octoprint": {
|
||||||
|
"job_status": "Job Status",
|
||||||
|
"file_name": "File Name",
|
||||||
|
"job_progress": "Progress"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ const components = {
|
|||||||
lidarr: dynamic(() => import("./lidarr/component")),
|
lidarr: dynamic(() => import("./lidarr/component")),
|
||||||
mastodon: dynamic(() => import("./mastodon/component")),
|
mastodon: dynamic(() => import("./mastodon/component")),
|
||||||
npm: dynamic(() => import("./npm/component")),
|
npm: dynamic(() => import("./npm/component")),
|
||||||
|
octoprint: dynamic(() => import("./octoprint/component")),
|
||||||
nzbget: dynamic(() => import("./nzbget/component")),
|
nzbget: dynamic(() => import("./nzbget/component")),
|
||||||
ombi: dynamic(() => import("./ombi/component")),
|
ombi: dynamic(() => import("./ombi/component")),
|
||||||
overseerr: dynamic(() => import("./overseerr/component")),
|
overseerr: dynamic(() => import("./overseerr/component")),
|
||||||
|
|||||||
@ -10,13 +10,12 @@ export default function Component({ service }) {
|
|||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
|
|
||||||
const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup.json");
|
const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup.json");
|
||||||
const { data: hdData, error: hdError } = useWidgetAPI(widget, "hd");
|
|
||||||
|
|
||||||
if (channelsError || hdError) {
|
if (channelsError) {
|
||||||
return <Container error={t("widget.api_error")} />;
|
return <Container error={t("widget.api_error")} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!channelsData || !hdData) {
|
if (!channelsData) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="hdhomerun.channels" />
|
<Block label="hdhomerun.channels" />
|
||||||
@ -25,10 +24,13 @@ export default function Component({ service }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hdChannels = channelsData?.filter((channel) => channel.HD === 1);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="hdhomerun.channels" value={t("common.number", { value: channelsData.length })} />
|
<Block label="hdhomerun.channels" value={channelsData.length } />
|
||||||
<Block label="hdhomerun.hd" value={t("common.number", { value: hdData.have })} />
|
<Block label="hdhomerun.hd" value={hdChannels.length} />
|
||||||
|
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,13 +8,7 @@ const widget = {
|
|||||||
mappings: {
|
mappings: {
|
||||||
"lineup.json": {
|
"lineup.json": {
|
||||||
endpoint: "lineup.json",
|
endpoint: "lineup.json",
|
||||||
},
|
}
|
||||||
hd: {
|
|
||||||
endpoint: "lineup.json",
|
|
||||||
map: (data) => ({
|
|
||||||
have: jsonArrayFilter(data, (item) => item?.HD === 1).length,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
44
src/widgets/octoprint/component.jsx
Normal file
44
src/widgets/octoprint/component.jsx
Normal file
@ -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 <Container error={t("widget.api_error")} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!jobData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="octoprint.job_status" />
|
||||||
|
<Block label="octoprint.file_name" />
|
||||||
|
<Block label="octoprint.progress" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const progress = jobData.progress.completion
|
||||||
|
if (progress !== null) {
|
||||||
|
var progress_pct = jobData.progress.completion.toFixed(2) + " %"
|
||||||
|
} else {
|
||||||
|
var progress_pct = "-"
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="octoprint.job_status" value={ jobData.state } />
|
||||||
|
<Block label="octoprint.file_name" value={ jobData.job.file.name } />
|
||||||
|
<Block label="octoprint.job_progress" value={ progress_pct } />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
15
src/widgets/octoprint/widget.js
Normal file
15
src/widgets/octoprint/widget.js
Normal file
@ -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;
|
||||||
@ -14,6 +14,7 @@ import lidarr from "./lidarr/widget";
|
|||||||
import mastodon from "./mastodon/widget";
|
import mastodon from "./mastodon/widget";
|
||||||
import npm from "./npm/widget";
|
import npm from "./npm/widget";
|
||||||
import nzbget from "./nzbget/widget";
|
import nzbget from "./nzbget/widget";
|
||||||
|
import octoprint from "./octoprint/widget";
|
||||||
import ombi from "./ombi/widget";
|
import ombi from "./ombi/widget";
|
||||||
import overseerr from "./overseerr/widget";
|
import overseerr from "./overseerr/widget";
|
||||||
import pihole from "./pihole/widget";
|
import pihole from "./pihole/widget";
|
||||||
@ -54,6 +55,7 @@ const widgets = {
|
|||||||
mastodon,
|
mastodon,
|
||||||
npm,
|
npm,
|
||||||
nzbget,
|
nzbget,
|
||||||
|
octoprint,
|
||||||
ombi,
|
ombi,
|
||||||
overseerr,
|
overseerr,
|
||||||
pihole,
|
pihole,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user