protocol data stores

This commit is contained in:
Julian Krauser 2024-10-13 15:47:52 +02:00
parent 8664836a20
commit 41b300fb72
15 changed files with 259 additions and 31 deletions

View file

@ -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();
}

View file

@ -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<AxiosResponse<any, any>> {
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 deleteProtocol(protocol: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/protocol/${protocol}`);
this.fetchProtocols();
return result;
},
},
});

View file

@ -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<ProtocolAgendaViewModel>,
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<SyncProtocolAgendaViewModel>
): Promise<AxiosResponse<any, any>> {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/agenda`, {
agenda: agenda,
});
this.fetchProtocolAgenda();
return result;
},
},
});

View file

@ -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<ProtocolDecisionViewModel>,
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<SyncProtocolDecisionViewModel>
): Promise<AxiosResponse<any, any>> {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/decisions`, {
decision: decision,
});
this.fetchProtocolDecision();
return result;
},
},
});

View file

@ -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<ProtocolPresenceViewModel>,
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<SyncProtocolPresenceViewModel>
): Promise<AxiosResponse<any, any>> {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/presence`, {
presence: presence,
});
this.fetchProtocolPresence();
return result;
},
},
});

View file

@ -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<ProtocolVotingViewModel>,
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<SyncProtocolVotingViewModel>
): Promise<AxiosResponse<any, any>> {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/votings`, {
voting: voting,
});
this.fetchProtocolVoting();
return result;
},
},
});

View file

@ -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;

View file

@ -4,3 +4,9 @@ export interface ProtocolAgendaViewModel {
context: string;
protocolId: number;
}
export interface SyncProtocolAgendaViewModel {
id?: number;
topic: string;
context: string;
}

View file

@ -4,3 +4,9 @@ export interface ProtocolDecisionViewModel {
context: string;
protocolId: number;
}
export interface SyncProtocolDecisionViewModel {
id?: number;
topic: string;
context: string;
}

View file

@ -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<number>;
}

View file

@ -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;
}

View file

@ -1,7 +1,9 @@
<template>
<div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
<Spinner v-if="loadingActive == 'loading'" class="mx-auto" />
<p v-else-if="loadingActive == 'failed'" @click="" class="cursor-pointer">&#8634; laden fehlgeschlagen</p>
<Spinner v-if="loading == 'loading'" class="mx-auto" />
<p v-else-if="loading == 'failed'" @click="fetchProtocolAgenda" class="cursor-pointer">
&#8634; laden fehlgeschlagen
</p>
<details class="flex flex-col gap-2 rounded-lg w-full justify-between border border-primary overflow-hidden">
<summary class="flex flex-row gap-2 bg-primary p-2 w-full justify-between items-center cursor-pointer">
@ -27,10 +29,10 @@
import { defineComponent } from "vue";
import { mapActions, mapState } from "pinia";
import Spinner from "@/components/Spinner.vue";
import { useProtocolStore } from "@/stores/admin/protocol";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import { toolbarOptions } from "@/helpers/quillConfig";
import { useProtocolAgendaStore } from "@/stores/admin/protocolAgenda";
</script>
<script lang="ts">
@ -39,9 +41,13 @@ export default defineComponent({
protocolId: String,
},
computed: {
...mapState(useProtocolStore, ["loadingActive"]),
...mapState(useProtocolAgendaStore, ["agenda", "loading"]),
},
mounted() {
this.fetchProtocolAgenda();
},
methods: {
...mapActions(useProtocolAgendaStore, ["fetchProtocolAgenda"]),
},
mounted() {},
methods: {},
});
</script>

View file

@ -1,7 +1,9 @@
<template>
<div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
<Spinner v-if="loadingActive == 'loading'" class="mx-auto" />
<p v-else-if="loadingActive == 'failed'" @click="" class="cursor-pointer">&#8634; laden fehlgeschlagen</p>
<Spinner v-if="loading == 'loading'" class="mx-auto" />
<p v-else-if="loading == 'failed'" @click="fetchProtocolDecision" class="cursor-pointer">
&#8634; laden fehlgeschlagen
</p>
</div>
</template>
@ -13,6 +15,7 @@ import { useProtocolStore } from "@/stores/admin/protocol";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import { toolbarOptions } from "@/helpers/quillConfig";
import { useProtocolDecisionStore } from "../../../../stores/admin/protocolDecision";
</script>
<script lang="ts">
@ -21,9 +24,13 @@ export default defineComponent({
protocolId: String,
},
computed: {
...mapState(useProtocolStore, ["loadingActive"]),
...mapState(useProtocolDecisionStore, ["decision", "loading"]),
},
mounted() {
this.fetchProtocolDecision();
},
methods: {
...mapActions(useProtocolDecisionStore, ["fetchProtocolDecision"]),
},
mounted() {},
methods: {},
});
</script>

View file

@ -1,7 +1,9 @@
<template>
<div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
<Spinner v-if="loadingActive == 'loading'" class="mx-auto" />
<p v-else-if="loadingActive == 'failed'" @click="" class="cursor-pointer">&#8634; laden fehlgeschlagen</p>
<Spinner v-if="loading == 'loading'" class="mx-auto" />
<p v-else-if="loading == 'failed'" @click="fetchProtocolPresence" class="cursor-pointer">
&#8634; laden fehlgeschlagen
</p>
<div class="w-full">
<Combobox v-model="selected" multiple>
<ComboboxLabel>Anwesende suchen</ComboboxLabel>
@ -92,6 +94,7 @@ import { TrashIcon } from "@heroicons/vue/24/outline";
import { useProtocolStore } from "@/stores/admin/protocol";
import { useMemberStore } from "@/stores/admin/member";
import type { MemberViewModel } from "@/viewmodels/admin/member.models";
import { useProtocolPresenceStore } from "../../../../stores/admin/protocolPresence";
</script>
<script lang="ts">
@ -106,7 +109,7 @@ export default defineComponent({
};
},
computed: {
...mapState(useProtocolStore, ["loadingActive"]),
...mapState(useProtocolPresenceStore, ["presence", "loading"]),
...mapState(useMemberStore, ["members"]),
filtered(): Array<MemberViewModel> {
return this.query === ""
@ -130,9 +133,11 @@ export default defineComponent({
},
mounted() {
this.fetchMembers();
this.fetchProtocolPresence();
},
methods: {
...mapActions(useMemberStore, ["fetchMembers"]),
...mapActions(useProtocolPresenceStore, ["fetchProtocolPresence"]),
removeSelected(id: number) {
let index = this.selected.findIndex((s) => s.id == id);
if (index != -1) {

View file

@ -1,7 +1,9 @@
<template>
<div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
<Spinner v-if="loadingActive == 'loading'" class="mx-auto" />
<p v-else-if="loadingActive == 'failed'" @click="" class="cursor-pointer">&#8634; laden fehlgeschlagen</p>
<Spinner v-if="loading == 'loading'" class="mx-auto" />
<p v-else-if="loading == 'failed'" @click="fetchProtocolVoting" class="cursor-pointer">
&#8634; laden fehlgeschlagen
</p>
</div>
</template>
@ -13,6 +15,7 @@ import { useProtocolStore } from "@/stores/admin/protocol";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import { toolbarOptions } from "@/helpers/quillConfig";
import { useProtocolVotingStore } from "../../../../stores/admin/protocolVoting";
</script>
<script lang="ts">
@ -21,9 +24,13 @@ export default defineComponent({
protocolId: String,
},
computed: {
...mapState(useProtocolStore, ["loadingActive"]),
...mapState(useProtocolVotingStore, ["voting", "loading"]),
},
mounted() {
this.fetchProtocolVoting();
},
methods: {
...mapActions(useProtocolVotingStore, ["fetchProtocolVoting"]),
},
mounted() {},
methods: {},
});
</script>