sse for progress (disabled)

This commit is contained in:
Julian Krauser 2024-12-31 14:23:42 +01:00
parent faadc71b1b
commit fcd07a15d0
6 changed files with 69 additions and 2 deletions

15
package-lock.json generated
View file

@ -18,6 +18,7 @@
"@heroicons/vue": "^2.1.5", "@heroicons/vue": "^2.1.5",
"@vueup/vue-quill": "^1.2.0", "@vueup/vue-quill": "^1.2.0",
"axios": "^0.26.1", "axios": "^0.26.1",
"event-source-polyfill": "^1.0.31",
"grapesjs": "^0.22.4", "grapesjs": "^0.22.4",
"grapesjs-preset-newsletter": "^1.0.2", "grapesjs-preset-newsletter": "^1.0.2",
"jwt-decode": "^4.0.0", "jwt-decode": "^4.0.0",
@ -39,6 +40,7 @@
"@rushstack/eslint-patch": "^1.8.0", "@rushstack/eslint-patch": "^1.8.0",
"@tsconfig/node20": "^20.1.4", "@tsconfig/node20": "^20.1.4",
"@types/eslint": "~9.6.0", "@types/eslint": "~9.6.0",
"@types/event-source-polyfill": "^1.0.5",
"@types/lodash.clonedeep": "^4.5.9", "@types/lodash.clonedeep": "^4.5.9",
"@types/lodash.difference": "^4.5.9", "@types/lodash.difference": "^4.5.9",
"@types/lodash.differencewith": "^4.5.9", "@types/lodash.differencewith": "^4.5.9",
@ -3101,6 +3103,13 @@
"integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==",
"dev": true "dev": true
}, },
"node_modules/@types/event-source-polyfill": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@types/event-source-polyfill/-/event-source-polyfill-1.0.5.tgz",
"integrity": "sha512-iaiDuDI2aIFft7XkcwMzDWLqo7LVDixd2sR6B4wxJut9xcp/Ev9bO4EFg4rm6S9QxATLBj5OPxdeocgmhjwKaw==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/jquery": { "node_modules/@types/jquery": {
"version": "3.5.32", "version": "3.5.32",
"resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.32.tgz", "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.32.tgz",
@ -5400,6 +5409,12 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/event-source-polyfill": {
"version": "1.0.31",
"resolved": "https://registry.npmjs.org/event-source-polyfill/-/event-source-polyfill-1.0.31.tgz",
"integrity": "sha512-4IJSItgS/41IxN5UVAVuAyczwZF7ZIEsM1XAoUzIHA6A+xzusEZUutdXz2Nr+MQPLxfTiCvqE79/C8HT8fKFvA==",
"license": "MIT"
},
"node_modules/eventemitter3": { "node_modules/eventemitter3": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz",

View file

@ -33,6 +33,7 @@
"@heroicons/vue": "^2.1.5", "@heroicons/vue": "^2.1.5",
"@vueup/vue-quill": "^1.2.0", "@vueup/vue-quill": "^1.2.0",
"axios": "^0.26.1", "axios": "^0.26.1",
"event-source-polyfill": "^1.0.31",
"grapesjs": "^0.22.4", "grapesjs": "^0.22.4",
"grapesjs-preset-newsletter": "^1.0.2", "grapesjs-preset-newsletter": "^1.0.2",
"jwt-decode": "^4.0.0", "jwt-decode": "^4.0.0",
@ -54,6 +55,7 @@
"@rushstack/eslint-patch": "^1.8.0", "@rushstack/eslint-patch": "^1.8.0",
"@tsconfig/node20": "^20.1.4", "@tsconfig/node20": "^20.1.4",
"@types/eslint": "~9.6.0", "@types/eslint": "~9.6.0",
"@types/event-source-polyfill": "^1.0.5",
"@types/lodash.clonedeep": "^4.5.9", "@types/lodash.clonedeep": "^4.5.9",
"@types/lodash.difference": "^4.5.9", "@types/lodash.difference": "^4.5.9",
"@types/lodash.differencewith": "^4.5.9", "@types/lodash.differencewith": "^4.5.9",

View file

@ -1,6 +1,7 @@
import { useNewsletterStore } from "@/stores/admin/newsletter"; import { useNewsletterStore } from "@/stores/admin/newsletter";
import { useNewsletterDatesStore } from "@/stores/admin/newsletterDates"; import { useNewsletterDatesStore } from "@/stores/admin/newsletterDates";
import { useNewsletterRecipientsStore } from "@/stores/admin/newsletterRecipients"; import { useNewsletterRecipientsStore } from "@/stores/admin/newsletterRecipients";
import { useNewsletterPrintoutStore } from "../stores/admin/newsletterPrintout";
export async function setNewsletterId(to: any, from: any, next: any) { export async function setNewsletterId(to: any, from: any, next: any) {
const newsletter = useNewsletterStore(); const newsletter = useNewsletterStore();
@ -8,6 +9,9 @@ export async function setNewsletterId(to: any, from: any, next: any) {
useNewsletterDatesStore().$reset(); useNewsletterDatesStore().$reset();
useNewsletterRecipientsStore().$reset(); useNewsletterRecipientsStore().$reset();
useNewsletterPrintoutStore().unsubscribePdfPrintingProgress();
useNewsletterPrintoutStore().unsubscribeMailSendingProgress();
useNewsletterPrintoutStore().$reset();
next(); next();
} }
@ -19,6 +23,9 @@ export async function resetNewsletterStores(to: any, from: any, next: any) {
useNewsletterDatesStore().$reset(); useNewsletterDatesStore().$reset();
useNewsletterRecipientsStore().$reset(); useNewsletterRecipientsStore().$reset();
useNewsletterPrintoutStore().unsubscribePdfPrintingProgress();
useNewsletterPrintoutStore().unsubscribeMailSendingProgress();
useNewsletterPrintoutStore().$reset();
next(); next();
} }

View file

@ -2,6 +2,7 @@ import axios from "axios";
import { isAuthenticatedPromise, type Payload } from "./router/authGuard"; import { isAuthenticatedPromise, type Payload } from "./router/authGuard";
import router from "./router"; import router from "./router";
import { useNotificationStore } from "./stores/notification"; import { useNotificationStore } from "./stores/notification";
import { EventSourcePolyfill } from "event-source-polyfill";
let devMode = process.env.NODE_ENV === "development"; let devMode = process.env.NODE_ENV === "development";
@ -88,4 +89,13 @@ export async function refreshToken(): Promise<void> {
}); });
} }
export { http, host }; function newEventSource(path: string) {
const token = localStorage.getItem("accessToken");
return new EventSourcePolyfill(url + "/api" + path, {
headers: {
Authorization: `Bearer ${token}`,
},
});
}
export { http, newEventSource, host };

View file

@ -1,7 +1,8 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { http } from "@/serverCom"; import { http, newEventSource } from "@/serverCom";
import { useNewsletterStore } from "./newsletter"; import { useNewsletterStore } from "./newsletter";
import type { AxiosResponse } from "axios"; import type { AxiosResponse } from "axios";
import type { EventSourcePolyfill } from "event-source-polyfill";
export const useNewsletterPrintoutStore = defineStore("newsletterPrintout", { export const useNewsletterPrintoutStore = defineStore("newsletterPrintout", {
state: () => { state: () => {
@ -11,6 +12,10 @@ export const useNewsletterPrintoutStore = defineStore("newsletterPrintout", {
printing: undefined as undefined | "loading" | "success" | "failed", printing: undefined as undefined | "loading" | "success" | "failed",
sending: undefined as undefined | "loading" | "success" | "failed", sending: undefined as undefined | "loading" | "success" | "failed",
sendingPreview: undefined as undefined | "loading" | "success" | "failed", sendingPreview: undefined as undefined | "loading" | "success" | "failed",
pdfProgessSource: undefined as undefined | EventSourcePolyfill,
mailProgessSource: undefined as undefined | EventSourcePolyfill,
pdfSourceMessages: [] as Array<Object>,
mailSourceMessages: [] as Array<Object>,
}; };
}, },
actions: { actions: {
@ -94,5 +99,29 @@ export const useNewsletterPrintoutStore = defineStore("newsletterPrintout", {
}, 1500); }, 1500);
}); });
}, },
subscribePdfPrintingProgress() {
// const newsletterId = useNewsletterStore().activeNewsletter;
// if (this.pdfProgessSource != undefined) return;
// this.pdfProgessSource = newEventSource(`/admin/newsletter/${newsletterId}/printoutprogress`);
// this.pdfProgessSource.onmessage = (event) => {
// console.log("pdf", event);
// };
},
subscribeMailSendingProgress() {
// const newsletterId = useNewsletterStore().activeNewsletter;
// if (this.mailProgessSource != undefined) return;
// this.mailProgessSource = newEventSource(`/admin/newsletter/${newsletterId}/sendprogress`);
// this.mailProgessSource.onmessage = (event) => {
// console.log("mail", event);
// };
},
unsubscribePdfPrintingProgress() {
this.pdfProgessSource?.close();
this.pdfProgessSource = undefined;
},
unsubscribeMailSendingProgress() {
this.mailProgessSource?.close();
this.mailProgessSource = undefined;
},
}, },
}); });

View file

@ -89,6 +89,8 @@ export default defineComponent({
}, },
mounted() { mounted() {
this.fetchNewsletterPrintout(); this.fetchNewsletterPrintout();
this.subscribeMailSendingProgress();
this.subscribePdfPrintingProgress();
}, },
methods: { methods: {
...mapActions(useModalStore, ["openModal"]), ...mapActions(useModalStore, ["openModal"]),
@ -98,6 +100,8 @@ export default defineComponent({
"fetchNewsletterPrintoutById", "fetchNewsletterPrintoutById",
"createNewsletterMailPreview", "createNewsletterMailPreview",
"createNewsletterSend", "createNewsletterSend",
"subscribeMailSendingProgress",
"subscribePdfPrintingProgress",
]), ]),
openPdfShow(filename?: string) { openPdfShow(filename?: string) {
this.openModal( this.openModal(