vehicle and equipment base
This commit is contained in:
parent
4338f58dea
commit
2b3231e26c
13 changed files with 912 additions and 8 deletions
|
@ -62,7 +62,7 @@ export const useNavigationStore = defineStore("navigation", {
|
|||
{
|
||||
key: "unit",
|
||||
title: "Wehr",
|
||||
levelDefault: "",
|
||||
levelDefault: "equipment",
|
||||
} as topLevelNavigationModel,
|
||||
]
|
||||
: []),
|
||||
|
@ -104,6 +104,13 @@ export const useNavigationStore = defineStore("navigation", {
|
|||
...(abilityStore.can("read", "club", "listprint") ? [{ key: "listprint", title: "Liste Drucken" }] : []),
|
||||
],
|
||||
},
|
||||
unit: {
|
||||
mainTitle: "Wehr",
|
||||
main: [
|
||||
...(abilityStore.can("read", "unit", "equipment") ? [{ key: "equipment", title: "Gerätschaften" }] : []),
|
||||
...(abilityStore.can("read", "unit", "vehicle") ? [{ key: "vehicle", title: "Fahrzeuge" }] : []),
|
||||
],
|
||||
},
|
||||
configuration: {
|
||||
mainTitle: "Einstellungen",
|
||||
main: [
|
||||
|
|
128
src/stores/admin/unit/equipment/equipment.ts
Normal file
128
src/stores/admin/unit/equipment/equipment.ts
Normal file
|
@ -0,0 +1,128 @@
|
|||
import { defineStore } from "pinia";
|
||||
import type {
|
||||
EquipmentViewModel,
|
||||
CreateEquipmentViewModel,
|
||||
EquipmentStatisticsViewModel,
|
||||
UpdateEquipmentViewModel,
|
||||
} from "@/viewmodels/admin/unit/equipment/equipment.models";
|
||||
import { http } from "@/serverCom";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
export const useEquipmentStore = defineStore("equipment", {
|
||||
state: () => {
|
||||
return {
|
||||
equipments: [] as Array<EquipmentViewModel & { tab_pos: number }>,
|
||||
totalCount: 0 as number,
|
||||
loading: "loading" as "loading" | "fetched" | "failed",
|
||||
activeEquipment: null as string | null,
|
||||
activeEquipmentObj: null as EquipmentViewModel | null,
|
||||
activeEquipmentStatistics: null as EquipmentStatisticsViewModel | null,
|
||||
loadingActive: "loading" as "loading" | "fetched" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchEquipments(offset = 0, count = 25, search = "", clear = false) {
|
||||
if (clear) this.equipments = [];
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get(`/admin/equipment?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
|
||||
.then((result) => {
|
||||
this.totalCount = result.data.total;
|
||||
result.data.equipments
|
||||
.filter((elem: EquipmentViewModel) => this.equipments.findIndex((m) => m.id == elem.id) == -1)
|
||||
.map((elem: EquipmentViewModel, index: number): EquipmentViewModel & { tab_pos: number } => {
|
||||
return {
|
||||
...elem,
|
||||
tab_pos: index + offset,
|
||||
};
|
||||
})
|
||||
.forEach((elem: EquipmentViewModel & { tab_pos: number }) => {
|
||||
this.equipments.push(elem);
|
||||
});
|
||||
this.loading = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
async getAllEquipments(): Promise<AxiosResponse<any, any>> {
|
||||
return await http.get(`/admin/equipment?noLimit=true`).then((res) => {
|
||||
return { ...res, data: res.data.equipments };
|
||||
});
|
||||
},
|
||||
async getEquipmentsByIds(ids: Array<string>): Promise<AxiosResponse<any, any>> {
|
||||
return await http
|
||||
.post(`/admin/equipment/ids`, {
|
||||
ids,
|
||||
})
|
||||
.then((res) => {
|
||||
return { ...res, data: res.data.equipments };
|
||||
});
|
||||
},
|
||||
async searchEquipments(search: string): Promise<AxiosResponse<any, any>> {
|
||||
return await http.get(`/admin/equipment?search=${search}&noLimit=true`).then((res) => {
|
||||
return { ...res, data: res.data.equipments };
|
||||
});
|
||||
},
|
||||
fetchEquipmentByActiveId() {
|
||||
this.loadingActive = "loading";
|
||||
http
|
||||
.get(`/admin/equipment/${this.activeEquipment}`)
|
||||
.then((res) => {
|
||||
this.activeEquipmentObj = res.data;
|
||||
this.loadingActive = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loadingActive = "failed";
|
||||
});
|
||||
},
|
||||
fetchEquipmentById(id: string) {
|
||||
return http.get(`/admin/equipment/${id}`);
|
||||
},
|
||||
fetchEquipmentStatisticsByActiveId() {
|
||||
http
|
||||
.get(`/admin/equipment/${this.activeEquipment}/statistics`)
|
||||
.then((res) => {
|
||||
this.activeEquipmentStatistics = res.data;
|
||||
})
|
||||
.catch((err) => {});
|
||||
},
|
||||
async printEquipmentByActiveId() {
|
||||
return http.get(`/admin/equipment/${this.activeEquipment}/print`, {
|
||||
responseType: "blob",
|
||||
});
|
||||
},
|
||||
fetchEquipmentStatisticsById(id: string) {
|
||||
return http.get(`/admin/equipment/${id}/statistics`);
|
||||
},
|
||||
async createEquipment(equipment: CreateEquipmentViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.post(`/admin/equipment`, {
|
||||
salutationId: equipment.salutationId,
|
||||
firstname: equipment.firstname,
|
||||
lastname: equipment.lastname,
|
||||
nameaffix: equipment.nameaffix,
|
||||
birthdate: equipment.birthdate,
|
||||
internalId: equipment.internalId,
|
||||
});
|
||||
this.fetchEquipments();
|
||||
return result;
|
||||
},
|
||||
async updateActiveEquipment(equipment: UpdateEquipmentViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/equipment/${equipment.id}`, {
|
||||
salutationId: equipment.salutationId,
|
||||
firstname: equipment.firstname,
|
||||
lastname: equipment.lastname,
|
||||
nameaffix: equipment.nameaffix,
|
||||
birthdate: equipment.birthdate,
|
||||
internalId: equipment.internalId,
|
||||
});
|
||||
this.fetchEquipments();
|
||||
return result;
|
||||
},
|
||||
async deleteEquipment(equipment: number): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.delete(`/admin/equipment/${equipment}`);
|
||||
this.fetchEquipments();
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
128
src/stores/admin/unit/vehicle/vehicle.ts
Normal file
128
src/stores/admin/unit/vehicle/vehicle.ts
Normal file
|
@ -0,0 +1,128 @@
|
|||
import { defineStore } from "pinia";
|
||||
import type {
|
||||
VehicleViewModel,
|
||||
CreateVehicleViewModel,
|
||||
VehicleStatisticsViewModel,
|
||||
UpdateVehicleViewModel,
|
||||
} from "@/viewmodels/admin/unit/vehicle/vehicle.models";
|
||||
import { http } from "@/serverCom";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
export const useVehicleStore = defineStore("vehicle", {
|
||||
state: () => {
|
||||
return {
|
||||
vehicles: [] as Array<VehicleViewModel & { tab_pos: number }>,
|
||||
totalCount: 0 as number,
|
||||
loading: "loading" as "loading" | "fetched" | "failed",
|
||||
activeVehicle: null as string | null,
|
||||
activeVehicleObj: null as VehicleViewModel | null,
|
||||
activeVehicleStatistics: null as VehicleStatisticsViewModel | null,
|
||||
loadingActive: "loading" as "loading" | "fetched" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchVehicles(offset = 0, count = 25, search = "", clear = false) {
|
||||
if (clear) this.vehicles = [];
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get(`/admin/vehicle?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
|
||||
.then((result) => {
|
||||
this.totalCount = result.data.total;
|
||||
result.data.vehicles
|
||||
.filter((elem: VehicleViewModel) => this.vehicles.findIndex((m) => m.id == elem.id) == -1)
|
||||
.map((elem: VehicleViewModel, index: number): VehicleViewModel & { tab_pos: number } => {
|
||||
return {
|
||||
...elem,
|
||||
tab_pos: index + offset,
|
||||
};
|
||||
})
|
||||
.forEach((elem: VehicleViewModel & { tab_pos: number }) => {
|
||||
this.vehicles.push(elem);
|
||||
});
|
||||
this.loading = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
async getAllVehicles(): Promise<AxiosResponse<any, any>> {
|
||||
return await http.get(`/admin/vehicle?noLimit=true`).then((res) => {
|
||||
return { ...res, data: res.data.vehicles };
|
||||
});
|
||||
},
|
||||
async getVehiclesByIds(ids: Array<string>): Promise<AxiosResponse<any, any>> {
|
||||
return await http
|
||||
.post(`/admin/vehicle/ids`, {
|
||||
ids,
|
||||
})
|
||||
.then((res) => {
|
||||
return { ...res, data: res.data.vehicles };
|
||||
});
|
||||
},
|
||||
async searchVehicles(search: string): Promise<AxiosResponse<any, any>> {
|
||||
return await http.get(`/admin/vehicle?search=${search}&noLimit=true`).then((res) => {
|
||||
return { ...res, data: res.data.vehicles };
|
||||
});
|
||||
},
|
||||
fetchVehicleByActiveId() {
|
||||
this.loadingActive = "loading";
|
||||
http
|
||||
.get(`/admin/vehicle/${this.activeVehicle}`)
|
||||
.then((res) => {
|
||||
this.activeVehicleObj = res.data;
|
||||
this.loadingActive = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loadingActive = "failed";
|
||||
});
|
||||
},
|
||||
fetchVehicleById(id: string) {
|
||||
return http.get(`/admin/vehicle/${id}`);
|
||||
},
|
||||
fetchVehicleStatisticsByActiveId() {
|
||||
http
|
||||
.get(`/admin/vehicle/${this.activeVehicle}/statistics`)
|
||||
.then((res) => {
|
||||
this.activeVehicleStatistics = res.data;
|
||||
})
|
||||
.catch((err) => {});
|
||||
},
|
||||
async printVehicleByActiveId() {
|
||||
return http.get(`/admin/vehicle/${this.activeVehicle}/print`, {
|
||||
responseType: "blob",
|
||||
});
|
||||
},
|
||||
fetchVehicleStatisticsById(id: string) {
|
||||
return http.get(`/admin/vehicle/${id}/statistics`);
|
||||
},
|
||||
async createVehicle(vehicle: CreateVehicleViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.post(`/admin/vehicle`, {
|
||||
salutationId: vehicle.salutationId,
|
||||
firstname: vehicle.firstname,
|
||||
lastname: vehicle.lastname,
|
||||
nameaffix: vehicle.nameaffix,
|
||||
birthdate: vehicle.birthdate,
|
||||
internalId: vehicle.internalId,
|
||||
});
|
||||
this.fetchVehicles();
|
||||
return result;
|
||||
},
|
||||
async updateActiveVehicle(vehicle: UpdateVehicleViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/vehicle/${vehicle.id}`, {
|
||||
salutationId: vehicle.salutationId,
|
||||
firstname: vehicle.firstname,
|
||||
lastname: vehicle.lastname,
|
||||
nameaffix: vehicle.nameaffix,
|
||||
birthdate: vehicle.birthdate,
|
||||
internalId: vehicle.internalId,
|
||||
});
|
||||
this.fetchVehicles();
|
||||
return result;
|
||||
},
|
||||
async deleteVehicle(vehicle: number): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.delete(`/admin/vehicle/${vehicle}`);
|
||||
this.fetchVehicles();
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue