update kirby to v5 and add refresh cache panel view button
This commit is contained in:
commit
9a86d41254
466 changed files with 19960 additions and 10497 deletions
|
|
@ -0,0 +1,57 @@
|
|||
<template>
|
||||
<k-button
|
||||
v-if="pageStatus !== 'draft'"
|
||||
:theme="theme"
|
||||
variant="dimmed"
|
||||
:icon="icon"
|
||||
title="Rafraîchir le cache front"
|
||||
@click="refreshCache()"
|
||||
>{{ text }}</k-button
|
||||
>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
|
||||
const { pageUri, pageStatus } = defineProps({
|
||||
pageUri: String,
|
||||
pageStatus: String,
|
||||
});
|
||||
|
||||
const text = ref("Rafraîchir");
|
||||
const icon = ref("refresh");
|
||||
const theme = ref("aqua-icon");
|
||||
|
||||
async function refreshCache() {
|
||||
text.value = "En cours…";
|
||||
icon.value = "loader";
|
||||
theme.value = "orange-icon";
|
||||
|
||||
const init = {
|
||||
method: "POST",
|
||||
"Content-Type": "application/json",
|
||||
body: JSON.stringify({ pageUri }),
|
||||
};
|
||||
|
||||
const res = await fetch("/refresh-cache.json", init);
|
||||
const json = await res.json();
|
||||
|
||||
if (json.status === "error") {
|
||||
console.error(json);
|
||||
text.value = "Erreur";
|
||||
icon.value = "alert";
|
||||
theme.value = "red-icon";
|
||||
} else {
|
||||
console.log(json);
|
||||
text.value = "Terminé";
|
||||
icon.value = "check";
|
||||
theme.value = "green-icon";
|
||||
|
||||
setTimeout(() => {
|
||||
text.value = "Rafraîchir";
|
||||
icon.value = "refresh";
|
||||
theme.value = "aqua-icon";
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
7
public/site/plugins/refresh-cache-button/src/index.js
Executable file
7
public/site/plugins/refresh-cache-button/src/index.js
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
import RefreshCacheButton from "./components/RefreshCacheButton.vue";
|
||||
|
||||
window.panel.plugin("adrienpayet/refresh-cache-button", {
|
||||
components: {
|
||||
"refresh-cache-button": RefreshCacheButton,
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
set_time_limit(0);
|
||||
|
||||
return [
|
||||
'pattern' => '/refresh-cache.json',
|
||||
'method' => 'POST',
|
||||
'action' => function() {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
if ($data->pageUri === 'projects') {
|
||||
$projects = page('projects')->children();
|
||||
foreach ($projects as $project) {
|
||||
$project->rebuildStepsCache();
|
||||
}
|
||||
return [
|
||||
'satus' => 'success',
|
||||
'message' => 'Données des pages projets rafraîchies avec succès.'
|
||||
];
|
||||
} else {
|
||||
try {
|
||||
$page = page($data->pageUri);
|
||||
} catch (\Throwable $th) {
|
||||
return [
|
||||
'status' => 'error',
|
||||
'message' => 'Impossible de rafraîchir le cache de la page : ' . $data->pageUri . '.',
|
||||
'details' => $th->getMessage(),
|
||||
'file' => $th->getFile(),
|
||||
'line' > $th->getLine()
|
||||
];
|
||||
}
|
||||
|
||||
$project = $page->template() == 'project' ?
|
||||
$page
|
||||
: $page->parents()->findBy('template', 'project');
|
||||
|
||||
if (!$project) {
|
||||
return [
|
||||
'satus' => 'error',
|
||||
'message' => 'Impossible de rafraîchir les données de la page ' . $data->pageUri . '. Aucun projet correspondant.'
|
||||
];
|
||||
}
|
||||
|
||||
$project->rebuildStepsCache();
|
||||
|
||||
return [
|
||||
'satus' => 'success',
|
||||
'message' => 'Données de la page ' . $data->pageUri . ' rafraîchie avec succès.'
|
||||
];
|
||||
}
|
||||
}
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue