2025-05-14 09:13:47 +02:00
|
|
|
import { defineStore } from "pinia";
|
|
|
|
import { http } from "@/serverCom";
|
|
|
|
import type { InspectionViewModel } from "@/viewmodels/admin/unit/inspectionPlan/inspectionPlan.models";
|
|
|
|
import { inspectionDemoData } from "@/demodata/inspectionPlan";
|
|
|
|
import { useEquipmentStore } from "./equipment";
|
|
|
|
|
|
|
|
export const useEquipmentInspectionStore = defineStore("equipmentInspection", {
|
|
|
|
state: () => {
|
|
|
|
return {
|
|
|
|
inspections: [] as Array<InspectionViewModel & { tab_pos: number }>,
|
|
|
|
totalCount: 0 as number,
|
|
|
|
loading: "loading" as "loading" | "fetched" | "failed",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
fetchInspectionForEquipment(offset = 0, count = 25, search = "", clear = false) {
|
|
|
|
const equipmentId = useEquipmentStore().activeEquipment;
|
2025-05-14 14:42:00 +02:00
|
|
|
this.inspections = inspectionDemoData
|
|
|
|
.filter((idd) => idd.relatedId == equipmentId)
|
|
|
|
.map((e, i) => ({ ...e, tab_pos: i }));
|
2025-05-14 09:13:47 +02:00
|
|
|
this.totalCount = this.inspections.length;
|
|
|
|
this.loading = "fetched";
|
|
|
|
return;
|
|
|
|
if (clear) this.inspections = [];
|
|
|
|
this.loading = "loading";
|
|
|
|
http
|
|
|
|
.get(
|
|
|
|
`/admin/equipment/${equipmentId}/inspection?offset=${offset}&count=${count}${search != "" ? "&search=" + search : ""}`
|
|
|
|
)
|
|
|
|
.then((result) => {
|
|
|
|
this.totalCount = result.data.total;
|
|
|
|
result.data.inspections
|
|
|
|
.filter((elem: InspectionViewModel) => this.inspections.findIndex((m) => m.id == elem.id) == -1)
|
|
|
|
.map((elem: InspectionViewModel, index: number): InspectionViewModel & { tab_pos: number } => {
|
|
|
|
return {
|
|
|
|
...elem,
|
|
|
|
tab_pos: index + offset,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.forEach((elem: InspectionViewModel & { tab_pos: number }) => {
|
|
|
|
this.inspections.push(elem);
|
|
|
|
});
|
|
|
|
this.loading = "fetched";
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
this.loading = "failed";
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|