diff --git a/src/router/protocolGuard.ts b/src/router/protocolGuard.ts index 6d80fe1..1db9857 100644 --- a/src/router/protocolGuard.ts +++ b/src/router/protocolGuard.ts @@ -1,9 +1,18 @@ import { useProtocolStore } from "@/stores/admin/protocol"; +import { useProtocolAgendaStore } from "@/stores/admin/protocolAgenda"; +import { useProtocolDecisionStore } from "@/stores/admin/protocolDecision"; +import { useProtocolPresenceStore } from "@/stores/admin/protocolPresence"; +import { useProtocolVotingStore } from "@/stores/admin/protocolVoting"; export async function setProtocolId(to: any, from: any, next: any) { const protocol = useProtocolStore(); protocol.activeProtocol = to.params?.protocolId ?? null; + useProtocolAgendaStore().$reset(); + useProtocolDecisionStore().$reset(); + useProtocolPresenceStore().$reset(); + useProtocolVotingStore().$reset(); + next(); } @@ -12,5 +21,10 @@ export async function resetProtocolStores(to: any, from: any, next: any) { protocol.activeProtocol = null; protocol.activeProtocolObj = null; + useProtocolAgendaStore().$reset(); + useProtocolDecisionStore().$reset(); + useProtocolPresenceStore().$reset(); + useProtocolVotingStore().$reset(); + next(); } diff --git a/src/stores/admin/protocol.ts b/src/stores/admin/protocol.ts index 3dd3b13..87d315a 100644 --- a/src/stores/admin/protocol.ts +++ b/src/stores/admin/protocol.ts @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import type { CreateProtocolViewModel, UpdateProtocolViewModel } from "@/viewmodels/admin/protocol.models"; +import type { CreateProtocolViewModel, SyncProtocolViewModel } from "@/viewmodels/admin/protocol.models"; import { http } from "@/serverCom"; import type { AxiosResponse } from "axios"; import type { ProtocolViewModel } from "@/viewmodels/admin/protocol.models"; @@ -64,18 +64,16 @@ export const useProtocolStore = defineStore("protocol", { this.fetchProtocols(); return result; }, - async updateActiveProtocol(protocol: UpdateProtocolViewModel): Promise> { + 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 deleteProtocol(protocol: number): Promise> { - const result = await http.delete(`/admin/protocol/${protocol}`); - this.fetchProtocols(); - return result; - }, }, }); diff --git a/src/stores/admin/protocolAgenda.ts b/src/stores/admin/protocolAgenda.ts new file mode 100644 index 0000000..7eccab8 --- /dev/null +++ b/src/stores/admin/protocolAgenda.ts @@ -0,0 +1,42 @@ +import { defineStore } from "pinia"; +import { http } from "@/serverCom"; +import type { AxiosResponse } from "axios"; +import type { + ProtocolAgendaViewModel, + SyncProtocolAgendaViewModel, +} from "../../viewmodels/admin/protocolAgenda.models"; +import { useProtocolStore } from "./protocol"; + +export const useProtocolAgendaStore = defineStore("protocolAgenda", { + state: () => { + return { + agenda: [] as Array, + loading: "loading" as "loading" | "fetched" | "failed", + }; + }, + actions: { + fetchProtocolAgenda() { + const protocolId = useProtocolStore().activeProtocol; + this.loading = "loading"; + http + .get(`/admin/protocol/${protocolId}/agenda`) + .then((result) => { + this.agenda = result.data; + this.loading = "fetched"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + async synchronizeActiveProtocolAgenda( + agenda: Array + ): Promise> { + const protocolId = useProtocolStore().activeProtocol; + const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/agenda`, { + agenda: agenda, + }); + this.fetchProtocolAgenda(); + return result; + }, + }, +}); diff --git a/src/stores/admin/protocolDecision.ts b/src/stores/admin/protocolDecision.ts new file mode 100644 index 0000000..87cd3e4 --- /dev/null +++ b/src/stores/admin/protocolDecision.ts @@ -0,0 +1,42 @@ +import { defineStore } from "pinia"; +import { http } from "@/serverCom"; +import type { AxiosResponse } from "axios"; +import type { + ProtocolDecisionViewModel, + SyncProtocolDecisionViewModel, +} from "../../viewmodels/admin/protocolDecision.models"; +import { useProtocolStore } from "./protocol"; + +export const useProtocolDecisionStore = defineStore("protocolDecision", { + state: () => { + return { + decision: [] as Array, + loading: "loading" as "loading" | "fetched" | "failed", + }; + }, + actions: { + fetchProtocolDecision() { + const protocolId = useProtocolStore().activeProtocol; + this.loading = "loading"; + http + .get(`/admin/protocol/${protocolId}/decisions`) + .then((result) => { + this.decision = result.data; + this.loading = "fetched"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + async synchronizeActiveProtocolDecision( + decision: Array + ): Promise> { + const protocolId = useProtocolStore().activeProtocol; + const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/decisions`, { + decision: decision, + }); + this.fetchProtocolDecision(); + return result; + }, + }, +}); diff --git a/src/stores/admin/protocolPresence.ts b/src/stores/admin/protocolPresence.ts new file mode 100644 index 0000000..1aac81f --- /dev/null +++ b/src/stores/admin/protocolPresence.ts @@ -0,0 +1,42 @@ +import { defineStore } from "pinia"; +import { http } from "@/serverCom"; +import type { AxiosResponse } from "axios"; +import type { + ProtocolPresenceViewModel, + SyncProtocolPresenceViewModel, +} from "../../viewmodels/admin/protocolPresence.models"; +import { useProtocolStore } from "./protocol"; + +export const useProtocolPresenceStore = defineStore("protocolPresence", { + state: () => { + return { + presence: [] as Array, + loading: "loading" as "loading" | "fetched" | "failed", + }; + }, + actions: { + fetchProtocolPresence() { + const protocolId = useProtocolStore().activeProtocol; + this.loading = "loading"; + http + .get(`/admin/protocol/${protocolId}/presence`) + .then((result) => { + this.presence = result.data; + this.loading = "fetched"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + async synchronizeActiveProtocolPresence( + presence: Array + ): Promise> { + const protocolId = useProtocolStore().activeProtocol; + const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/presence`, { + presence: presence, + }); + this.fetchProtocolPresence(); + return result; + }, + }, +}); diff --git a/src/stores/admin/protocolVoting.ts b/src/stores/admin/protocolVoting.ts new file mode 100644 index 0000000..5dd8790 --- /dev/null +++ b/src/stores/admin/protocolVoting.ts @@ -0,0 +1,42 @@ +import { defineStore } from "pinia"; +import { http } from "@/serverCom"; +import type { AxiosResponse } from "axios"; +import type { + ProtocolVotingViewModel, + SyncProtocolVotingViewModel, +} from "../../viewmodels/admin/protocolVoting.models"; +import { useProtocolStore } from "./protocol"; + +export const useProtocolVotingStore = defineStore("protocolVoting", { + state: () => { + return { + voting: [] as Array, + loading: "loading" as "loading" | "fetched" | "failed", + }; + }, + actions: { + fetchProtocolVoting() { + const protocolId = useProtocolStore().activeProtocol; + this.loading = "loading"; + http + .get(`/admin/protocol/${protocolId}/votings`) + .then((result) => { + this.voting = result.data; + this.loading = "fetched"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + async synchronizeActiveProtocolVoting( + voting: Array + ): Promise> { + const protocolId = useProtocolStore().activeProtocol; + const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/votings`, { + voting: voting, + }); + this.fetchProtocolVoting(); + return result; + }, + }, +}); diff --git a/src/viewmodels/admin/protocol.models.ts b/src/viewmodels/admin/protocol.models.ts index a30fb3c..0cd3279 100644 --- a/src/viewmodels/admin/protocol.models.ts +++ b/src/viewmodels/admin/protocol.models.ts @@ -10,12 +10,9 @@ export interface ProtocolViewModel { export interface CreateProtocolViewModel { title: string; date: Date; - starttime: Date; - endtime: Date; - summary: string; } -export interface UpdateProtocolViewModel { +export interface SyncProtocolViewModel { id: number; title: string; date: Date; diff --git a/src/viewmodels/admin/protocolAgenda.models.ts b/src/viewmodels/admin/protocolAgenda.models.ts index 3a59327..6015315 100644 --- a/src/viewmodels/admin/protocolAgenda.models.ts +++ b/src/viewmodels/admin/protocolAgenda.models.ts @@ -4,3 +4,9 @@ export interface ProtocolAgendaViewModel { context: string; protocolId: number; } + +export interface SyncProtocolAgendaViewModel { + id?: number; + topic: string; + context: string; +} diff --git a/src/viewmodels/admin/protocolDecision.models.ts b/src/viewmodels/admin/protocolDecision.models.ts index 4a7212c..19e1d61 100644 --- a/src/viewmodels/admin/protocolDecision.models.ts +++ b/src/viewmodels/admin/protocolDecision.models.ts @@ -4,3 +4,9 @@ export interface ProtocolDecisionViewModel { context: string; protocolId: number; } + +export interface SyncProtocolDecisionViewModel { + id?: number; + topic: string; + context: string; +} diff --git a/src/viewmodels/admin/protocolPresence.models.ts b/src/viewmodels/admin/protocolPresence.models.ts index 9c10f59..d72d916 100644 --- a/src/viewmodels/admin/protocolPresence.models.ts +++ b/src/viewmodels/admin/protocolPresence.models.ts @@ -1,7 +1,11 @@ -import { MemberViewModel } from "./member.models"; +import type { MemberViewModel } from "./member.models"; export interface ProtocolPresenceViewModel { memberId: number; member: MemberViewModel; protocolId: number; } + +export interface SyncProtocolPresenceViewModel { + memberIds: Array; +} diff --git a/src/viewmodels/admin/protocolVoting.models.ts b/src/viewmodels/admin/protocolVoting.models.ts index 686f423..cb61f68 100644 --- a/src/viewmodels/admin/protocolVoting.models.ts +++ b/src/viewmodels/admin/protocolVoting.models.ts @@ -7,3 +7,13 @@ export interface ProtocolVotingViewModel { against: number; protocolId: number; } + +export interface SyncProtocolVotingViewModel { + id?: number; + topic: string; + context: string; + favour: number; + abstain: number; + against: number; + protocolId: number; +} diff --git a/src/views/admin/club/protocol/ProtocolAgenda.vue b/src/views/admin/club/protocol/ProtocolAgenda.vue index 8822838..fce4262 100644 --- a/src/views/admin/club/protocol/ProtocolAgenda.vue +++ b/src/views/admin/club/protocol/ProtocolAgenda.vue @@ -1,7 +1,9 @@