chore: added cargo types json object validation & alert messages

This commit is contained in:
2025-12-02 02:18:59 +01:00
parent be148c2aee
commit 7eeaeb28d4
@@ -71,6 +71,7 @@
<div class="details-cargo-types" v-if="currentVehicleGroupType == 'wagon'"> <div class="details-cargo-types" v-if="currentVehicleGroupType == 'wagon'">
<input type="checkbox" id="include-cargo-types" v-model="includeCargoTypes" /> <input type="checkbox" id="include-cargo-types" v-model="includeCargoTypes" />
<label for="include-cargo-types">Ładunki (wagon):</label> <label for="include-cargo-types">Ładunki (wagon):</label>
(JSON: {{ isCargoTypesJsonValid ? 'poprawny' : 'niepoprawny' }})
<br /> <br />
<textarea name="cargo-types-textarea" id="cargo-types-textarea" v-model="cargoTypesJsonString">{{ <textarea name="cargo-types-textarea" id="cargo-types-textarea" v-model="cargoTypesJsonString">{{
JSON.stringify(vehicleGroupValues.cargoTypes) JSON.stringify(vehicleGroupValues.cargoTypes)
@@ -161,6 +162,8 @@ onMounted(() => {
modalElementRef.value?.focus(); modalElementRef.value?.focus();
}); });
// JSON watchers
watch(massSpeedsJsonString, (val) => { watch(massSpeedsJsonString, (val) => {
try { try {
JSON.parse(val); JSON.parse(val);
@@ -170,6 +173,15 @@ watch(massSpeedsJsonString, (val) => {
} }
}); });
watch(cargoTypesJsonString, (val) => {
try {
JSON.parse(val);
isCargoTypesJsonValid.value = true;
} catch (error) {
isCargoTypesJsonValid.value = false;
}
});
function populateVehicleGroupValues(vehicleGroup: IVehicleGroup) { function populateVehicleGroupValues(vehicleGroup: IVehicleGroup) {
if (!vehicleGroup.locoProps) currentVehicleGroupType.value = 'wagon'; if (!vehicleGroup.locoProps) currentVehicleGroupType.value = 'wagon';
@@ -228,6 +240,16 @@ async function updateVehicleGroup() {
if (!vehicleGroup) return; if (!vehicleGroup) return;
if (!isMassSpeedsJsonValid.value) {
alert('JSON dopuszczalnych mas jest niepoprawny! Popraw go przed zaktualizowaniem danych!');
return;
}
if (!isCargoTypesJsonValid.value) {
alert('JSON ładunków jest niepoprawny! Popraw go przed zaktualizowaniem danych!');
return;
}
try { try {
const updatedData = ( const updatedData = (
await client.put<UpdateVehicleGroupAPIResponse>(`/manager/vehicleGroups/${vehicleGroup.id}`, { await client.put<UpdateVehicleGroupAPIResponse>(`/manager/vehicleGroups/${vehicleGroup.id}`, {
@@ -249,7 +271,7 @@ async function updateVehicleGroup() {
tableObject.vehicleGroupRef = updatedData; tableObject.vehicleGroupRef = updatedData;
} }
// alert('Zaktualizowano grupę: ' + updatedData.name); alert('Zaktualizowano grupę: ' + updatedData.name);
closeModal(); closeModal();
} catch (error) { } catch (error) {
alert(handleAPIErrors(error)); alert(handleAPIErrors(error));
@@ -274,7 +296,7 @@ async function removeVehicleGroup() {
(v) => v.vehicleGroupRef.id != vehicleGroup.id, (v) => v.vehicleGroupRef.id != vehicleGroup.id,
); );
// alert('Usunięto pojazd: ' + removedData.name); alert('Usunięto pojazd: ' + removedData.name);
closeModal(); closeModal();
} catch (error) { } catch (error) {
alert(handleAPIErrors(error)); alert(handleAPIErrors(error));