diff --git a/public/assets/app.js b/public/assets/app.js index b504fae..e02c916 100644 --- a/public/assets/app.js +++ b/public/assets/app.js @@ -5641,6 +5641,14 @@ function copyYealinkUrl(inputId, btn) { // ========================================================================= // GESTIONNAIRE DE MISES À JOUR DU SYSTÈME NEXUSPBX (OTA) // ========================================================================= +function openUpdatePanel() { + switchTab('system'); + setTimeout(() => { + const el = document.getElementById('update-status-box'); + if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' }); + }, 150); +} + async function checkSystemUpdate(notify = false) { const btnCheck = document.getElementById('btn-check-update'); const btnRun = document.getElementById('btn-run-update'); @@ -5651,6 +5659,25 @@ async function checkSystemUpdate(notify = false) { const pingDot = document.getElementById('update-ping'); const verTag = document.getElementById('system-version-tag'); const appBadge = document.getElementById('app-version-badge'); + const headerUpdateBadge = document.getElementById('header-update-badge'); + const headerUpdateText = document.getElementById('header-update-text'); + + const STORAGE_KEY_TIME = 'nexus_update_last_check_ts'; + const STORAGE_KEY_DATA = 'nexus_update_cached_data'; + const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000; + + // Si pas de clic explicite (notify === false), vérifier si un check a déjà été fait il y a moins de 24h + if (!notify) { + const lastTs = parseInt(localStorage.getItem(STORAGE_KEY_TIME) || '0', 10); + const cachedRaw = localStorage.getItem(STORAGE_KEY_DATA); + if (lastTs && (Date.now() - lastTs < TWENTY_FOUR_HOURS) && cachedRaw) { + try { + const cached = JSON.parse(cachedRaw); + applyUpdateUI(cached); + return; + } catch (_) {} + } + } if (btnCheck) { btnCheck.disabled = true; @@ -5661,9 +5688,35 @@ async function checkSystemUpdate(notify = false) { const res = await fetch('/api.php?action=check_update'); const data = await res.json(); + // Enregistrement du timestamp de vérification et des données en cache local (24h) + localStorage.setItem(STORAGE_KEY_TIME, Date.now().toString()); + localStorage.setItem(STORAGE_KEY_DATA, JSON.stringify(data)); + + applyUpdateUI(data); + + if (notify) { + if (data.has_update) { + showToast(`Nouvelle version NexusPBX v${data.latest_version} disponible !`, 'info'); + } else { + showToast("Votre système NexusPBX est parfaitement à jour !", 'success'); + } + } + } catch (e) { + if (notify) { + showToast("Erreur lors de la vérification des mises à jour : " + e.message, 'error'); + } + } finally { + if (btnCheck) { + btnCheck.disabled = false; + btnCheck.classList.remove('opacity-50'); + } + } + + function applyUpdateUI(data) { if (lastChecked) { - const now = new Date(); - lastChecked.textContent = `Dernière vérification : ${now.toLocaleTimeString()}`; + const lastTs = parseInt(localStorage.getItem(STORAGE_KEY_TIME) || Date.now().toString(), 10); + const d = new Date(lastTs); + lastChecked.textContent = `Dernière vérification : ${d.toLocaleDateString()} à ${d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}`; } if (verTag && data.current_version) { @@ -5674,6 +5727,14 @@ async function checkSystemUpdate(notify = false) { } if (data.has_update) { + // Affichage du badge dans l'en-tête à côté de Tester AMI + if (headerUpdateBadge) { + headerUpdateBadge.style.display = 'inline-flex'; + if (headerUpdateText) { + headerUpdateText.textContent = `v${escapeHtml(data.latest_version)} dispo`; + } + } + if (statusText) { statusText.className = 'text-amber-400 font-bold'; statusText.innerHTML = `🚀 Nouvelle version disponible : v${escapeHtml(data.latest_version)} !`; @@ -5688,10 +5749,12 @@ async function checkSystemUpdate(notify = false) { changelogList.innerHTML = data.changelog.map(item => `
  • ${escapeHtml(item)}
  • `).join(''); if (changelogContainer) changelogContainer.classList.remove('hidden'); } - if (notify) { - showToast(`Nouvelle version NexusPBX v${data.latest_version} disponible !`, 'info'); - } } else { + // Pas de mise à jour disponible : masquer le badge dans l'en-tête + if (headerUpdateBadge) { + headerUpdateBadge.style.display = 'none'; + } + if (statusText) { statusText.className = 'text-emerald-400 font-bold'; statusText.textContent = `Votre PBX est à jour avec la dernière version officielle (v${data.current_version}).`; @@ -5699,18 +5762,6 @@ async function checkSystemUpdate(notify = false) { if (btnRun) btnRun.style.display = 'none'; if (pingDot) pingDot.classList.add('hidden'); if (changelogContainer) changelogContainer.classList.add('hidden'); - if (notify) { - showToast("Votre système NexusPBX est parfaitement à jour !", 'success'); - } - } - } catch (e) { - if (notify) { - showToast("Erreur lors de la vérification des mises à jour : " + e.message, 'error'); - } - } finally { - if (btnCheck) { - btnCheck.disabled = false; - btnCheck.classList.remove('opacity-50'); } } } diff --git a/public/index.php b/public/index.php index f095397..80b786c 100644 --- a/public/index.php +++ b/public/index.php @@ -478,6 +478,13 @@ $currentUser = Auth::getUsername();
    + + +