// Tab switching functionality
function setupTabs() {
const tabs = document.querySelectorAll('.tab-button');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
// Deactivate all tabs
tabs.forEach(t => {
t.classList.remove('active');
document.getElementById(t.dataset.tab).classList.remove('active');
});
// Activate clicked tab
tab.classList.add('active');
document.getElementById(tab.dataset.tab).classList.add('active');
});
});
}
// Health status functionality
async function updateHealth() {
try {
const response = await fetch('/system/health');
const data = await response.json();
const statusHtml = `
Status: ${data.status}
Timestamp: ${data.timestamp}
Components:
${Object.entries(data.components).map(([key, value]) => `
${key}: ${value}
`).join('')}
`;
document.getElementById('health-status').innerHTML = statusHtml;
} catch (error) {
document.getElementById('health-status').innerHTML = 'Error fetching health status
';
}
}
// Database status functionality
async function updateDatabase() {
try {
const response = await fetch('/system/database');
const data = await response.json();
displayDatabaseStatus(data);
} catch (error) {
console.error('Error fetching database status:', error);
document.getElementById('collections').innerHTML =
'Error fetching database status. Please try again later.
';
}
}
function displayDatabaseStatus(data) {
document.getElementById('db-timestamp').textContent = `Last updated: ${new Date(data.timestamp).toLocaleString()}`;
const collectionsDiv = document.getElementById('collections');
collectionsDiv.innerHTML = '';
Object.entries(data.collections).forEach(([name, info]) => {
const collectionDiv = document.createElement('div');
collectionDiv.className = 'collection fade-in';
const html = `
${name}
Document count: ${info.document_count}
Document Fields:
${info.fields.map(field => {
const indexInfo = info.indexes.find(idx =>
idx.keys.some(([key]) => key === field)
);
const indexIcon = indexInfo ?
`` :
``;
return `- ${indexIcon} ${field}
`;
}).join('')}
`;
collectionDiv.innerHTML = html;
collectionsDiv.appendChild(collectionDiv);
});
}
// Initialize everything
document.addEventListener('DOMContentLoaded', () => {
setupTabs();
updateHealth();
updateDatabase();
// Refresh data every 30 seconds
//setInterval(updateHealth, 30000);
//setInterval(updateDatabase, 30000);
});