From 2a4e032c99ec7b9b54784230f63114760ace4675 Mon Sep 17 00:00:00 2001 From: BurnLP2013 Date: Sun, 13 Oct 2024 23:05:31 +0200 Subject: [PATCH] added basic update mock for lat and lng fields --- web/src/components/TableCategory.vue | 32 ++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/web/src/components/TableCategory.vue b/web/src/components/TableCategory.vue index 4361b65..b327936 100644 --- a/web/src/components/TableCategory.vue +++ b/web/src/components/TableCategory.vue @@ -20,8 +20,14 @@ {{ node.status }} - {{ node.position.lat }} - {{ node.position.lng }} + {{ node.position.lat }} + {{ node.position.lng }} {{ calculateBatteryPercentage(node.batteryVoltage, node.minVoltage, node.maxVoltage) }}% {{ node.temperature }}°C {{ node.runtime }} @@ -121,6 +127,28 @@ export default { } else { return ((currentVoltage - minVoltage) / (maxVoltage - minVoltage) * 100).toFixed(2); } + }, + validateAndUpdateLatLng(node, field, event) { + const originalValue = node.position[field]; + let newValue = event.target.innerText; + + // normalize seperated values + newValue = newValue.replace(',', '.'); + + // check if float value + const validNumberRegex = /^-?\d+(\.\d+)?$/; + + if (validNumberRegex.test(newValue)) { + const parsedValue = parseFloat(newValue); + + // Update if valid + node.position[field] = parsedValue; + console.log(`Updated ${field} of ${node.name}: ${parsedValue}`); + } else { + // Reset to original value if invalid + event.target.innerText = originalValue; + console.log(`Failed to set ${field} of ${node.name}: Invalid input "${newValue}"`); + } } } };