11<template lang="pug">
22q-layout
3- sesame-appbar( @closeDrawer ="drawer = !drawer" )
3+ sesame-appbar( @closeDrawer ="drawer = !drawer" @syncing = "syncing" )
44 q-drawer.flex ( v-model ="drawer" side ="left" : mini= "true" bordered )
55 template( #mini )
66 q-scroll-area.fit.mini-slot.cursor-pointer
@@ -20,6 +20,19 @@ q-layout
2020 q-separator
2121 q-page-container
2222 nuxt-page
23+ q-dialog( seamless v-model ="eventSeamless" position ="bottom" )
24+ q-card( style ="width: 350px" )
25+ q-linear-progress( :value ="eventSeamlessProgress" color ="amber-9" )
26+ q-card-section.row.items-center.no-wrap
27+ q-circular-progress.q-mr-md ( indeterminate size ="42px" color ="amber-9" )
28+ //- pre(v-html="JSON.stringify(eventSeamlessCurrentJobs, null, 2)")
29+ div
30+ .text-weight-bold.q-px-md.text-center
31+ | Synchronisation en cours
32+ q-badge( color ="amber-10" ) {{ eventSeamlessCurrent }}/{{ eventSeamlessTotal }}
33+ //- .text-grey Fitz & The Tantrums
34+ q-space
35+ q-btn( flat round icon ="mdi-close" v-close-popup )
2336</template >
2437
2538<script lang="ts" setup>
@@ -28,11 +41,74 @@ import { IdentityState } from '~/composables'
2841import { useIdentityStateStore } from ' ~/stores/identityState'
2942import { useIdentityAffectationStore } from ' ~/stores/identityAffectation'
3043import { useMenu } from ' ~/composables'
44+ import ReconnectingEventSource from " reconnecting-eventsource" ;
45+
46+ const identityStateStore = useIdentityStateStore ()
47+
48+ const auth = useAuth ()
49+ const config = useAppConfig ()
50+ const esUrl = new URL (config .baseUrl + " /core/backends/sse" )
51+ esUrl .searchParams .append (" key" , ' ' + auth .user ?.sseToken )
52+ var es = new ReconnectingEventSource (esUrl )
53+
54+ console .log (' identityStateStore.getProcessingCount' , identityStateStore .getProcessingCount )
55+
56+ const eventSeamless = ref (false )
57+ const eventSeamlessTotal = ref (identityStateStore .getProcessingCount )
58+ const eventSeamlessCurrent = ref (0 )
59+ const eventSeamlessCurrentJobs = ref ({})
60+
61+ const eventSeamlessProgress = computed (() => {
62+ return eventSeamlessTotal .value === 0 ? 0 : eventSeamlessCurrent .value / eventSeamlessTotal .value
63+ })
64+
65+ async function onmessage(event ) {
66+ try {
67+ const data = JSON .parse (event .data )
68+
69+ if (/ ^ job:/ .test (data .channel )) {
70+ eventSeamless .value = true
71+ if (eventSeamlessTotal .value === 0 ) {
72+ await identityStateStore .fetchProcessingCount ()
73+ eventSeamlessTotal .value = identityStateStore .getProcessingCount
74+ }
75+ }
76+
77+ switch (data .channel ) {
78+ case ' job:added' :
79+ eventSeamlessCurrentJobs .value [data .payload .jobId ] = data .payload
80+ break
81+
82+ case ' job:completed' :
83+ delete eventSeamlessCurrentJobs .value [data .payload .jobId ]
84+ eventSeamlessCurrent .value ++
85+
86+ if (eventSeamlessCurrent .value >= eventSeamlessTotal .value ) {
87+ eventSeamlessCurrent .value = 0
88+ eventSeamlessCurrentJobs .value = {}
89+ setTimeout (() => {
90+ eventSeamless .value = false
91+ }, 2000 )
92+ }
93+ break
94+ }
95+
96+ } catch (e ) {
97+ console .error (e )
98+ }
99+ }
100+
101+ es .onmessage = onmessage
102+
103+ function syncing(payload : { count: number }) {
104+ eventSeamlessTotal .value = payload .count
105+ eventSeamlessCurrent .value = 0
106+ eventSeamless .value = true
107+ }
31108
32109const drawer = ref (true )
33110
34111const router = useRouter ()
35- const identityStateStore = useIdentityStateStore ()
36112const identityAffectationStore = useIdentityAffectationStore ()
37113const { fetchAllStateCount } = identityStateStore
38114const { fetchAllAffectationCount } = identityAffectationStore
@@ -51,10 +127,6 @@ function push(path: string) {
51127function logout() {
52128 router .push ({ name: ' login' })
53129}
54-
55- function test() {
56- console .log (' test' )
57- }
58130 </script >
59131
60132<style >
0 commit comments