diff --git a/package-lock.json b/package-lock.json index 6b3ff66..79e2f18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,7 @@ "mui-tel-input": "^7.0.0", "notistack": "^3.0.1", "openweathermap-ts": "^1.2.10", - "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#master", + "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", "query-string": "^9.2.1", "react": "^18.3.1", "react-beautiful-dnd": "^13.1.1", @@ -11967,7 +11967,7 @@ }, "node_modules/protobuf-ts": { "version": "1.0.0", - "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#ab9e8d4fd38f9af7802398403d38fddda5eb01da", + "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#1c00e059fe16126e85c50581786b7510759920d7", "dependencies": { "protobufjs": "^6.8.8" } diff --git a/package.json b/package.json index 7f5044c..90ac71b 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "mui-tel-input": "^7.0.0", "notistack": "^3.0.1", "openweathermap-ts": "^1.2.10", - "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#master", + "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", "query-string": "^9.2.1", "react": "^18.3.1", "react-beautiful-dnd": "^13.1.1", diff --git a/src/bin/BinCardV2.tsx b/src/bin/BinCardV2.tsx index f39c553..5244db9 100644 --- a/src/bin/BinCardV2.tsx +++ b/src/bin/BinCardV2.tsx @@ -443,14 +443,24 @@ export default function BinCard(props: Props) { " L" ); } - if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && bin.bushelsPerTonne() > 1) { + + if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1) { return ( - bin.grainTonnes().toLocaleString() + + bin.grainInventory().toLocaleString() + " mT " + bin.fillPercent() + "%" ); + } else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1) { + return ( + bin.grainInventory().toLocaleString() + + " t " + + bin.fillPercent() + + "%" + ); } + + return ( current.toLocaleString() + "/" + diff --git a/src/bin/BinControllerDisplay.tsx b/src/bin/BinControllerDisplay.tsx new file mode 100644 index 0000000..32cbd94 --- /dev/null +++ b/src/bin/BinControllerDisplay.tsx @@ -0,0 +1,168 @@ +import { Component } from "models" +import React, { useEffect, useState } from "react" +import { makeStyles } from "@mui/styles"; +import { Box, Button, DialogActions, DialogContent, DialogTitle, Typography } from "@mui/material"; +import AerationFanIcon from "products/AgIcons/AerationFanIcon"; +import { quack } from "protobuf-ts/quack"; +import { useComponentAPI, useMobile, useSnackbar } from "hooks"; +import ButtonGroup from "common/ButtonGroup"; +import ObjectHeaterIcon from "products/Construction/ObjectHeaterIcon"; +import ResponsiveDialog from "common/ResponsiveDialog"; + + +interface Props { + deviceID: number + component: Component + currentState?: boolean +} + +const useStyles = makeStyles(() => { + return ({ + controllerDisplay: { + display: "flex", + justifyContent: "space-between", + paddingLeft: 5, + paddingRight: 5 + }, + }) +}) + +export default function BinControllerDisplay(props: Props) { + const {component, deviceID, currentState} = props + const [controllerState, setControllerState] = useState(0) + const [openDialog, setOpenDialog] = useState(false) + const [newOutputState, setNewOutputState] = useState(0) + const {openSnack} = useSnackbar() + const componentAPI = useComponentAPI() + const isMobile = useMobile() + const classes = useStyles() + + useEffect(()=>{ + setControllerState(component.settings.defaultOutputState) + },[component]) + + + const controllerIcon = () => { + if(component.subType() === quack.BooleanOutputSubtype.BOOLEAN_OUTPUT_SUBTYPE_HEATER){ + return + }else{ + return + } + } + + const setController = () => { + let newSettings = component.settings + newSettings.defaultOutputState = newOutputState + componentAPI.update(deviceID, newSettings).then(resp => { + openSnack("Updated controllers output state") + setControllerState(newOutputState) + }).catch(err => { + openSnack("There was a problem updating the controller") + }).finally(() => { + setOpenDialog(false) + }) + } + + const controllerDialog = () => { + return ( + {setOpenDialog(false)}}> + Set Controller State + + This Action will change the output state of the controller + + + + + + + ) + } + + const componentOn = () => { + if(currentState){ + return currentState + }else{ + let state = false + component.status.lastGoodMeasurement.forEach(um => { + if(um.type === quack.MeasurementType.MEASUREMENT_TYPE_BOOLEAN){ + if(um.values.length > 0){ + let readings = um.values + if(readings[readings.length-1].values.length > 0){ + let nodes = readings[readings.length-1].values + if (nodes[nodes.length -1] === 1){ + state = true + } + } + } + } + }) + return state + } + } + + return ( + + {controllerDialog()} + + + + {controllerIcon()} + + + {component.name()} + + + + { + setNewOutputState(0) + setOpenDialog(true) + } + }, + { + title: "On", + function: () => { + setNewOutputState(1) + setOpenDialog(true) + } + }, + { + title: "Off", + function: () => { + setNewOutputState(2) + setOpenDialog(true) + } + } + ]} + toggledButtons={[controllerState]} + toggle + /> + + {componentOn() ? "ON" : "OFF"} + + + + + ) + +} \ No newline at end of file diff --git a/src/bin/BinSettings.tsx b/src/bin/BinSettings.tsx index 4192974..58669d6 100644 --- a/src/bin/BinSettings.tsx +++ b/src/bin/BinSettings.tsx @@ -126,14 +126,13 @@ interface BinFormExtension { hopperHeight: string; diameter: string; grainBushels: string; - grainTonnes: string; + grainWeight: string; grainType: Option | null; grainUse: Option | null; grainSubtype: string; customTypeName: string; highTemp: number; lowTemp: number; - bushelsPerTonne: string; tempTarget: number; } @@ -160,14 +159,13 @@ export default function BinSettings(props: Props) { hopperHeight: "", diameter: "", grainBushels: "", - grainTonnes: "", + grainWeight: "", grainType: null, grainUse: null, grainSubtype: "", customTypeName: "", highTemp: 20, lowTemp: 10, - bushelsPerTonne: "", tempTarget: 15 }); const [initialized, setInitialized] = useState(false); @@ -194,6 +192,7 @@ export default function BinSettings(props: Props) { const [isCustomBin, setIsCustomBin] = useState(false); const [binModelOps, setBinModelOptions] = useState([]); const [selectedBinModel, setSelectedBinModel] = useState