Feature: Plant-it widget (#2941)

This commit is contained in:
Massimiliano De Luise 2024-02-20 02:54:28 +01:00 committed by GitHub
parent 841c74d58a
commit 619f365c92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 91 additions and 0 deletions

View file

@ -78,6 +78,7 @@ const components = {
proxmoxbackupserver: dynamic(() => import("./proxmoxbackupserver/component")),
pialert: dynamic(() => import("./pialert/component")),
pihole: dynamic(() => import("./pihole/component")),
plantit: dynamic(() => import("./plantit/component")),
plex: dynamic(() => import("./plex/component")),
portainer: dynamic(() => import("./portainer/component")),
prometheus: dynamic(() => import("./prometheus/component")),

View file

@ -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: plantitData, error: plantitError } = useWidgetAPI(widget, "plantit");
if (plantitError) {
return <Container service={service} error={plantitError} />;
}
if (!plantitData) {
return (
<Container service={service}>
<Block label="plantit.events" />
<Block label="plantit.plants" />
<Block label="plantit.photos" />
<Block label="plantit.species" />
</Container>
);
}
return (
<Container service={service}>
<Block label="plantit.events" value={t("common.number", { value: plantitData.diaryEntryCount })} />
<Block label="plantit.plants" value={t("common.number", { value: plantitData.plantCount })} />
<Block label="plantit.photos" value={t("common.number", { value: plantitData.imageCount })} />
<Block label="plantit.species" value={t("common.number", { value: plantitData.botanicalInfoCount })} />
</Container>
);
}

View file

@ -0,0 +1,21 @@
import { asJson } from "utils/proxy/api-helpers";
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
const widget = {
api: "{url}/api/{endpoint}",
proxyHandler: credentialedProxyHandler,
mappings: {
plantit: {
endpoint: "stats",
},
map: (data) => ({
events: Object.values(asJson(data).diaryEntryCount).reduce((acc, i) => acc + i, 0),
plants: Object.values(asJson(data).plantCount).reduce((acc, i) => acc + i, 0),
photos: Object.values(asJson(data).imageCount).reduce((acc, i) => acc + i, 0),
species: Object.values(asJson(data).botanicalInfoCount).reduce((acc, i) => acc + i, 0),
}),
},
};
export default widget;

View file

@ -71,6 +71,7 @@ import photoprism from "./photoprism/widget";
import proxmoxbackupserver from "./proxmoxbackupserver/widget";
import pialert from "./pialert/widget";
import pihole from "./pihole/widget";
import plantit from "./plantit/widget";
import plex from "./plex/widget";
import portainer from "./portainer/widget";
import prometheus from "./prometheus/widget";
@ -180,6 +181,7 @@ const widgets = {
proxmoxbackupserver,
pialert,
pihole,
plantit,
plex,
portainer,
prometheus,