2024-10-14 17:03:48 +02:00
|
|
|
<template>
|
|
|
|
<CloudIcon v-if="syncing == 'synced'" class="w-5 h-5" />
|
2024-10-15 16:24:29 +02:00
|
|
|
<CloudArrowUpIcon
|
|
|
|
v-else-if="syncing == 'detectedChanges'"
|
|
|
|
class="w-5 h-5 cursor-pointer animate-bounce"
|
|
|
|
@click="syncAll"
|
|
|
|
/>
|
2024-10-14 17:03:48 +02:00
|
|
|
<ArrowPathIcon v-else-if="syncing == 'syncing'" class="w-5 h-5 animate-spin" />
|
2024-10-15 16:24:29 +02:00
|
|
|
<ExclamationTriangleIcon
|
|
|
|
v-else
|
|
|
|
class="w-5 h-5 animate-[ping_1s_ease-in-out_3] text-red-500 cursor-pointer"
|
|
|
|
@click="syncAll"
|
|
|
|
/>
|
2024-10-14 17:03:48 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import { mapState, mapActions } from "pinia";
|
|
|
|
import { useProtocolStore } from "@/stores/admin/protocol";
|
|
|
|
import { ArrowPathIcon, CloudArrowUpIcon, CloudIcon, ExclamationTriangleIcon } from "@heroicons/vue/24/outline";
|
2024-10-15 16:24:29 +02:00
|
|
|
import { useProtocolAgendaStore } from "@/stores/admin/protocolAgenda";
|
|
|
|
import { useProtocolPresenceStore } from "@/stores/admin/protocolPresence";
|
2024-10-14 17:03:48 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export default defineComponent({
|
|
|
|
props: ["executeSyncAll"],
|
|
|
|
watch: {
|
|
|
|
executeSyncAll() {
|
|
|
|
this.syncAll();
|
|
|
|
},
|
|
|
|
syncing() {
|
|
|
|
this.$emit("syncState", this.syncing);
|
|
|
|
},
|
|
|
|
detectedChangeProtocol() {
|
|
|
|
clearTimeout(this.protocolTimer);
|
2024-10-15 16:24:29 +02:00
|
|
|
this.setProtocolSyncingState("synced");
|
2024-10-14 17:03:48 +02:00
|
|
|
if (this.detectedChangeProtocol == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setProtocolSyncingState("detectedChanges");
|
|
|
|
this.protocolTimer = setTimeout(() => {
|
|
|
|
this.synchronizeActiveProtocol();
|
|
|
|
}, 10000);
|
|
|
|
},
|
2024-10-15 16:24:29 +02:00
|
|
|
detectedChangeProtocolAgenda() {
|
|
|
|
console.log(this.detectedChangeProtocolAgenda);
|
|
|
|
clearTimeout(this.protocolAgendaTimer);
|
|
|
|
if (this.detectedChangeProtocolAgenda == false) {
|
|
|
|
this.setProtocolAgendaSyncingState("synced");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setProtocolAgendaSyncingState("detectedChanges");
|
|
|
|
this.protocolAgendaTimer = setTimeout(() => {
|
|
|
|
this.synchronizeActiveProtocolAgenda();
|
|
|
|
}, 10000);
|
|
|
|
},
|
|
|
|
detectedChangeProtocolPresence() {
|
|
|
|
clearTimeout(this.protocolPresenceTimer);
|
|
|
|
this.setProtocolPresenceSyncingState("synced");
|
|
|
|
if (this.detectedChangeProtocolPresence == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setProtocolPresenceSyncingState("detectedChanges");
|
|
|
|
this.protocolPresenceTimer = setTimeout(() => {
|
|
|
|
this.synchronizeActiveProtocolPresence();
|
|
|
|
}, 10000);
|
|
|
|
},
|
2024-10-14 17:03:48 +02:00
|
|
|
},
|
|
|
|
emits: {
|
|
|
|
syncState(state: "synced" | "syncing" | "detectedChanges" | "failed") {
|
|
|
|
return typeof state == "string";
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
protocolTimer: undefined as undefined | any,
|
2024-10-15 16:24:29 +02:00
|
|
|
protocolAgendaTimer: undefined as undefined | any,
|
|
|
|
protocolPresenceTimer: undefined as undefined | any,
|
2024-10-14 17:03:48 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$emit("syncState", this.syncing);
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
if (!this.protocolTimer) clearTimeout(this.protocolTimer);
|
2024-10-15 16:24:29 +02:00
|
|
|
if (!this.protocolAgendaTimer) clearTimeout(this.protocolAgendaTimer);
|
|
|
|
if (!this.protocolPresenceTimer) clearTimeout(this.protocolPresenceTimer);
|
2024-10-14 17:03:48 +02:00
|
|
|
},
|
|
|
|
computed: {
|
2024-10-15 16:24:29 +02:00
|
|
|
...mapState(useProtocolStore, ["syncingProtocol", "detectedChangeProtocol"]),
|
|
|
|
...mapState(useProtocolAgendaStore, ["syncingProtocolAgenda", "detectedChangeProtocolAgenda"]),
|
|
|
|
...mapState(useProtocolPresenceStore, ["syncingProtocolPresence", "detectedChangeProtocolPresence"]),
|
2024-10-14 17:03:48 +02:00
|
|
|
|
|
|
|
syncing(): "synced" | "syncing" | "detectedChanges" | "failed" {
|
2024-10-15 16:24:29 +02:00
|
|
|
let states = [this.syncingProtocol, this.syncingProtocolAgenda, this.syncingProtocolPresence];
|
2024-10-14 17:03:48 +02:00
|
|
|
|
|
|
|
if (states.includes("failed")) return "failed";
|
|
|
|
else if (states.includes("syncing")) return "syncing";
|
|
|
|
else if (states.includes("detectedChanges")) return "detectedChanges";
|
|
|
|
else return "synced";
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions(useProtocolStore, ["synchronizeActiveProtocol", "setProtocolSyncingState"]),
|
2024-10-15 16:24:29 +02:00
|
|
|
...mapActions(useProtocolAgendaStore, ["synchronizeActiveProtocolAgenda", "setProtocolAgendaSyncingState"]),
|
|
|
|
...mapActions(useProtocolPresenceStore, ["synchronizeActiveProtocolPresence", "setProtocolPresenceSyncingState"]),
|
2024-10-14 17:03:48 +02:00
|
|
|
syncAll() {
|
|
|
|
if (!this.protocolTimer) clearTimeout(this.protocolTimer);
|
2024-10-15 16:24:29 +02:00
|
|
|
if (!this.protocolAgendaTimer) clearTimeout(this.protocolAgendaTimer);
|
|
|
|
if (!this.protocolPresenceTimer) clearTimeout(this.protocolPresenceTimer);
|
2024-10-14 17:03:48 +02:00
|
|
|
this.synchronizeActiveProtocol();
|
2024-10-15 16:24:29 +02:00
|
|
|
this.synchronizeActiveProtocolAgenda();
|
|
|
|
this.synchronizeActiveProtocolPresence();
|
2024-10-14 17:03:48 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|