base views and store
This commit is contained in:
parent
b9b0381356
commit
b56347c172
29 changed files with 655 additions and 22 deletions
|
@ -120,12 +120,11 @@ export const useNavigationStore = defineStore("navigation", {
|
|||
? [{ key: "respiratory_mission", title: "Atemschutz-Einsätze" }]
|
||||
: []),
|
||||
...(abilityStore.can("create", "unit", "inspection") ? [{ key: "inspection", title: "Prüfungen" }] : []),
|
||||
...(abilityStore.can("read", "unit", "maintenance") ? [{ key: "maintenance", title: "Wartungen" }] : []),
|
||||
...(abilityStore.can("read", "unit", "damage_report")
|
||||
? [{ key: "damage_report", title: "Schadensmeldungen" }]
|
||||
: []),
|
||||
...(abilityStore.can("read", "unit", "maintenance")
|
||||
? [{ key: "maintenance", title: "Wartungen / Reparaturen" }]
|
||||
: []),
|
||||
...(abilityStore.can("read", "unit", "repair") ? [{ key: "repair", title: "Reparaturen" }] : []),
|
||||
{ key: "divider1", title: "Basisdaten" },
|
||||
...(abilityStore.can("read", "unit", "equipment_type")
|
||||
? [{ key: "equipment_type", title: "Geräte-Typen" }]
|
||||
|
|
106
src/stores/admin/unit/repair.ts
Normal file
106
src/stores/admin/unit/repair.ts
Normal file
|
@ -0,0 +1,106 @@
|
|||
import { defineStore } from "pinia";
|
||||
import type { RepairViewModel, UpdateRepairViewModel } from "@/viewmodels/admin/unit/repair.models";
|
||||
import { http } from "@/serverCom";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
export const useRepairStore = defineStore("repair", {
|
||||
state: () => {
|
||||
return {
|
||||
repairs: [] as Array<RepairViewModel & { tab_pos: number }>,
|
||||
totalCount: 0 as number,
|
||||
loading: "loading" as "loading" | "fetched" | "failed",
|
||||
activeRepair: null as string | null,
|
||||
activeRepairObj: null as RepairViewModel | null,
|
||||
loadingActive: "loading" as "loading" | "fetched" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
formatQueryReturnToPagination(result: AxiosResponse<any, any>, offset: number) {
|
||||
this.totalCount = result.data.total;
|
||||
result.data.repairs
|
||||
.filter((elem: RepairViewModel) => this.repairs.findIndex((m) => m.id == elem.id) == -1)
|
||||
.map((elem: RepairViewModel, index: number): RepairViewModel & { tab_pos: number } => {
|
||||
return {
|
||||
...elem,
|
||||
tab_pos: index + offset,
|
||||
};
|
||||
})
|
||||
.forEach((elem: RepairViewModel & { tab_pos: number }) => {
|
||||
this.repairs.push(elem);
|
||||
});
|
||||
},
|
||||
fetchOpenRepairs(offset = 0, count = 25, search = "", clear = false) {
|
||||
if (clear) this.repairs = [];
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get(`/admin/repair?done=false&offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
|
||||
.then((result) => {
|
||||
this.formatQueryReturnToPagination(result, offset);
|
||||
this.loading = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
fetchDoneRepairs(offset = 0, count = 25, search = "", clear = false) {
|
||||
if (clear) this.repairs = [];
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get(`/admin/repair?done=true&offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
|
||||
.then((result) => {
|
||||
this.formatQueryReturnToPagination(result, offset);
|
||||
this.loading = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
async getAllRepairs(): Promise<AxiosResponse<any, any>> {
|
||||
return await http.get(`/admin/repair?noLimit=true`).then((res) => {
|
||||
return { ...res, data: res.data.repairs };
|
||||
});
|
||||
},
|
||||
async getRepairsByIds(ids: Array<string>): Promise<AxiosResponse<any, any>> {
|
||||
return await http
|
||||
.post(`/admin/repair/ids`, {
|
||||
ids,
|
||||
})
|
||||
.then((res) => {
|
||||
return { ...res, data: res.data.repairs };
|
||||
});
|
||||
},
|
||||
async searchRepairs(search: string): Promise<AxiosResponse<any, any>> {
|
||||
return await http.get(`/admin/repair?search=${search}&noLimit=true`).then((res) => {
|
||||
return { ...res, data: res.data.repairs };
|
||||
});
|
||||
},
|
||||
fetchRepairByActiveId() {
|
||||
this.loadingActive = "loading";
|
||||
http
|
||||
.get(`/admin/repair/${this.activeRepair}`)
|
||||
.then((res) => {
|
||||
this.activeRepairObj = res.data;
|
||||
this.loadingActive = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loadingActive = "failed";
|
||||
});
|
||||
},
|
||||
fetchRepairById(id: string) {
|
||||
return http.get(`/admin/repair/${id}`);
|
||||
},
|
||||
loadRepairImage(url: string) {
|
||||
return http.get(`/admin/repair/${this.activeRepairObj?.id}/${url}`, {
|
||||
responseType: "blob",
|
||||
});
|
||||
},
|
||||
async updateRepair(repair: UpdateRepairViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/repair/${repair.id}`, {
|
||||
status: repair.status,
|
||||
noteByWorker: repair.noteByWorker,
|
||||
done: repair.done,
|
||||
});
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue