mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-10-30 22:13:59 +00:00 
			
		
		
		
	Feature: Plant-it widget (#2941)
This commit is contained in:
		
							parent
							
								
									841c74d58a
								
							
						
					
					
						commit
						619f365c92
					
				
							
								
								
									
										15
									
								
								docs/widgets/services/planit.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								docs/widgets/services/planit.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| --- | ||||
| title: Plant-it | ||||
| description: Plant-it Widget Configuration | ||||
| --- | ||||
| 
 | ||||
| Learn more about [Plantit](https://github.com/MDeLuise/plant-it). | ||||
| 
 | ||||
| API key can be created from the REST API. | ||||
| 
 | ||||
| ```yaml | ||||
| widget: | ||||
|   type: plantit | ||||
|   url: http://plant-it.host.or.ip:port # api port | ||||
|   key: plantit-api-key | ||||
| ``` | ||||
| @ -103,6 +103,7 @@ nav: | ||||
|       - widgets/services/photoprism.md | ||||
|       - widgets/services/pialert.md | ||||
|       - widgets/services/pihole.md | ||||
|       - widgets/services/plantit.md | ||||
|       - widgets/services/plex-tautulli.md | ||||
|       - widgets/services/plex.md | ||||
|       - widgets/services/portainer.md | ||||
|  | ||||
| @ -825,5 +825,11 @@ | ||||
|     "netdata": { | ||||
|       "warnings": "Warnings", | ||||
|       "criticals": "Criticals" | ||||
|     }, | ||||
|     "plantit": { | ||||
|         "events": "Events", | ||||
|         "plants": "Plants", | ||||
|         "photos": "Photos", | ||||
|         "species": "Species" | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -803,5 +803,11 @@ | ||||
|     "netdata": { | ||||
|         "warnings": "Warnings", | ||||
|         "criticals": "Criticals" | ||||
|     }, | ||||
|     "plantit": { | ||||
|         "events": "Eventi", | ||||
|         "plants": "Piante", | ||||
|         "species": "Specie", | ||||
|         "images": "Immagini" | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -65,6 +65,8 @@ export default async function credentialedProxyHandler(req, res, map) { | ||||
|         headers.Authorization = `Basic ${Buffer.from(`$:${widget.key}`).toString("base64")}`; | ||||
|       } else if (widget.type === "glances") { | ||||
|         headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`; | ||||
|       } else if (widget.type === "plantit") { | ||||
|         headers.Key = `${widget.key}`; | ||||
|       } else { | ||||
|         headers["X-API-Key"] = `${widget.key}`; | ||||
|       } | ||||
|  | ||||
| @ -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")), | ||||
|  | ||||
							
								
								
									
										37
									
								
								src/widgets/plantit/component.jsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/widgets/plantit/component.jsx
									
									
									
									
									
										Normal 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> | ||||
|   ); | ||||
| } | ||||
							
								
								
									
										21
									
								
								src/widgets/plantit/widget.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/widgets/plantit/widget.js
									
									
									
									
									
										Normal 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; | ||||
| @ -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, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Massimiliano De Luise
						Massimiliano De Luise