Correctly stringify numbers in textboxes (#921)

* fix an issue where the fov isnt reset on error

* Fix issue with incorrectly reading fov on update

* Properly handle NPE in case of error

* Fix issue with vuetify comps not converting strings to numbers

* Formatting fixes
This commit is contained in:
Sriman Achanta
2023-09-26 08:02:18 -04:00
committed by GitHub
parent 2cb87c5a88
commit 43eefcf1c5
4 changed files with 18 additions and 10 deletions

View File

@@ -3,20 +3,22 @@ import CvSelect from "@/components/common/cv-select.vue";
import CvNumberInput from "@/components/common/cv-number-input.vue";
import { useCameraSettingsStore } from "@/stores/settings/CameraSettingsStore";
import { useStateStore } from "@/stores/StateStore";
import { ref } from "vue";
import { ref, watchEffect } from "vue";
const currentFov = ref(useCameraSettingsStore().currentCameraSettings.fov.value);
const currentFov = ref();
const saveCameraSettings = () => {
useCameraSettingsStore()
.updateCameraSettings({ fov: currentFov.value }, true)
.updateCameraSettings({ fov: currentFov.value }, false)
.then((response) => {
useCameraSettingsStore().currentCameraSettings.fov.value = currentFov.value;
useStateStore().showSnackbarMessage({
color: "success",
message: response.data.text || response.data
});
})
.catch((error) => {
currentFov.value = useCameraSettingsStore().currentCameraSettings.fov.value;
if (error.response) {
useStateStore().showSnackbarMessage({
color: "error",
@@ -33,11 +35,12 @@ const saveCameraSettings = () => {
message: "An error occurred while trying to process the request."
});
}
})
.finally(() => {
useCameraSettingsStore().currentCameraSettings.fov.value = currentFov.value;
});
};
watchEffect(() => {
currentFov.value = useCameraSettingsStore().currentCameraSettings.fov.value;
});
</script>
<template>

View File

@@ -32,7 +32,12 @@ const localValue = computed<[number, number]>({
get: (): [number, number] => {
return Object.values(props.value) as [number, number];
},
set: (v) => emit("input", v)
set: (v) => {
for (let i = 0; i < v.length; i++) {
v[i] = parseFloat(v[i] as unknown as string);
}
emit("input", v);
}
});
const changeFromSlot = (v: number, i: number) => {

View File

@@ -27,7 +27,7 @@ const emit = defineEmits<{
const localValue = computed({
get: () => props.value,
set: (v) => emit("input", v)
set: (v) => emit("input", parseFloat(v as unknown as string))
});
</script>

View File

@@ -323,7 +323,7 @@ public class RequestHandler {
var data = kObjectMapper.readTree(ctx.body());
int index = data.get("index").asInt();
double fov = kObjectMapper.readTree(data.get("settings").asText()).get("fov").asDouble();
double fov = data.get("settings").get("fov").asDouble();
var module = VisionModuleManager.getInstance().getModule(index);
module.setFov(fov);
@@ -333,7 +333,7 @@ public class RequestHandler {
ctx.status(200);
ctx.result("Successfully saved camera settings");
logger.info("Successfully saved camera settings");
} catch (JsonProcessingException e) {
} catch (JsonProcessingException | NullPointerException e) {
ctx.status(400);
ctx.result("The provided camera settings were malformed");
logger.error("The provided camera settings were malformed", e);