next and running inspections

This commit is contained in:
Julian Krauser 2025-07-10 13:22:38 +02:00
parent 1409cf8045
commit 74b05ee97f
14 changed files with 280 additions and 75 deletions

View file

@ -3,19 +3,77 @@ import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type {
CreateInspectionViewModel,
InspectionNextViewModel,
InspectionViewModel,
MinifiedInspectionViewModel,
UpdateInspectionViewModel,
} from "@/viewmodels/admin/unit/inspection/inspection.models";
export const useInspectionStore = defineStore("inspection", {
state: () => {
return {
inspections: [] as Array<MinifiedInspectionViewModel & { tab_pos: number }>,
totalCount: 0 as number,
loading: "loading" as "loading" | "fetched" | "failed",
nextInspections: [] as Array<InspectionNextViewModel & { tab_pos: number }>,
nextTotalCount: 0 as number,
nextLoading: "loading" as "loading" | "fetched" | "failed",
activeInspection: null as string | null,
activeInspectionObj: null as InspectionViewModel | null,
loadingActive: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
fetchRunningInspections(offset = 0, count = 25, search = "", clear = false) {
if (clear) this.inspections = [];
this.loading = "loading";
http
.get(`/admin/inspection/running?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.inspections
.filter((elem: MinifiedInspectionViewModel) => this.inspections.findIndex((m) => m.id == elem.id) == -1)
.map(
(elem: MinifiedInspectionViewModel, index: number): MinifiedInspectionViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
}
)
.forEach((elem: MinifiedInspectionViewModel & { tab_pos: number }) => {
this.inspections.push(elem);
});
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchNextInspections(offset = 0, count = 25, search = "", clear = false) {
if (clear) this.nextInspections = [];
this.nextLoading = "loading";
http
.get(`/admin/inspection/next?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`)
.then((result) => {
this.nextTotalCount = result.data.total;
result.data.inspections
.filter((elem: InspectionNextViewModel) => this.nextInspections.findIndex((m) => m.id == elem.id) == -1)
.map((elem: InspectionNextViewModel, index: number): InspectionNextViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
})
.forEach((elem: InspectionNextViewModel & { tab_pos: number }) => {
this.nextInspections.push(elem);
});
this.nextLoading = "fetched";
})
.catch((err) => {
this.nextLoading = "failed";
});
},
fetchInspectionByActiveId() {
this.loadingActive = "loading";
http