Change: default merge pihole blocked fields (#3065)

pull/2708/head
shamoon 9 months ago
parent b05b9b1420
commit 9caede1cc3

@ -9,6 +9,8 @@ As of v2022.12 [PiHole requires the use of an API key](https://pi-hole.net/blog/
Allowed fields: `["queries", "blocked", "blocked_percent", "gravity"]`. Allowed fields: `["queries", "blocked", "blocked_percent", "gravity"]`.
Note: by default the "blocked" and "blocked_percent" fields are merged e.g. "1,234 (15%)" but explicitly including the "blocked_percent" field will change them to display separately.
```yaml ```yaml
widget: widget:
type: pihole type: pihole
@ -16,4 +18,4 @@ widget:
key: yourpiholeapikey # optional key: yourpiholeapikey # optional
``` ```
_Added in v0.1.0, updated in v0.6.18_ _Added in v0.1.0, updated in v0.8.9_

@ -15,6 +15,10 @@ export default function Component({ service }) {
return <Container service={service} error={piholeError} />; return <Container service={service} error={piholeError} />;
} }
if (!widget.fields) {
widget.fields = ["queries", "blocked", "gravity"];
}
if (!piholeData) { if (!piholeData) {
return ( return (
<Container service={service}> <Container service={service}>
@ -26,10 +30,15 @@ export default function Component({ service }) {
); );
} }
let blockedValue = `${t("common.number", { value: parseInt(piholeData.ads_blocked_today, 10) })}`;
if (!widget.fields.includes("blocked_percent")) {
blockedValue += ` (${t("common.percent", { value: parseFloat(piholeData.ads_percentage_today.toPrecision(3)) })})`;
}
return ( return (
<Container service={service}> <Container service={service}>
<Block label="pihole.queries" value={t("common.number", { value: parseInt(piholeData.dns_queries_today, 10) })} /> <Block label="pihole.queries" value={t("common.number", { value: parseInt(piholeData.dns_queries_today, 10) })} />
<Block label="pihole.blocked" value={t("common.number", { value: parseInt(piholeData.ads_blocked_today, 10) })} /> <Block label="pihole.blocked" value={blockedValue} />
<Block <Block
label="pihole.blocked_percent" label="pihole.blocked_percent"
value={t("common.percent", { value: parseFloat(piholeData.ads_percentage_today.toPrecision(3)) })} value={t("common.percent", { value: parseFloat(piholeData.ads_percentage_today.toPrecision(3)) })}

Loading…
Cancel
Save