Skip to content

Commit

Permalink
Correctly stringify numbers in textboxes (#921)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
srimanachanta authored Sep 26, 2023
1 parent 2cb87c5 commit 43eefcf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
15 changes: 9 additions & 6 deletions photon-client/src/components/cameras/CameraSettingsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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>
Expand Down
7 changes: 6 additions & 1 deletion photon-client/src/components/common/cv-range-slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion photon-client/src/components/common/cv-slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public static void onCameraSettingsRequest(Context ctx) {
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);
Expand All @@ -333,7 +333,7 @@ public static void onCameraSettingsRequest(Context ctx) {
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);
Expand Down

0 comments on commit 43eefcf

Please sign in to comment.