mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-02 21:18:13 +00:00
chore: added cargo types json object validation & alert messages
This commit is contained in:
@@ -71,6 +71,7 @@
|
||||
<div class="details-cargo-types" v-if="currentVehicleGroupType == 'wagon'">
|
||||
<input type="checkbox" id="include-cargo-types" v-model="includeCargoTypes" />
|
||||
<label for="include-cargo-types">Ładunki (wagon):</label>
|
||||
(JSON: {{ isCargoTypesJsonValid ? 'poprawny' : 'niepoprawny' }})
|
||||
<br />
|
||||
<textarea name="cargo-types-textarea" id="cargo-types-textarea" v-model="cargoTypesJsonString">{{
|
||||
JSON.stringify(vehicleGroupValues.cargoTypes)
|
||||
@@ -161,6 +162,8 @@ onMounted(() => {
|
||||
modalElementRef.value?.focus();
|
||||
});
|
||||
|
||||
// JSON watchers
|
||||
|
||||
watch(massSpeedsJsonString, (val) => {
|
||||
try {
|
||||
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) {
|
||||
if (!vehicleGroup.locoProps) currentVehicleGroupType.value = 'wagon';
|
||||
|
||||
@@ -228,6 +240,16 @@ async function updateVehicleGroup() {
|
||||
|
||||
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 {
|
||||
const updatedData = (
|
||||
await client.put<UpdateVehicleGroupAPIResponse>(`/manager/vehicleGroups/${vehicleGroup.id}`, {
|
||||
@@ -249,7 +271,7 @@ async function updateVehicleGroup() {
|
||||
tableObject.vehicleGroupRef = updatedData;
|
||||
}
|
||||
|
||||
// alert('Zaktualizowano grupę: ' + updatedData.name);
|
||||
alert('Zaktualizowano grupę: ' + updatedData.name);
|
||||
closeModal();
|
||||
} catch (error) {
|
||||
alert(handleAPIErrors(error));
|
||||
@@ -274,7 +296,7 @@ async function removeVehicleGroup() {
|
||||
(v) => v.vehicleGroupRef.id != vehicleGroup.id,
|
||||
);
|
||||
|
||||
// alert('Usunięto pojazd: ' + removedData.name);
|
||||
alert('Usunięto pojazd: ' + removedData.name);
|
||||
closeModal();
|
||||
} catch (error) {
|
||||
alert(handleAPIErrors(error));
|
||||
|
||||
Reference in New Issue
Block a user