From 7575723c99191093f6545297ddb8e9f6216f2651 Mon Sep 17 00:00:00 2001 From: Jeff Randall Date: Sat, 27 Jan 2024 12:06:17 -0600 Subject: [PATCH] If no fields are configured, set the calcaulated defaults. Limit the field count to 4. Always provide the data as common in widgets. --- docs/widgets/services/unifi-controller.md | 6 ++- src/widgets/unifi/component.jsx | 46 ++++++++++++++++------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/docs/widgets/services/unifi-controller.md b/docs/widgets/services/unifi-controller.md index fb7018d1..71b2df27 100644 --- a/docs/widgets/services/unifi-controller.md +++ b/docs/widgets/services/unifi-controller.md @@ -11,7 +11,9 @@ You can display general connectivity status from your Unifi (Network) Controller An optional 'site' parameter can be supplied, if it is not the widget will use the default site for the controller. -Allowed fields: `["uptime", "wan", "lan_users", "wlan_users"]`. +Allowed fields: `["uptime", "wan", "lan", "lan_users", "lan_devices", "wlan" "wlan_users", "wlan_devices" ]`. + +If more than 4 fields are provided, only the first 4 are displayed. ```yaml widget: @@ -22,4 +24,4 @@ widget: site: Site Name # optional ``` -_Added in v0.4.18, updated in 0.6.7_ +_Added in v0.4.18, updated in 0.8.7_ diff --git a/src/widgets/unifi/component.jsx b/src/widgets/unifi/component.jsx index 5ab09999..434a51bb 100644 --- a/src/widgets/unifi/component.jsx +++ b/src/widgets/unifi/component.jsx @@ -52,22 +52,40 @@ export default function Component({ service }) { ); } + // If fields are not configured, set the dynamically determined fields. + if (!widget.fields) { + widget.fields = []; + if (uptime) { + widget.fields.push("unifi.uptime"); + } + if (wan.show) { + widget.fields.push("unifi.wan"); + } + if (lan.show && !wlan.show) { + widget.fields.push("unifi.lan_users"); + widget.fields.push("unifi.lan"); + } + if (wlan.show) { + widget.fields.push("unifi.wlan_users"); + } + if (wlan.show && !lan.show) { + widget.fields.push("unifi.wlan_devices"); + widget.fields.push("unifi.wlan"); + } + } + // Limit to the first 4 available + widget.fields = widget.fields.slice(0, 4); + return ( - {uptime && } - {wan.show && } - - {lan.show && } - {lan.show && !wlan.show && ( - - )} - {lan.show && !wlan.show && } - - {wlan.show && } - {wlan.show && !lan.show && ( - - )} - {wlan.show && !lan.show && } + + + + + + + + ); }