show render or download
This commit is contained in:
parent
f3ffdb1ffd
commit
28ac0a835b
3 changed files with 82 additions and 12 deletions
|
@ -0,0 +1,40 @@
|
||||||
|
<template>
|
||||||
|
<div class="w-full h-full flex flex-col gap-2">
|
||||||
|
<div class="grow">
|
||||||
|
<iframe ref="viewer" class="w-full h-full" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button primary-outline class="!w-fit self-end" @click="closeModal">schließen</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { defineComponent } from "vue";
|
||||||
|
import { mapState, mapActions } from "pinia";
|
||||||
|
import { useModalStore } from "@/stores/modal";
|
||||||
|
import Spinner from "@/components/Spinner.vue";
|
||||||
|
import { useProtocolPrintoutStore } from "@/stores/admin/protocolPrintout";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
export default defineComponent({
|
||||||
|
computed: {
|
||||||
|
...mapState(useModalStore, ["data"]),
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.fetchItem();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(useModalStore, ["closeModal"]),
|
||||||
|
...mapActions(useProtocolPrintoutStore, ["fetchProtocolPrintoutById"]),
|
||||||
|
fetchItem() {
|
||||||
|
this.fetchProtocolPrintoutById(this.data)
|
||||||
|
.then((response) => {
|
||||||
|
const blob = new Blob([response.data], { type: "application/pdf" });
|
||||||
|
(this.$refs.viewer as HTMLIFrameElement).src = window.URL.createObjectURL(blob);
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -2,6 +2,7 @@ import { defineStore } from "pinia";
|
||||||
import { http } from "@/serverCom";
|
import { http } from "@/serverCom";
|
||||||
import type { ProtocolPrintoutViewModel } from "../../viewmodels/admin/protocolPrintout.models";
|
import type { ProtocolPrintoutViewModel } from "../../viewmodels/admin/protocolPrintout.models";
|
||||||
import { useProtocolStore } from "./protocol";
|
import { useProtocolStore } from "./protocol";
|
||||||
|
import type { AxiosResponse } from "axios";
|
||||||
|
|
||||||
export const useProtocolPrintoutStore = defineStore("protocolPrintout", {
|
export const useProtocolPrintoutStore = defineStore("protocolPrintout", {
|
||||||
state: () => {
|
state: () => {
|
||||||
|
@ -25,16 +26,10 @@ export const useProtocolPrintoutStore = defineStore("protocolPrintout", {
|
||||||
this.loading = "failed";
|
this.loading = "failed";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fetchProtocolPrintoutById(printoutId: string) {
|
fetchProtocolPrintoutById(printoutId: number): Promise<AxiosResponse<any, any>> {
|
||||||
const protocolId = useProtocolStore().activeProtocol;
|
const protocolId = useProtocolStore().activeProtocol;
|
||||||
this.loading = "loading";
|
return http.get(`/admin/protocol/${protocolId}/printout/${printoutId}`, {
|
||||||
http
|
responseType: "blob",
|
||||||
.get(`/admin/protocol/${protocolId}/printout/${printoutId}`)
|
|
||||||
.then((result) => {
|
|
||||||
this.loading = "fetched";
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.loading = "failed";
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createProtocolPrintout() {
|
createProtocolPrintout() {
|
||||||
|
|
|
@ -13,6 +13,14 @@
|
||||||
>
|
>
|
||||||
<div class="bg-primary p-2 text-white flex flex-row justify-between items-center">
|
<div class="bg-primary p-2 text-white flex flex-row justify-between items-center">
|
||||||
<p>{{ print.title }}</p>
|
<p>{{ print.title }}</p>
|
||||||
|
<div class="flex flex-row">
|
||||||
|
<div>
|
||||||
|
<ViewfinderCircleIcon class="w-5 h-5 p-1 box-content cursor-pointer" @click="openPdfShow(print.id)" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<ArrowDownTrayIcon class="w-5 h-5 p-1 box-content cursor-pointer" @click="downloadPdf(print.id)" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-2">
|
<div class="p-2">
|
||||||
<p>Ausdruck Nummer: {{ print.iteration }}</p>
|
<p>Ausdruck Nummer: {{ print.iteration }}</p>
|
||||||
|
@ -33,12 +41,14 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineComponent } from "vue";
|
import { defineAsyncComponent, defineComponent, markRaw } from "vue";
|
||||||
import { mapActions, mapState } from "pinia";
|
import { mapActions, mapState } from "pinia";
|
||||||
import Spinner from "@/components/Spinner.vue";
|
import Spinner from "@/components/Spinner.vue";
|
||||||
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
||||||
import FailureXMark from "@/components/FailureXMark.vue";
|
import FailureXMark from "@/components/FailureXMark.vue";
|
||||||
import { useProtocolPrintoutStore } from "@/stores/admin/protocolPrintout";
|
import { useProtocolPrintoutStore } from "@/stores/admin/protocolPrintout";
|
||||||
|
import { ArrowDownTrayIcon, ViewfinderCircleIcon } from "@heroicons/vue/24/outline";
|
||||||
|
import { useModalStore } from "@/stores/modal";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
@ -53,7 +63,32 @@ export default defineComponent({
|
||||||
this.fetchProtocolPrintout();
|
this.fetchProtocolPrintout();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(useProtocolPrintoutStore, ["fetchProtocolPrintout", "createProtocolPrintout"]),
|
...mapActions(useModalStore, ["openModal"]),
|
||||||
|
...mapActions(useProtocolPrintoutStore, [
|
||||||
|
"fetchProtocolPrintout",
|
||||||
|
"createProtocolPrintout",
|
||||||
|
"fetchProtocolPrintoutById",
|
||||||
|
]),
|
||||||
|
openPdfShow(id: number) {
|
||||||
|
this.openModal(
|
||||||
|
markRaw(defineAsyncComponent(() => import("@/components/admin/club/protocol/ProtocolPrintoutViewerModal.vue"))),
|
||||||
|
id
|
||||||
|
);
|
||||||
|
},
|
||||||
|
downloadPdf(id: number) {
|
||||||
|
let clickedOn = this.printout.find((p) => p.id == id);
|
||||||
|
this.fetchProtocolPrintoutById(id)
|
||||||
|
.then((response) => {
|
||||||
|
const fileURL = window.URL.createObjectURL(new Blob([response.data]));
|
||||||
|
const fileLink = document.createElement("a");
|
||||||
|
fileLink.href = fileURL;
|
||||||
|
fileLink.setAttribute("download", clickedOn?.title ? clickedOn.title + ".pdf" : "Protokoll.pdf");
|
||||||
|
document.body.appendChild(fileLink);
|
||||||
|
fileLink.click();
|
||||||
|
fileLink.remove();
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue