diff --git a/nginx.conf b/nginx.conf index b390bff..1537b32 100644 --- a/nginx.conf +++ b/nginx.conf @@ -71,6 +71,12 @@ http { add_header Cache-Control "no-store, no-cache, must-revalidate"; } + # Force re-cache of old service-worker + location = /service-worker.js { + root /usr/share/nginx/html; # adjust if your build folder is elsewhere + add_header Cache-Control "no-store, no-cache, must-revalidate"; + } + # Redirect old /index.html requests to new file location = /index.html { return 301 /indexV2.html; diff --git a/package-lock.json b/package-lock.json index 6292c47..dd7737d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10911,7 +10911,7 @@ }, "node_modules/protobuf-ts": { "version": "1.0.0", - "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#70351a87aa4a83bd6274adf8e3b7937090ab4cc2", + "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#c669ff3b4818861ef356c59eee671313ac090ddb", "dependencies": { "protobufjs": "^6.8.8" } diff --git a/public/service-worker.js b/public/service-worker.js new file mode 100644 index 0000000..6b6a19c --- /dev/null +++ b/public/service-worker.js @@ -0,0 +1,24 @@ +// public/service-worker.js +self.addEventListener('install', () => self.skipWaiting()); + +self.addEventListener('activate', async () => { + // Unregister old CRA SW + const regs = await self.registration.scope ? [self.registration] : await self.clients.getRegistrations(); + for (const reg of regs) { + if (reg && reg.scriptURL.endsWith('service-worker.js')) { + await reg.unregister(); + } + } + + // Clear all caches + if ('caches' in self) { + const keys = await caches.keys(); + for (const key of keys) { + await caches.delete(key); + } + } + + // Reload all clients + const clients = await self.clients.matchAll({ type: 'window' }); + clients.forEach(client => client.navigate(client.url)); +}); diff --git a/src/bin/BinCardV2.tsx b/src/bin/BinCardV2.tsx index 7026f8f..4bfcb4f 100644 --- a/src/bin/BinCardV2.tsx +++ b/src/bin/BinCardV2.tsx @@ -103,8 +103,10 @@ export default function BinCard(props: Props) { let filteredNodes = c.filteredNodes(true) allTemps.push(...filteredNodes.temps); - allHums.push(...filteredNodes.humids); - allMoistures.push(...filteredNodes.moistures); + if(avg(c.humidities) !== 0){ //if the average of the humidities is 0 that means that all the readings are 0 and it is a temp only cable + allHums.push(...filteredNodes.humids); + allMoistures.push(...filteredNodes.moistures); + } //set the hottest and coldest nodes if (coldestNode === undefined || Math.min(...filteredNodes.temps) < coldestNode.temp) { diff --git a/src/bin/BinDuplication.tsx b/src/bin/BinDuplication.tsx index d546e44..113830a 100644 --- a/src/bin/BinDuplication.tsx +++ b/src/bin/BinDuplication.tsx @@ -34,7 +34,7 @@ export default function BinDuplication(props: Props) { binAPI .addBin(settings) .then(resp => { - openSnack("Successfully duplicated bin"); + openSnack("Successfully duplicated bin"); }) .catch(err => { openSnack("Failed to duplicate bin"); diff --git a/src/bin/BinSVGV2.tsx b/src/bin/BinSVGV2.tsx index 2c7a888..c3c1a40 100644 --- a/src/bin/BinSVGV2.tsx +++ b/src/bin/BinSVGV2.tsx @@ -476,11 +476,11 @@ export default function BinSVGV2(props: Props) { return cableGrainPath; }; - const nodeClass = (nodeTemp: number) => { - if (hottestNodeTemp && hottestNodeTemp.toFixed(2) === nodeTemp.toFixed(2)) { + const nodeClass = (nodeTemp: number, underTop: boolean) => { + if (hottestNodeTemp && hottestNodeTemp.toFixed(2) === nodeTemp.toFixed(2) && underTop) { return classes.hotNode; } - if (coldestNodeTemp && coldestNodeTemp.toFixed(2) === nodeTemp.toFixed(2)) { + if (coldestNodeTemp && coldestNodeTemp.toFixed(2) === nodeTemp.toFixed(2) && underTop) { return classes.coldNode; } return classes.cableNode; @@ -507,12 +507,12 @@ export default function BinSVGV2(props: Props) { //if the cables have the same number of nodes if (b.temperatures.length === a.temperatures.length) { //sort by temp only last and any type that has humidity first - if ( - a.settings.subtype === quack.GrainCableSubtype.GRAIN_CABLE_SUBTYPE_OPI_TEMP && - b.settings.subtype !== quack.GrainCableSubtype.GRAIN_CABLE_SUBTYPE_OPI_TEMP - ) { + if ((avg(a.humidities) === 0 || a.humidities.length === 0) && (avg(b.humidities) !== 0 || b.humidities.length > 0)) { return 1; - } else { + } else if ((avg(b.humidities) === 0 || b.humidities.length === 0) && (avg(a.humidities) !== 0 || a.humidities.length > 0)) { + return -1; + } + else { return a.key() > b.key() ? 1 : -1; } } @@ -759,7 +759,7 @@ export default function BinSVGV2(props: Props) { return ( {e.nodeNumber === topNode && !e.excluded && topNodeHat(cablePos, e.y)} - + ) } diff --git a/src/bin/BinVisualizerV2.tsx b/src/bin/BinVisualizerV2.tsx index 0db4690..7bfc8a1 100644 --- a/src/bin/BinVisualizerV2.tsx +++ b/src/bin/BinVisualizerV2.tsx @@ -250,6 +250,7 @@ export default function BinVisualizer(props: Props) { const [cfmHighOpen, setCFMHighOpen] = useState(false); const [{ user }] = useGlobalState(); const [newPreset, setNewPreset] = useState(pond.BinMode.BIN_MODE_NONE); + const [newBinMode, setNewBinMode] = useState(pond.BinMode.BIN_MODE_NONE); const [selectedCable, setSelectedCable] = useState(); const [openNodeDialog, setOpenNodeDialog] = useState(false); const [cableDevice, setCableDevice] = useState(); @@ -345,6 +346,7 @@ export default function BinVisualizer(props: Props) { setGrainOption(ToGrainOption(bin.settings.inventory.grainType)); setBushPerTonne(bin.settings.inventory.bushelsPerTonne.toFixed(2)); setGrainSubtype(bin.subtype()); + setNewBinMode(bin.settings.mode); } if (bin.settings) { let t = bin.settings.outdoorTemp; @@ -384,8 +386,11 @@ export default function BinVisualizer(props: Props) { //also reverse it so that the node 1 (end of the cable) is in the first position let filteredNodes = cable.filteredNodes(true) temps.push(...filteredNodes.temps) - humids.push(...filteredNodes.humids) - emcs.push(...filteredNodes.moistures) + //only push to the humidity values if the cable reads humidities + if(cable.subType() !== quack.GrainCableSubtype.GRAIN_CABLE_SUBTYPE_OPI_TEMP){ + humids.push(...filteredNodes.humids) + emcs.push(...filteredNodes.moistures) + } // let tempClone = cloneDeep(cable.temperatures).reverse(); // let humClone = cloneDeep(cable.humidities).reverse(); // let emcClone = cloneDeep(cable.grainMoistures).reverse(); @@ -409,14 +414,15 @@ export default function BinVisualizer(props: Props) { //if the lowest temp for this cable is less than the temp in the low node conditions or the low node conditions are not set //use this cables lowest node and trend data in the condition - if (!lowNodeConditions || Math.min(...temps) < lowNodeConditions.tempC) { + if (!lowNodeConditions || Math.min(...filteredNodes.temps) < lowNodeConditions.tempC) { //determine which node is the coldest so that the data displayed is for the same node let lowTempIndex = - temps.indexOf(Math.min(...temps)) === -1 ? 0 : temps.indexOf(Math.min(...temps)); + filteredNodes.temps.indexOf(Math.min(...filteredNodes.temps)) === -1 ? 0 : filteredNodes.temps.indexOf(Math.min(...filteredNodes.temps)); + console.log(lowTempIndex) lowNodeConditions = { - tempC: temps[lowTempIndex], - humidity: humids[lowTempIndex], - emc: emcs[lowTempIndex], + tempC: filteredNodes.temps[lowTempIndex], + humidity: filteredNodes.humids[lowTempIndex], + emc: filteredNodes.moistures[lowTempIndex], tempCTrend: cableTrendData.coldNodeTrend?.tempTrend ?? 0, humidityTrend: cableTrendData.coldNodeTrend?.humidityTrend ?? 0, emcTrend: cableTrendData.coldNodeTrend?.emcTrend ?? 0 @@ -424,13 +430,13 @@ export default function BinVisualizer(props: Props) { } //do the same for the high node - if (!highNodeConditions || cable.maxTemp() > highNodeConditions.tempC) { + if (!highNodeConditions || Math.max(...filteredNodes.temps) > highNodeConditions.tempC) { let highTempIndex = - temps.indexOf(Math.max(...temps)) === -1 ? 0 : temps.indexOf(Math.max(...temps)); + filteredNodes.temps.indexOf(Math.max(...filteredNodes.temps)) === -1 ? 0 : filteredNodes.temps.indexOf(Math.max(...filteredNodes.temps)); highNodeConditions = { - tempC: temps[highTempIndex], - humidity: humids[highTempIndex], - emc: emcs[highTempIndex], + tempC: filteredNodes.temps[highTempIndex], + humidity: filteredNodes.humids[highTempIndex], + emc: filteredNodes.humids[highTempIndex], tempCTrend: cableTrendData.hotNodeTrend?.tempTrend ?? 0, humidityTrend: cableTrendData.hotNodeTrend?.humidityTrend ?? 0, emcTrend: cableTrendData.hotNodeTrend?.emcTrend ?? 0 @@ -1967,6 +1973,7 @@ export default function BinVisualizer(props: Props) { const setModeStorage = () => { setNewPreset(pond.BinMode.BIN_MODE_STORAGE); + setNewBinMode(pond.BinMode.BIN_MODE_STORAGE); }; const setModeCooldown = () => { @@ -1974,6 +1981,7 @@ export default function BinVisualizer(props: Props) { return; } setNewPreset(pond.BinMode.BIN_MODE_COOLDOWN); + setNewBinMode(pond.BinMode.BIN_MODE_COOLDOWN); }; const setModeDrying = () => { @@ -1982,13 +1990,16 @@ export default function BinVisualizer(props: Props) { bin.settings.inventory?.initialMoisture < bin.settings.inventory?.targetMoisture ) { setNewPreset(pond.BinMode.BIN_MODE_HYDRATING); + setNewBinMode(pond.BinMode.BIN_MODE_HYDRATING); } else { setNewPreset(pond.BinMode.BIN_MODE_DRYING); + setNewBinMode(pond.BinMode.BIN_MODE_DRYING); } }; const closeMoistureDialog = () => { setNewPreset(0); + setNewBinMode(bin.settings.mode); setShowInputMoisture(false); }; @@ -2049,6 +2060,7 @@ export default function BinVisualizer(props: Props) {