diff --git a/static/consistency.js b/static/consistency.js index fddba1d..cc6c53a 100644 --- a/static/consistency.js +++ b/static/consistency.js @@ -2,6 +2,7 @@ import { API_BASE_URL, CONSISTENCY_POLL_INTERVAL, setInconsistencyData, inconsistencyData } from './global.js'; import { hideConsistencyModal, showConsistencyModal } from './modals.js'; import { loadAllData } from './data_loader.js'; // Will be imported later +import { checkConsistency } from './global.js'; /** * Core function to resolve consistency by making a POST call to a sync endpoint. @@ -55,61 +56,6 @@ } -/** - * Periodically checks the consistency status with the backend. - */ -export async function checkConsistency() { - const button = document.getElementById('consistency-button'); - if (!button) return; - - // Save previous state before fetch - const hadConflict = inconsistencyData !== null && inconsistencyData.inconsistent === true; - const isCurrentlyError = button.classList.contains('error'); - - button.textContent = 'Checking...'; - button.classList.add('loading'); - button.classList.remove('consistent', 'inconsistent', 'error'); - button.disabled = true; - - try { - const response = await fetch(`${API_BASE_URL}/is-consistent`); - if (!response.ok) throw new Error(response.statusText); - - const data = await response.json(); - const consistencyStatus = data.consistent; - const hasConflict = consistencyStatus.inconsistent === true; - - setInconsistencyData(hasConflict ? consistencyStatus : null); - - button.classList.remove('loading'); - button.disabled = !hasConflict; // Only enable if inconsistent - - if (hasConflict) { - button.textContent = '🚨 CONFLICT'; - button.classList.remove('consistent', 'error'); - button.classList.add('inconsistent'); - // If conflict is new or if we recovered from an error, show the modal - if (!hadConflict || isCurrentlyError) { - // Optionally show the modal automatically here, or leave it to user click - } - } else { - button.textContent = '✅ Consistent'; - button.classList.remove('inconsistent', 'error'); - button.classList.add('consistent'); - hideConsistencyModal(); - } - - } catch (error) { - button.classList.remove('loading', 'consistent', 'inconsistent'); - button.classList.add('error'); - button.textContent = '❌ Error'; - button.disabled = true; - setInconsistencyData(null); - console.error("Consistency check failed:", error); - } -} - - // Exported functions must be attached to 'window' if called from inline HTML attributes export function manualFlush() { resolveConsistency('flush'); diff --git a/static/data_loader.js b/static/data_loader.js index 415c72a..ac840fe 100644 --- a/static/data_loader.js +++ b/static/data_loader.js @@ -2,8 +2,7 @@ import { listClusters } from './clusters.js'; import { listListeners } from './listeners.js'; import { setupModalTabs } from './modals.js'; -import { checkConsistency } from './consistency.js'; -import {CONSISTENCY_POLL_INTERVAL} from './global.js'; +import {CONSISTENCY_POLL_INTERVAL, checkConsistency} from './global.js'; // ========================================================================= diff --git a/static/global.js b/static/global.js index a3e482c..80b1944 100644 --- a/static/global.js +++ b/static/global.js @@ -798,7 +798,7 @@ document.getElementById('consistencyModal').style.display = 'none'; } -async function checkConsistency() { +export async function checkConsistency() { const button = document.getElementById('consistency-button'); if (!button) return;