From 8da0b54d2b00c1a9507858a76f8a53097d016b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Uribe=20Stengel?= Date: Thu, 23 Jul 2020 17:59:36 +0200 Subject: [PATCH] Refactor Overview page, make Settings page to home and add warning when temp or soil values are critical. --- imports/api/{espNames.js => espIds.js} | 2 +- imports/ui/App.jsx | 4 - imports/ui/Home.jsx | 160 +++++++++++-------------- imports/ui/NavigationBar.jsx | 1 - imports/ui/Overview.jsx | 129 ++++++++++++++------ imports/ui/SensorCardDeck.jsx | 53 ++++++-- imports/ui/Settings.jsx | 61 +++++++--- 7 files changed, 250 insertions(+), 160 deletions(-) rename imports/api/{espNames.js => espIds.js} (87%) diff --git a/imports/api/espNames.js b/imports/api/espIds.js similarity index 87% rename from imports/api/espNames.js rename to imports/api/espIds.js index ea77f0f..07360fd 100644 --- a/imports/api/espNames.js +++ b/imports/api/espIds.js @@ -1,6 +1,6 @@ import {SensorDataCollection} from "../../client/main"; -export function getAllEspNames() { +export function getAllEspIds() { return _.uniq(SensorDataCollection.find({}, { sort: {device_id: 1}, fields: {device_id: true} }).fetch().map(function (x) { diff --git a/imports/ui/App.jsx b/imports/ui/App.jsx index db9ccdf..3d68829 100644 --- a/imports/ui/App.jsx +++ b/imports/ui/App.jsx @@ -2,7 +2,6 @@ import React, { Suspense } from 'react' import NavBar from './NavigationBar' import Home from './Home' import Overview from './Overview' -import Settings from './Settings' import About from './About' import { BrowserRouter as Router, Switch, Route } from 'react-router-dom' @@ -20,9 +19,6 @@ function App() {
- -
-
diff --git a/imports/ui/Home.jsx b/imports/ui/Home.jsx index 94dfbba..784a2cf 100644 --- a/imports/ui/Home.jsx +++ b/imports/ui/Home.jsx @@ -1,11 +1,13 @@ import React from 'react' -import {CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis} from 'recharts'; -import SensorCardDeck from './SensorCardDeck' -import {SensorDataCollection, ActiveDeviceCollection} from "../../client/main"; +import { + SensorDataCollection, + ActiveDeviceCollection, + ConfiguredDevicesCollection, + PlantTypesCollection +} from "../../client/main"; import {useTracker} from 'meteor/react-meteor-data'; -import { Col, Form, Row, Card, CardDeck } from "react-bootstrap"; -import { getAllEspNames } from "../api/espNames"; -import moment from 'moment' +import { Card, CardDeck, Table } from "react-bootstrap"; +import Settings from "./Settings"; export default function Home() { const deviceId = useTracker(() => { @@ -23,19 +25,36 @@ export default function Home() { } }); - const handleChange = (e) => { - if (e.target.value === "") { - console.log("No device selected!"); - } else { - var doc = ActiveDeviceCollection.findOne({deviceId: deviceId.deviceId}); - ActiveDeviceCollection.update({_id: doc._id}, {$set: {deviceId: e.target.value}}); - } + const configuredDevices = useTracker(() => { + return ConfiguredDevicesCollection.find().fetch(); + }); + + function getSoil(type) { + const plantType = PlantTypesCollection.findOne({plantType: type}); + return plantType.dirtType } - const getLabelFromStamp = (x) => { - return moment(x.timestamp).format("HH:mm"); + function getPermWilPoint(type) { + const plantType = PlantTypesCollection.findOne({plantType: type}); + return plantType.data.soilMoisture.pwp } + function getFieldCap(type) { + const plantType = PlantTypesCollection.findOne({plantType: type}); + return plantType.data.soilMoisture.fc + } + + function getMinTemp(type) { + const plantType = PlantTypesCollection.findOne({plantType: type}); + return plantType.data.temperature.minTemp + } + + function getMinLux(type) { + const plantType = PlantTypesCollection.findOne({plantType: type}); + return plantType.data.light.minLux + } + + if ((sensorData.length <= 0)) { return ( @@ -50,84 +69,41 @@ export default function Home() { } else { return ( <> + + + + + + + + + + + + + + + + {configuredDevices.map((device, index) => { + return + + + + + + + + + + + })} + +
#Device NicknameDevice IDPlant TypeSoil TypePermanent Wilting PointField CapacityMin TemperatureMin Brightness
{index}{device.alias}{device.deviceId}{device.type}{getSoil(device.type)}{getPermWilPoint(device.type) + " %"}{getFieldCap(device.type) + " %"}{getMinTemp(device.type) + " °C"}{getMinLux(device.type) + " lux"}


- - -

Devices:

- -
- - -
- - - - {getAllEspNames().map((espName, index) => { - return - })} - - -
- - -
active device: {deviceId.deviceId}
- -
- - - - - - - el.temperature !== null)} margin={{top: 50, right: 50, bottom: 20, left: 5}}> - - - - - - - - - - - - el.humidity !== null)} margin={{top: 50, right: 50, bottom: 20, left: 5}}> - - - - - - - - - - - - - - el.brightness !== null)} margin={{top: 50, right: 50, bottom: 20, left: 5}}> - - - - - - - - - - - - el.moisture !== null)} margin={{top: 50, right: 50, bottom: 20, left: 5}}> - - - - - - - - - - +

If your device is not visible in the table above, configure it here below.

+

+

+ ) } diff --git a/imports/ui/NavigationBar.jsx b/imports/ui/NavigationBar.jsx index bad79f0..ca90401 100644 --- a/imports/ui/NavigationBar.jsx +++ b/imports/ui/NavigationBar.jsx @@ -24,7 +24,6 @@ export default function NavigationBar() {