Add OctoPrint widget
- Tracking Job Status (state), File Name, Job Progress (pct)
This commit is contained in:
parent
fa57c79722
commit
1097d423a7
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@ -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")),
|
||||
|
||||
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.job_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;
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user