diff --git a/public/locales/en/common.json b/public/locales/en/common.json index aa1d6601a..48a3ef7f3 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -292,5 +292,10 @@ "up_to_date": "Up to Date", "child_bridges": "Child Bridges", "child_bridges_status": "{{ok}}/{{total}}" + }, + "truenas": { + "load": "System Load", + "uptime": "Uptime", + "alerts": "Alerts" } } diff --git a/src/widgets/components.js b/src/widgets/components.js index 8f7bfeb93..c339946dd 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -35,6 +35,7 @@ const components = { tautulli: dynamic(() => import("./tautulli/component")), traefik: dynamic(() => import("./traefik/component")), transmission: dynamic(() => import("./transmission/component")), + truenas: dynamic(() => import("./truenas/component")), unifi: dynamic(() => import("./unifi/component")), }; diff --git a/src/widgets/truenas/component.jsx b/src/widgets/truenas/component.jsx new file mode 100644 index 000000000..9529ae0f6 --- /dev/null +++ b/src/widgets/truenas/component.jsx @@ -0,0 +1,37 @@ +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: alertData, error: alertError } = useWidgetAPI(widget, "alerts"); + const { data: statusData, error: statusError } = useWidgetAPI(widget, "status"); + + if (alertError || statusError) { + return ; + } + + if (!alertData || !statusData) { + return ( + + + + + + ); + } + + return ( + + + + + + + ); +} diff --git a/src/widgets/truenas/widget.js b/src/widgets/truenas/widget.js new file mode 100644 index 000000000..7269e36a1 --- /dev/null +++ b/src/widgets/truenas/widget.js @@ -0,0 +1,21 @@ +import { jsonArrayFilter } from "utils/proxy/api-helpers"; +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/api/v2.0/{endpoint}", + proxyHandler: genericProxyHandler, + + mappings: { + alerts: { + endpoint: "alert/list", + map: (data) => ({ + pending: jsonArrayFilter(data, (item) => item?.dismissed === false).length, + }), + }, + status: { + endpoint: "system/info", + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 55379e986..c82003fea 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -30,6 +30,7 @@ import strelaysrv from "./strelaysrv/widget"; import tautulli from "./tautulli/widget"; import traefik from "./traefik/widget"; import transmission from "./transmission/widget"; +import truenas from "./truenas/widget"; import unifi from "./unifi/widget"; const widgets = { @@ -66,6 +67,7 @@ const widgets = { tautulli, traefik, transmission, + truenas, unifi, unifi_console: unifi, };