added basic update mock for lat and lng fields

This commit is contained in:
BurnLP2013 2024-10-13 23:05:31 +02:00
parent 644dd6394e
commit 2a4e032c99

View file

@ -20,8 +20,14 @@
{{ node.status }} {{ node.status }}
</span> </span>
</td> </td>
<td>{{ node.position.lat }}</td> <td
<td>{{ node.position.lng }}</td> contenteditable="true"
@blur="validateAndUpdateLatLng(node, 'lat', $event)"
>{{ node.position.lat }}</td>
<td
contenteditable="true"
@blur="validateAndUpdateLatLng(node, 'lng', $event)"
>{{ node.position.lng }}</td>
<td>{{ calculateBatteryPercentage(node.batteryVoltage, node.minVoltage, node.maxVoltage) }}%</td> <td>{{ calculateBatteryPercentage(node.batteryVoltage, node.minVoltage, node.maxVoltage) }}%</td>
<td>{{ node.temperature }}°C</td> <td>{{ node.temperature }}°C</td>
<td>{{ node.runtime }}</td> <td>{{ node.runtime }}</td>
@ -121,6 +127,28 @@ export default {
} else { } else {
return ((currentVoltage - minVoltage) / (maxVoltage - minVoltage) * 100).toFixed(2); 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}"`);
}
} }
} }
}; };