2025-09-10 14:28:38 +02:00
|
|
|
<template>
|
2025-09-24 09:13:04 +02:00
|
|
|
<div id="refresh-cache-button">
|
|
|
|
|
<k-button
|
|
|
|
|
v-if="pageStatus !== 'draft'"
|
|
|
|
|
:theme="theme"
|
|
|
|
|
variant="dimmed"
|
|
|
|
|
:icon="icon"
|
|
|
|
|
:title="title"
|
|
|
|
|
@click="refreshCache()"
|
2026-01-15 12:08:13 +01:00
|
|
|
:disabled="isProcessing"
|
2025-09-24 09:13:04 +02:00
|
|
|
>{{ text }}</k-button
|
|
|
|
|
>
|
|
|
|
|
</div>
|
2025-09-10 14:28:38 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-09-24 09:13:04 +02:00
|
|
|
import { computed, ref } from "vue";
|
2025-09-10 14:28:38 +02:00
|
|
|
|
2025-09-24 09:13:04 +02:00
|
|
|
const { pageUri, pageStatus, lastCacheUpdate } = defineProps({
|
2025-09-10 14:28:38 +02:00
|
|
|
pageUri: String,
|
|
|
|
|
pageStatus: String,
|
2025-09-24 09:13:04 +02:00
|
|
|
lastCacheUpdate: String,
|
2025-09-10 14:28:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const text = ref("Rafraîchir");
|
|
|
|
|
const icon = ref("refresh");
|
|
|
|
|
const theme = ref("aqua-icon");
|
2026-01-15 12:08:13 +01:00
|
|
|
const isProcessing = ref(false);
|
|
|
|
|
|
2025-09-24 09:13:04 +02:00
|
|
|
const title = computed(() => {
|
|
|
|
|
return lastCacheUpdate?.length > 0
|
|
|
|
|
? "Dernière mise à jour : " + lastCacheUpdate
|
|
|
|
|
: "Mettre à jour le cache front";
|
|
|
|
|
});
|
2025-09-10 14:28:38 +02:00
|
|
|
|
|
|
|
|
async function refreshCache() {
|
2026-01-15 12:08:13 +01:00
|
|
|
isProcessing.value = true;
|
2025-09-10 14:28:38 +02:00
|
|
|
icon.value = "loader";
|
|
|
|
|
theme.value = "orange-icon";
|
|
|
|
|
|
2026-01-15 12:08:13 +01:00
|
|
|
// Pour les projets multiples (batch processing)
|
|
|
|
|
if (pageUri === 'projects') {
|
|
|
|
|
await refreshAllProjects();
|
|
|
|
|
} else {
|
|
|
|
|
await refreshSingleProject();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function refreshAllProjects() {
|
|
|
|
|
let offset = 0;
|
|
|
|
|
const limit = 10; // 10 projets par batch
|
|
|
|
|
let hasMore = true;
|
|
|
|
|
let total = 0;
|
|
|
|
|
|
2026-01-15 12:18:33 +01:00
|
|
|
text.value = "En cours 0%";
|
2026-01-15 12:13:26 +01:00
|
|
|
|
2026-01-15 12:08:13 +01:00
|
|
|
try {
|
|
|
|
|
while (hasMore) {
|
|
|
|
|
const init = {
|
|
|
|
|
method: "POST",
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
pageUri: 'projects',
|
|
|
|
|
offset,
|
|
|
|
|
limit
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await fetch("/refresh-cache.json", init);
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
|
|
|
|
|
if (json.status === "error") {
|
|
|
|
|
throw new Error(json.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
total = json.total;
|
|
|
|
|
hasMore = json.hasMore;
|
|
|
|
|
offset = json.nextOffset;
|
|
|
|
|
|
2026-01-15 12:18:33 +01:00
|
|
|
// Mise à jour de la progression dans le texte du bouton
|
2026-01-15 12:08:13 +01:00
|
|
|
const progress = Math.round((json.processed / json.total) * 100);
|
2026-01-15 12:18:33 +01:00
|
|
|
text.value = `En cours ${progress}%`;
|
2026-01-15 12:08:13 +01:00
|
|
|
|
2026-01-15 12:18:33 +01:00
|
|
|
console.log(`Batch terminé : ${json.processed}/${json.total} projets (${progress}%)`);
|
2026-01-15 12:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Succès
|
2026-01-15 12:13:26 +01:00
|
|
|
text.value = "Terminé";
|
2026-01-15 12:08:13 +01:00
|
|
|
icon.value = "check";
|
|
|
|
|
theme.value = "green-icon";
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
location.href = location.href;
|
2026-01-15 12:13:26 +01:00
|
|
|
}, 2000);
|
2026-01-15 12:08:13 +01:00
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
text.value = "Erreur";
|
|
|
|
|
icon.value = "alert";
|
|
|
|
|
theme.value = "red-icon";
|
|
|
|
|
isProcessing.value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function refreshSingleProject() {
|
|
|
|
|
text.value = "En cours…";
|
|
|
|
|
|
2025-09-10 14:28:38 +02:00
|
|
|
const init = {
|
|
|
|
|
method: "POST",
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
body: JSON.stringify({ pageUri }),
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-15 12:08:13 +01:00
|
|
|
try {
|
|
|
|
|
const res = await fetch("/refresh-cache.json", init);
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
|
|
|
|
|
if (json.status === "error") {
|
|
|
|
|
throw new Error(json.message);
|
|
|
|
|
}
|
2025-09-10 14:28:38 +02:00
|
|
|
|
|
|
|
|
console.log(json);
|
|
|
|
|
text.value = "Terminé";
|
|
|
|
|
icon.value = "check";
|
|
|
|
|
theme.value = "green-icon";
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2025-09-24 09:13:04 +02:00
|
|
|
location.href = location.href;
|
|
|
|
|
}, 1500);
|
2026-01-15 12:08:13 +01:00
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
text.value = "Erreur";
|
|
|
|
|
icon.value = "alert";
|
|
|
|
|
theme.value = "red-icon";
|
|
|
|
|
isProcessing.value = false;
|
2025-09-10 14:28:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|