From 36eaaafd88f8c718ede20ffdea223cc5bb90c60f Mon Sep 17 00:00:00 2001
From: Salvatore Gabriele La Greca
<35406071+thegabriele97@users.noreply.github.com>
Date: Sun, 21 May 2023 18:12:14 +0200
Subject: [PATCH] Added PiAlert widget [WIP] (#1493)
* Added PiAlert widget
* pialert: comments clean
* Syntax changes to piAlert widget
---------
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
---
public/locales/en/common.json | 6 +++++
src/widgets/components.js | 1 +
src/widgets/pialert/component.jsx | 37 +++++++++++++++++++++++++++++++
src/widgets/pialert/widget.js | 14 ++++++++++++
src/widgets/widgets.js | 2 ++
5 files changed, 60 insertions(+)
create mode 100644 src/widgets/pialert/component.jsx
create mode 100644 src/widgets/pialert/widget.js
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index 8e5b9022..b725132a 100755
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -232,6 +232,12 @@
"approved": "Approved",
"available": "Available"
},
+ "pialert": {
+ "total": "Total",
+ "connected": "Connected",
+ "new_devices": "New Devices",
+ "down_alerts": "Down Alerts"
+ },
"pihole": {
"queries": "Queries",
"blocked": "Blocked",
diff --git a/src/widgets/components.js b/src/widgets/components.js
index 66b4d4a0..589a93ad 100644
--- a/src/widgets/components.js
+++ b/src/widgets/components.js
@@ -57,6 +57,7 @@ const components = {
pfsense: dynamic(() => import("./pfsense/component")),
photoprism: dynamic(() => import("./photoprism/component")),
proxmoxbackupserver: dynamic(() => import("./proxmoxbackupserver/component")),
+ pialert: dynamic(() => import("./pialert/component")),
pihole: dynamic(() => import("./pihole/component")),
plex: dynamic(() => import("./plex/component")),
portainer: dynamic(() => import("./portainer/component")),
diff --git a/src/widgets/pialert/component.jsx b/src/widgets/pialert/component.jsx
new file mode 100644
index 00000000..49bef897
--- /dev/null
+++ b/src/widgets/pialert/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: pialertData, error: pialertError } = useWidgetAPI(widget, "data");
+
+ if (pialertError) {
+ return ;
+ }
+
+ if (!pialertData) {
+ return (
+
+
+
+
+
+
+ );
+ }
+
+ return (
+
+
+
+
+
+
+ );
+}
diff --git a/src/widgets/pialert/widget.js b/src/widgets/pialert/widget.js
new file mode 100644
index 00000000..1bed96ee
--- /dev/null
+++ b/src/widgets/pialert/widget.js
@@ -0,0 +1,14 @@
+import genericProxyHandler from "utils/proxy/handlers/generic";
+
+const widget = {
+ api: "{url}/php/server/devices.php?action=getDevicesTotals",
+ proxyHandler: genericProxyHandler,
+
+ mappings: {
+ "data": {
+ endpoint: "data",
+ },
+ },
+};
+
+export default widget;
diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js
index 49e70124..f843a168 100644
--- a/src/widgets/widgets.js
+++ b/src/widgets/widgets.js
@@ -51,6 +51,7 @@ import paperlessngx from "./paperlessngx/widget";
import pfsense from "./pfsense/widget";
import photoprism from "./photoprism/widget";
import proxmoxbackupserver from "./proxmoxbackupserver/widget";
+import pialert from "./pialert/widget";
import pihole from "./pihole/widget";
import plex from "./plex/widget";
import portainer from "./portainer/widget";
@@ -138,6 +139,7 @@ const widgets = {
pfsense,
photoprism,
proxmoxbackupserver,
+ pialert,
pihole,
plex,
portainer,