From b1f7854510bb803d0e3b4bba55ad56c6e4f88415 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Wed, 24 Sep 2025 09:13:04 +0200 Subject: [PATCH] refresh cache button plugin : add last cache update date and time on button title --- public/site/blueprints/pages/project.yml | 2 ++ .../plugins/refresh-cache-button/index.js | 2 +- .../plugins/refresh-cache-button/index.php | 3 +- .../src/components/RefreshCacheButton.vue | 36 +++++++++++-------- .../src/routes/refresh-cache.php | 11 ++++++ 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/public/site/blueprints/pages/project.yml b/public/site/blueprints/pages/project.yml index db6025a..946e238 100644 --- a/public/site/blueprints/pages/project.yml +++ b/public/site/blueprints/pages/project.yml @@ -19,6 +19,8 @@ tabs: columns: - width: 1/1 fields: + lastCacheUpdate: + type: hidden isClientRequest: type: hidden default: "false" diff --git a/public/site/plugins/refresh-cache-button/index.js b/public/site/plugins/refresh-cache-button/index.js index e9ec8e3..8fc4d42 100644 --- a/public/site/plugins/refresh-cache-button/index.js +++ b/public/site/plugins/refresh-cache-button/index.js @@ -1 +1 @@ -(function(){"use strict";function f(n,e,c,t,r,o,i,u){var a=typeof n=="function"?n.options:n;return e&&(a.render=e,a.staticRenderFns=c,a._compiled=!0),{exports:n,options:a}}const l={__name:"RefreshCacheButton",props:{pageUri:String,pageStatus:String},setup(n){const{pageUri:e,pageStatus:c}=n,t=Vue.ref("Rafraîchir"),r=Vue.ref("refresh"),o=Vue.ref("aqua-icon");async function i(){t.value="En cours…",r.value="loader",o.value="orange-icon";const u={method:"POST","Content-Type":"application/json",body:JSON.stringify({pageUri:e})},s=await(await fetch("/refresh-cache.json",u)).json();s.status==="error"?(console.error(s),t.value="Erreur",r.value="alert",o.value="red-icon"):(console.log(s),t.value="Terminé",r.value="check",o.value="green-icon",setTimeout(()=>{t.value="Rafraîchir",r.value="refresh",o.value="aqua-icon"},2e3))}return{__sfc:!0,text:t,icon:r,theme:o,refreshCache:i}}};var h=function(){var e=this,c=e._self._c,t=e._self._setupProxy;return e.pageStatus!=="draft"?c("k-button",{attrs:{theme:t.theme,variant:"dimmed",icon:t.icon,title:"Rafraîchir le cache front"},on:{click:function(r){return t.refreshCache()}}},[e._v(e._s(t.text))]):e._e()},_=[],p=f(l,h,_);const v=p.exports;window.panel.plugin("adrienpayet/refresh-cache-button",{components:{"refresh-cache-button":v}})})(); +(function(){"use strict";function f(n,e,a,t,r,c,s,u){var o=typeof n=="function"?n.options:n;return e&&(o.render=e,o.staticRenderFns=a,o._compiled=!0),{exports:n,options:o}}const l={__name:"RefreshCacheButton",props:{pageUri:String,pageStatus:String,lastCacheUpdate:String},setup(n){const{pageUri:e,pageStatus:a,lastCacheUpdate:t}=n,r=Vue.ref("Rafraîchir"),c=Vue.ref("refresh"),s=Vue.ref("aqua-icon"),u=Vue.computed(()=>(t==null?void 0:t.length)>0?"Dernière mise à jour : "+t:"Mettre à jour le cache front");async function o(){r.value="En cours…",c.value="loader",s.value="orange-icon";const m={method:"POST","Content-Type":"application/json",body:JSON.stringify({pageUri:e})},i=await(await fetch("/refresh-cache.json",m)).json();i.status==="error"?(console.error(i),r.value="Erreur",c.value="alert",s.value="red-icon"):(console.log(i),r.value="Terminé",c.value="check",s.value="green-icon",setTimeout(()=>{location.href=location.href},1500))}return{__sfc:!0,text:r,icon:c,theme:s,title:u,refreshCache:o}}};var h=function(){var e=this,a=e._self._c,t=e._self._setupProxy;return a("div",{attrs:{id:"refresh-cache-button"}},[e.pageStatus!=="draft"?a("k-button",{attrs:{theme:t.theme,variant:"dimmed",icon:t.icon,title:t.title},on:{click:function(r){return t.refreshCache()}}},[e._v(e._s(t.text))]):e._e()],1)},_=[],p=f(l,h,_);const d=p.exports;window.panel.plugin("adrienpayet/refresh-cache-button",{components:{"refresh-cache-button":d}})})(); diff --git a/public/site/plugins/refresh-cache-button/index.php b/public/site/plugins/refresh-cache-button/index.php index 6ec483b..4f27279 100755 --- a/public/site/plugins/refresh-cache-button/index.php +++ b/public/site/plugins/refresh-cache-button/index.php @@ -10,7 +10,8 @@ Kirby::plugin('adrienpayet/refresh-cache-button', [ 'component' => 'refresh-cache-button', 'props' => [ 'pageUri' => $page->uri(), - 'pageStatus' => $page->status() + 'pageStatus' => $page->status(), + 'lastCacheUpdate' => $page->lastCacheUpdate()->value(), ] ]; } diff --git a/public/site/plugins/refresh-cache-button/src/components/RefreshCacheButton.vue b/public/site/plugins/refresh-cache-button/src/components/RefreshCacheButton.vue index 3a8d32c..5fdb1cf 100644 --- a/public/site/plugins/refresh-cache-button/src/components/RefreshCacheButton.vue +++ b/public/site/plugins/refresh-cache-button/src/components/RefreshCacheButton.vue @@ -1,26 +1,34 @@ diff --git a/public/site/plugins/refresh-cache-button/src/routes/refresh-cache.php b/public/site/plugins/refresh-cache-button/src/routes/refresh-cache.php index 4c2e9d5..207d34e 100644 --- a/public/site/plugins/refresh-cache-button/src/routes/refresh-cache.php +++ b/public/site/plugins/refresh-cache-button/src/routes/refresh-cache.php @@ -12,6 +12,11 @@ return [ $projects = page('projects')->children(); foreach ($projects as $project) { $project->rebuildStepsCache(); + + $formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'Europe/Paris'); + $project->update([ + 'lastCacheUpdate' => $formatter->format(time()) + ]); } return [ 'satus' => 'success', @@ -43,6 +48,12 @@ return [ $project->rebuildStepsCache(); + $formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'Europe/Paris'); + $project->update([ + 'lastCacheUpdate' => $formatter->format(time()) + ]); + + return [ 'satus' => 'success', 'message' => 'Données de la page ' . $data->pageUri . ' rafraîchie avec succès.'