let models = []; let currentPage = 1; const modelsPerPage = 12; // DOM Elements const modelGrid = document.getElementById('modelGrid'); const configSection = document.getElementById('configSection'); const configList = document.getElementById('configList'); const selectedModelId = document.getElementById('selectedModelId'); const configModelTitle = document.getElementById('configModelTitle'); const noConfig = document.getElementById('noConfig'); const prevPageBtn = document.getElementById('prevPage'); const nextPageBtn = document.getElementById('nextPage'); const pageInfo = document.getElementById('pageInfo'); const searchButton = document.getElementById('searchButton'); const modelIdSearch = document.getElementById('modelIdSearch'); const closeConfig = document.getElementById('closeConfig'); const loadingModels = document.getElementById('loadingModels'); const loadingConfig = document.getElementById('loadingConfig'); // Fetch models from the API async function fetchModels() { loadingModels.style.display = 'block'; try { const response = await fetch('/api/models'); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log('Fetched models:', data); models = data || []; renderModels(); updatePagination(); } catch (error) { console.error('Error fetching models:', error); modelGrid.innerHTML = `
${error.message}
Failed to fetch configurations. Please try again later.
`; configList.innerHTML = ''; } finally { loadingConfig.style.display = 'none'; } } // Initialize the page document.addEventListener('DOMContentLoaded', () => { fetchModels(); // Add event listeners document.getElementById('searchButton').addEventListener('click', handleSearch); document.getElementById('prevPage').addEventListener('click', goToPrevPage); document.getElementById('nextPage').addEventListener('click', goToNextPage); document.getElementById('closeConfig').addEventListener('click', () => { document.getElementById('configSection').style.display = 'none'; }); }); function renderModels() { loadingModels.style.display = 'block'; modelGrid.innerHTML = ''; // Simulate API delay setTimeout(() => { const startIdx = (currentPage - 1) * modelsPerPage; const endIdx = startIdx + modelsPerPage; // Sort models alphabetically by title (case-insensitive) const sortedModels = [...models].sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()) ); const paginatedModels = sortedModels.slice(startIdx, endIdx); if (paginatedModels.length === 0) { modelGrid.innerHTML = `There are currently no models to display.
Architecture: ${model.type}
`; modelCard.addEventListener('click', () => showModelConfigurations(model.id)); modelGrid.appendChild(modelCard); }); } loadingModels.style.display = 'none'; }, 500); } function getModelIcon(type) { switch(type.toLowerCase()) { case 'regression': return 'fa-chart-line'; case 'classification': return 'fa-tags'; case 'ensemble': return 'fa-layer-group'; case 'forecasting': return 'fa-calendar-alt'; case 'clustering': return 'fa-object-group'; default: return 'fa-cube'; } } function handleSearch() { const searchTerm = modelIdSearch.value.trim(); if (!searchTerm) { alert('Please enter a Model ID'); return; } // Show configurations for the searched model showModelConfigurations(searchTerm); } function updatePagination() { const totalPages = Math.ceil(models.length / modelsPerPage); prevPageBtn.disabled = currentPage <= 1; nextPageBtn.disabled = currentPage >= totalPages; pageInfo.textContent = `Page ${currentPage} of ${totalPages}`; } function goToPrevPage() { if (currentPage > 1) { currentPage--; renderModels(); updatePagination(); } } function goToNextPage() { const totalPages = Math.ceil(models.length / modelsPerPage); if (currentPage < totalPages) { currentPage++; renderModels(); updatePagination(); } } function createConfigurationElement(config) { const configElement = document.createElement('div'); configElement.className = 'config-item'; // Add your configuration content here, but skip the title // For example: configElement.innerHTML = `