vehicle update screen
This commit is contained in:
parent
70e9b47483
commit
9ee1cca46d
2 changed files with 119 additions and 3 deletions
|
@ -780,8 +780,8 @@ const router = createRouter({
|
||||||
{
|
{
|
||||||
path: "edit",
|
path: "edit",
|
||||||
name: "admin-unit-vehicle_type-edit",
|
name: "admin-unit-vehicle_type-edit",
|
||||||
component: () => import("@/views/admin/ViewSelect.vue"),
|
component: () => import("@/views/admin/unit/vehicleType/UpdateVehicleType.vue"),
|
||||||
meta: { type: "update", section: "unit", module: "equipment_type" },
|
meta: { type: "update", section: "unit", module: "vehicle_type" },
|
||||||
beforeEnter: [abilityAndNavUpdate],
|
beforeEnter: [abilityAndNavUpdate],
|
||||||
props: true,
|
props: true,
|
||||||
},
|
},
|
||||||
|
@ -828,7 +828,7 @@ const router = createRouter({
|
||||||
path: "create",
|
path: "create",
|
||||||
name: "admin-unit-inspection_plan-create",
|
name: "admin-unit-inspection_plan-create",
|
||||||
component: () => import("@/views/admin/unit/inspectionPlan/CreateInspectionPlan.vue"),
|
component: () => import("@/views/admin/unit/inspectionPlan/CreateInspectionPlan.vue"),
|
||||||
meta: { type: "create", section: "unit", module: "equipment" },
|
meta: { type: "create", section: "unit", module: "inspection_plan" },
|
||||||
beforeEnter: [abilityAndNavUpdate],
|
beforeEnter: [abilityAndNavUpdate],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
116
src/views/admin/unit/vehicleType/UpdateVehicleType.vue
Normal file
116
src/views/admin/unit/vehicleType/UpdateVehicleType.vue
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
|
||||||
|
<Spinner v-if="loading == 'loading'" class="mx-auto" />
|
||||||
|
<p v-else-if="loading == 'failed'">laden fehlgeschlagen</p>
|
||||||
|
<form
|
||||||
|
v-else-if="vehicleType != null"
|
||||||
|
class="flex flex-col gap-4 py-2 w-full max-w-xl mx-auto"
|
||||||
|
@submit.prevent="triggerUpdate"
|
||||||
|
>
|
||||||
|
<p class="mx-auto">Fahrzeug-Typ bearbeiten</p>
|
||||||
|
<div>
|
||||||
|
<label for="name">Typ</label>
|
||||||
|
<input type="text" id="name" required v-model="vehicleType.type" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="location">Beschreibung</label>
|
||||||
|
<input type="text" id="location" v-model="vehicleType.description" />
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-row justify-end gap-2">
|
||||||
|
<button primary-outline type="reset" class="w-fit!" :disabled="canSaveOrReset" @click="resetForm">
|
||||||
|
abbrechen
|
||||||
|
</button>
|
||||||
|
<button primary type="submit" class="w-fit!" :disabled="status == 'loading'">speichern</button>
|
||||||
|
<Spinner v-if="status == 'loading'" class="my-auto" />
|
||||||
|
<SuccessCheckmark v-else-if="status?.status == 'success'" />
|
||||||
|
<FailureXMark v-else-if="status?.status == 'failed'" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { defineComponent } from "vue";
|
||||||
|
import { mapActions, mapState } from "pinia";
|
||||||
|
import { useVehicleTypeStore } from "@/stores/admin/unit/vehicleType/vehicleType";
|
||||||
|
import type {
|
||||||
|
CreateVehicleTypeViewModel,
|
||||||
|
VehicleTypeViewModel,
|
||||||
|
UpdateVehicleTypeViewModel,
|
||||||
|
} from "@/viewmodels/admin/unit/vehicleType/vehicleType.models";
|
||||||
|
import Spinner from "@/components/Spinner.vue";
|
||||||
|
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
||||||
|
import FailureXMark from "@/components/FailureXMark.vue";
|
||||||
|
import isEqual from "lodash.isequal";
|
||||||
|
import cloneDeep from "lodash.clonedeep";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
export default defineComponent({
|
||||||
|
props: {
|
||||||
|
vehicleTypeId: String,
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
loadingActive() {
|
||||||
|
if (this.loading == "loading") {
|
||||||
|
this.loading = this.loadingActive;
|
||||||
|
}
|
||||||
|
if (this.loadingActive == "fetched") this.vehicleType = cloneDeep(this.activeVehicleTypeObj);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
loading: "loading" as "loading" | "fetched" | "failed",
|
||||||
|
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
|
||||||
|
vehicleType: null as null | VehicleTypeViewModel,
|
||||||
|
timeout: null as any,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
canSaveOrReset(): boolean {
|
||||||
|
return isEqual(this.activeVehicleTypeObj, this.vehicleType);
|
||||||
|
},
|
||||||
|
...mapState(useVehicleTypeStore, ["activeVehicleTypeObj", "loadingActive"]),
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.fetchItem();
|
||||||
|
},
|
||||||
|
beforeUnmount() {
|
||||||
|
try {
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
} catch (error) {}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(useVehicleTypeStore, ["updateActiveVehicleType", "fetchVehicleTypeByActiveId"]),
|
||||||
|
resetForm() {
|
||||||
|
this.vehicleType = cloneDeep(this.activeVehicleTypeObj);
|
||||||
|
},
|
||||||
|
fetchItem() {
|
||||||
|
this.fetchVehicleTypeByActiveId();
|
||||||
|
},
|
||||||
|
triggerUpdate(e: any) {
|
||||||
|
if (this.vehicleType == null) return;
|
||||||
|
let formData = e.target.elements;
|
||||||
|
let updateVehicleType: UpdateVehicleTypeViewModel = {
|
||||||
|
id: this.vehicleType.id,
|
||||||
|
type: formData.type.value,
|
||||||
|
description: formData.description.value,
|
||||||
|
};
|
||||||
|
this.status = "loading";
|
||||||
|
this.updateActiveVehicleType(updateVehicleType)
|
||||||
|
.then((res) => {
|
||||||
|
this.fetchItem();
|
||||||
|
this.status = { status: "success" };
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.status = { status: "failed" };
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.timeout = setTimeout(() => {
|
||||||
|
this.status = null;
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Reference in a new issue