From 52deb253c1d5d8fe18b7d2427669ebbe0b2ff4d4 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Mon, 14 Oct 2024 17:03:48 +0200 Subject: [PATCH] syncing --- package-lock.json | 11 +++ package.json | 1 + .../club/protocol/CreateProtocolModal.vue | 80 +++++++++++++++++++ .../club/protocol/CurrentlySyncingModal.vue | 26 ++++++ .../admin/club/protocol/ProtocolListItem.vue | 6 +- .../admin/club/protocol/ProtocolSyncing.vue | 72 +++++++++++++++++ src/stores/admin/protocol.ts | 49 +++++++++--- src/views/admin/club/protocol/Protocol.vue | 6 +- .../admin/club/protocol/ProtocolRouting.vue | 55 +++++++++---- 9 files changed, 272 insertions(+), 34 deletions(-) create mode 100644 src/components/admin/club/protocol/CreateProtocolModal.vue create mode 100644 src/components/admin/club/protocol/CurrentlySyncingModal.vue create mode 100644 src/components/admin/club/protocol/ProtocolSyncing.vue diff --git a/package-lock.json b/package-lock.json index 654c907..c86341e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "@tsconfig/node20": "^20.1.4", "@types/eslint": "~9.6.0", "@types/lodash.clonedeep": "^4.5.9", + "@types/lodash.difference": "^4.5.9", "@types/lodash.isequal": "^4.5.8", "@types/node": "^20.14.5", "@types/nprogress": "^0.2.0", @@ -3085,6 +3086,16 @@ "@types/lodash": "*" } }, + "node_modules/@types/lodash.difference": { + "version": "4.5.9", + "resolved": "https://registry.npmjs.org/@types/lodash.difference/-/lodash.difference-4.5.9.tgz", + "integrity": "sha512-MNlajcjtwzLpXk+cw38UkBvEXJNEPhULgS8A4EHwtUwT7f7yFH/SFKD0iw5Rfilwh60yJIgFo0vsMr7xsa5+aw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/lodash.isequal": { "version": "4.5.8", "resolved": "https://registry.npmjs.org/@types/lodash.isequal/-/lodash.isequal-4.5.8.tgz", diff --git a/package.json b/package.json index 6b17df4..e886a5f 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@tsconfig/node20": "^20.1.4", "@types/eslint": "~9.6.0", "@types/lodash.clonedeep": "^4.5.9", + "@types/lodash.difference": "^4.5.9", "@types/lodash.isequal": "^4.5.8", "@types/node": "^20.14.5", "@types/nprogress": "^0.2.0", diff --git a/src/components/admin/club/protocol/CreateProtocolModal.vue b/src/components/admin/club/protocol/CreateProtocolModal.vue new file mode 100644 index 0000000..7a576b4 --- /dev/null +++ b/src/components/admin/club/protocol/CreateProtocolModal.vue @@ -0,0 +1,80 @@ + + + + + diff --git a/src/components/admin/club/protocol/CurrentlySyncingModal.vue b/src/components/admin/club/protocol/CurrentlySyncingModal.vue new file mode 100644 index 0000000..5bd8f47 --- /dev/null +++ b/src/components/admin/club/protocol/CurrentlySyncingModal.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/src/components/admin/club/protocol/ProtocolListItem.vue b/src/components/admin/club/protocol/ProtocolListItem.vue index 6cf34e3..141006a 100644 --- a/src/components/admin/club/protocol/ProtocolListItem.vue +++ b/src/components/admin/club/protocol/ProtocolListItem.vue @@ -4,10 +4,10 @@ :to="{ name: 'admin-club-protocol-overview', params: { protocolId: protocol.id } }" class="bg-primary p-2 text-white flex flex-row justify-between items-center" > -

{{ protocol.title }}

+

{{ protocol.title }} - {{ protocol.date }}

-
-

Infos

+
+

diff --git a/src/components/admin/club/protocol/ProtocolSyncing.vue b/src/components/admin/club/protocol/ProtocolSyncing.vue new file mode 100644 index 0000000..d3fea13 --- /dev/null +++ b/src/components/admin/club/protocol/ProtocolSyncing.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/src/stores/admin/protocol.ts b/src/stores/admin/protocol.ts index 87d315a..ca39eea 100644 --- a/src/stores/admin/protocol.ts +++ b/src/stores/admin/protocol.ts @@ -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> { - 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 { + 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) => {}); }, }, }); diff --git a/src/views/admin/club/protocol/Protocol.vue b/src/views/admin/club/protocol/Protocol.vue index dc9a17f..273d37c 100644 --- a/src/views/admin/club/protocol/Protocol.vue +++ b/src/views/admin/club/protocol/Protocol.vue @@ -57,9 +57,9 @@ export default defineComponent({ ...mapActions(useProtocolStore, ["fetchProtocols"]), ...mapActions(useModalStore, ["openModal"]), openCreateModal() { - // this.openModal( - // markRaw(defineAsyncComponent(() => import("@/components/admin/club/protocol/CreateProtocolModal.vue"))) - // ); + this.openModal( + markRaw(defineAsyncComponent(() => import("@/components/admin/club/protocol/CreateProtocolModal.vue"))) + ); }, }, }); diff --git a/src/views/admin/club/protocol/ProtocolRouting.vue b/src/views/admin/club/protocol/ProtocolRouting.vue index f24d348..f77c91b 100644 --- a/src/views/admin/club/protocol/ProtocolRouting.vue +++ b/src/views/admin/club/protocol/ProtocolRouting.vue @@ -5,14 +5,16 @@