From 3483fe1188f1c6c5d319db73e9462c2631c33d95 Mon Sep 17 00:00:00 2001 From: Dimitar Ilkov Date: Wed, 26 Oct 2022 11:36:15 +0300 Subject: [PATCH] Add widget for Truenas --- public/locales/en/common.json | 5 +++++ src/widgets/components.js | 1 + src/widgets/truenas/component.jsx | 37 +++++++++++++++++++++++++++++++ src/widgets/truenas/widget.js | 21 ++++++++++++++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 66 insertions(+) create mode 100644 src/widgets/truenas/component.jsx create mode 100644 src/widgets/truenas/widget.js 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, };