syncing
This commit is contained in:
parent
41b300fb72
commit
52deb253c1
9 changed files with 272 additions and 34 deletions
|
@ -3,6 +3,9 @@ import type { CreateProtocolViewModel, SyncProtocolViewModel } from "@/viewmodel
|
|||
import { http } from "@/serverCom";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import type { ProtocolViewModel } from "@/viewmodels/admin/protocol.models";
|
||||
import cloneDeep from "lodash.clonedeep";
|
||||
import isEqual from "lodash.isEqual";
|
||||
import difference from "lodash.difference";
|
||||
|
||||
export const useProtocolStore = defineStore("protocol", {
|
||||
state: () => {
|
||||
|
@ -12,11 +15,18 @@ export const useProtocolStore = defineStore("protocol", {
|
|||
loading: "loading" as "loading" | "fetched" | "failed",
|
||||
activeProtocol: null as number | null,
|
||||
activeProtocolObj: null as ProtocolViewModel | null,
|
||||
origin: null as ProtocolViewModel | null,
|
||||
loadingActive: "loading" as "loading" | "fetched" | "failed",
|
||||
syncing: "synced" as "synced" | "syncing" | "detectedChanges" | "failed",
|
||||
syncingProtocol: "synced" as "synced" | "syncing" | "detectedChanges" | "failed",
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
detectedChangeProtocol: (state) => !isEqual(state.origin, state.activeProtocolObj),
|
||||
},
|
||||
actions: {
|
||||
setProtocolSyncingState(state: "synced" | "syncing" | "detectedChanges" | "failed") {
|
||||
this.syncingProtocol = state;
|
||||
},
|
||||
fetchProtocols(offset = 0, count = 25, clear = false) {
|
||||
if (clear) this.protocols = [];
|
||||
this.loading = "loading";
|
||||
|
@ -46,7 +56,8 @@ export const useProtocolStore = defineStore("protocol", {
|
|||
http
|
||||
.get(`/admin/protocol/${this.activeProtocol}`)
|
||||
.then((res) => {
|
||||
this.activeProtocolObj = res.data;
|
||||
this.origin = res.data;
|
||||
this.activeProtocolObj = cloneDeep(this.origin);
|
||||
this.loadingActive = "fetched";
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -64,16 +75,30 @@ export const useProtocolStore = defineStore("protocol", {
|
|||
this.fetchProtocols();
|
||||
return result;
|
||||
},
|
||||
async synchronizeActiveProtocol(protocol: SyncProtocolViewModel): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/protocol/${protocol.id}`, {
|
||||
title: protocol.title,
|
||||
date: protocol.date,
|
||||
starttime: protocol.starttime,
|
||||
endtime: protocol.endtime,
|
||||
summary: protocol.summary,
|
||||
});
|
||||
this.fetchProtocols();
|
||||
return result;
|
||||
async synchronizeActiveProtocol(): Promise<void> {
|
||||
if (this.origin == null || this.activeProtocolObj == null) return;
|
||||
|
||||
this.syncingProtocol = "syncing";
|
||||
await http
|
||||
.put(`/admin/protocol/${this.origin.id}/synchronize`, {
|
||||
title: this.activeProtocolObj.title,
|
||||
date: this.activeProtocolObj.date,
|
||||
starttime: this.activeProtocolObj.starttime,
|
||||
endtime: this.activeProtocolObj.endtime,
|
||||
summary: this.activeProtocolObj.summary,
|
||||
})
|
||||
.then((res) => {
|
||||
this.syncingProtocol = "synced";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.syncingProtocol = "failed";
|
||||
});
|
||||
this.fetchProtocolById(this.origin.id)
|
||||
.then((res) => {
|
||||
this.origin = res.data;
|
||||
this.activeProtocolObj = cloneDeep(this.origin);
|
||||
})
|
||||
.catch((err) => {});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue