From f3ffdb1ffdc9a4d970e1e124f5af1f0704ad73b0 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Sat, 19 Oct 2024 16:24:33 +0200 Subject: [PATCH] printout page --- src/router/index.ts | 6 ++ src/router/protocolGuard.ts | 3 + src/stores/admin/protocol.ts | 6 -- src/stores/admin/protocolPrintout.ts | 60 +++++++++++++++++++ .../admin/protocolPrintout.models.ts | 7 +++ .../admin/club/protocol/ProtocolPrintout.vue | 59 ++++++++++++++++++ .../admin/club/protocol/ProtocolRouting.vue | 4 +- 7 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 src/stores/admin/protocolPrintout.ts create mode 100644 src/viewmodels/admin/protocolPrintout.models.ts create mode 100644 src/views/admin/club/protocol/ProtocolPrintout.vue diff --git a/src/router/index.ts b/src/router/index.ts index 704a63a..ae1565b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -197,6 +197,12 @@ const router = createRouter({ component: () => import("@/views/admin/club/protocol/ProtocolAgenda.vue"), props: true, }, + { + path: "printout", + name: "admin-club-protocol-printout", + component: () => import("@/views/admin/club/protocol/ProtocolPrintout.vue"), + props: true, + }, ], }, ], diff --git a/src/router/protocolGuard.ts b/src/router/protocolGuard.ts index 1db9857..a86d848 100644 --- a/src/router/protocolGuard.ts +++ b/src/router/protocolGuard.ts @@ -3,6 +3,7 @@ import { useProtocolAgendaStore } from "@/stores/admin/protocolAgenda"; import { useProtocolDecisionStore } from "@/stores/admin/protocolDecision"; import { useProtocolPresenceStore } from "@/stores/admin/protocolPresence"; import { useProtocolVotingStore } from "@/stores/admin/protocolVoting"; +import { useProtocolPrintoutStore } from "../stores/admin/protocolPrintout"; export async function setProtocolId(to: any, from: any, next: any) { const protocol = useProtocolStore(); @@ -12,6 +13,7 @@ export async function setProtocolId(to: any, from: any, next: any) { useProtocolDecisionStore().$reset(); useProtocolPresenceStore().$reset(); useProtocolVotingStore().$reset(); + useProtocolPrintoutStore().$reset(); next(); } @@ -25,6 +27,7 @@ export async function resetProtocolStores(to: any, from: any, next: any) { useProtocolDecisionStore().$reset(); useProtocolPresenceStore().$reset(); useProtocolVotingStore().$reset(); + useProtocolPrintoutStore().$reset(); next(); } diff --git a/src/stores/admin/protocol.ts b/src/stores/admin/protocol.ts index 8262291..3c637d8 100644 --- a/src/stores/admin/protocol.ts +++ b/src/stores/admin/protocol.ts @@ -100,11 +100,5 @@ export const useProtocolStore = defineStore("protocol", { }) .catch((err) => {}); }, - printProtocol() { - return http - .post(`/admin/protocol/${this.activeProtocol}/render`) - .then(() => {}) - .catch(() => {}); - }, }, }); diff --git a/src/stores/admin/protocolPrintout.ts b/src/stores/admin/protocolPrintout.ts new file mode 100644 index 0000000..4760c1e --- /dev/null +++ b/src/stores/admin/protocolPrintout.ts @@ -0,0 +1,60 @@ +import { defineStore } from "pinia"; +import { http } from "@/serverCom"; +import type { ProtocolPrintoutViewModel } from "../../viewmodels/admin/protocolPrintout.models"; +import { useProtocolStore } from "./protocol"; + +export const useProtocolPrintoutStore = defineStore("protocolPrintout", { + state: () => { + return { + printout: [] as Array, + loading: "loading" as "loading" | "fetched" | "failed", + printing: undefined as undefined | "loading" | "success" | "failed", + }; + }, + actions: { + fetchProtocolPrintout() { + const protocolId = useProtocolStore().activeProtocol; + this.loading = "loading"; + http + .get(`/admin/protocol/${protocolId}/printouts`) + .then((result) => { + this.printout = result.data; + this.loading = "fetched"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + fetchProtocolPrintoutById(printoutId: string) { + const protocolId = useProtocolStore().activeProtocol; + this.loading = "loading"; + http + .get(`/admin/protocol/${protocolId}/printout/${printoutId}`) + .then((result) => { + this.loading = "fetched"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + createProtocolPrintout() { + this.printing = "loading"; + const protocolId = useProtocolStore().activeProtocol; + if (protocolId == null) return; + return http + .post(`/admin/protocol/${protocolId}/printout`) + .then((res) => { + this.fetchProtocolPrintout(); + this.printing = "success"; + }) + .catch((err) => { + this.printing = "failed"; + }) + .finally(() => { + setTimeout(() => { + this.printing = undefined; + }, 1500); + }); + }, + }, +}); diff --git a/src/viewmodels/admin/protocolPrintout.models.ts b/src/viewmodels/admin/protocolPrintout.models.ts new file mode 100644 index 0000000..ff60cdb --- /dev/null +++ b/src/viewmodels/admin/protocolPrintout.models.ts @@ -0,0 +1,7 @@ +export interface ProtocolPrintoutViewModel { + id: number; + title: string; + iteration: number; + createdAt: Date; + protocolId: number; +} diff --git a/src/views/admin/club/protocol/ProtocolPrintout.vue b/src/views/admin/club/protocol/ProtocolPrintout.vue new file mode 100644 index 0000000..d989bdf --- /dev/null +++ b/src/views/admin/club/protocol/ProtocolPrintout.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/src/views/admin/club/protocol/ProtocolRouting.vue b/src/views/admin/club/protocol/ProtocolRouting.vue index f5380fd..2f8edd1 100644 --- a/src/views/admin/club/protocol/ProtocolRouting.vue +++ b/src/views/admin/club/protocol/ProtocolRouting.vue @@ -6,7 +6,6 @@