|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
initializeApp(); |
|
|
}); |
|
|
|
|
|
function initializeApp() { |
|
|
|
|
|
setupEventListeners(); |
|
|
|
|
|
|
|
|
loadDashboardData(); |
|
|
|
|
|
|
|
|
startRealTimeUpdates(); |
|
|
} |
|
|
|
|
|
function setupEventListeners() { |
|
|
|
|
|
const mobileMenuButton = document.querySelector('[data-mobile-menu]'); |
|
|
if (mobileMenuButton) { |
|
|
mobileMenuButton.addEventListener('click', toggleMobileMenu); |
|
|
} |
|
|
|
|
|
|
|
|
const searchInput = document.querySelector('[data-search-input]'); |
|
|
if (searchInput) { |
|
|
searchInput.addEventListener('input', handleSearch); |
|
|
} |
|
|
|
|
|
|
|
|
const themeToggle = document.querySelector('[data-theme-toggle]'); |
|
|
if (themeToggle) { |
|
|
themeToggle.addEventListener('click', toggleTheme); |
|
|
} |
|
|
} |
|
|
|
|
|
function toggleMobileMenu() { |
|
|
const sidebar = document.querySelector('nav-sidebar'); |
|
|
if (sidebar) { |
|
|
sidebar.toggleMobile(); |
|
|
} |
|
|
} |
|
|
|
|
|
function handleSearch(event) { |
|
|
const searchTerm = event.target.value.toLowerCase(); |
|
|
|
|
|
|
|
|
console.log('Searching for:', searchTerm); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
function toggleTheme() { |
|
|
|
|
|
document.documentElement.classList.toggle('dark'); |
|
|
} |
|
|
|
|
|
|
|
|
async function loadDashboardData() { |
|
|
try { |
|
|
|
|
|
const response = await fetch('/api/dashboard'); |
|
|
const data = await response.json(); |
|
|
|
|
|
updateDashboardUI(data); |
|
|
} catch (error) { |
|
|
console.error('Failed to load dashboard data:', error); |
|
|
showNotification('Failed to load dashboard data', 'error'); |
|
|
} |
|
|
} |
|
|
|
|
|
function updateDashboardUI(data) { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
function startRealTimeUpdates() { |
|
|
|
|
|
setInterval(updateRealTimeData, 30000); |
|
|
} |
|
|
|
|
|
async function updateRealTimeData() { |
|
|
try { |
|
|
|
|
|
const response = await fetch('/api/activity/latest'); |
|
|
const activity = await response.json(); |
|
|
|
|
|
updateActivityFeed(activity); |
|
|
} catch (error) { |
|
|
console.error('Failed to update real-time data:', error); |
|
|
} |
|
|
} |
|
|
|
|
|
function updateActivityFeed(activities) { |
|
|
const activityContainer = document.querySelector('[data-activity-feed]'); |
|
|
if (!activityContainer) return; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function showNotification(message, type = 'info') { |
|
|
|
|
|
const notification = document.createElement('div'); |
|
|
notification.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg z-50 transition-all duration-300 ${ |
|
|
type === 'error' ? 'bg-red-500 text-white' : |
|
|
type === 'success' ? 'bg-green-500 text-white' : |
|
|
'bg-primary text-white' |
|
|
}`; |
|
|
notification.textContent = message; |
|
|
|
|
|
document.body.appendChild(notification); |
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
notification.remove(); |
|
|
}, 5000); |
|
|
} |
|
|
|
|
|
|
|
|
async function startAgent(agentId) { |
|
|
try { |
|
|
const response = await fetch(`/api/agents/${agentId}/start`, { |
|
|
method: 'POST' |
|
|
}); |
|
|
|
|
|
if (response.ok) { |
|
|
showNotification('Agent started successfully', 'success'); |
|
|
|
|
|
} else { |
|
|
throw new Error('Failed to start agent'); |
|
|
} |
|
|
} catch (error) { |
|
|
console.error('Failed to start agent:', error); |
|
|
showNotification('Failed to start agent', 'error'); |
|
|
} |
|
|
} |
|
|
|
|
|
async function stopAgent(agentId) { |
|
|
try { |
|
|
const response = await fetch(`/api/agents/${agentId}/stop`, { |
|
|
method: 'POST' |
|
|
}); |
|
|
|
|
|
if (response.ok) { |
|
|
showNotification('Agent stopped successfully', 'success'); |
|
|
} else { |
|
|
throw new Error('Failed to stop agent'); |
|
|
} |
|
|
} catch (error) { |
|
|
console.error('Failed to stop agent:', error); |
|
|
showNotification('Failed to stop agent', 'error'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function addRepository(repoData) { |
|
|
try { |
|
|
const response = await fetch('/api/repositories', { |
|
|
method: 'POST', |
|
|
headers: { |
|
|
'Content-Type': 'application/json', |
|
|
}, |
|
|
body: JSON.stringify(repoData) |
|
|
}); |
|
|
|
|
|
if (response.ok) { |
|
|
showNotification('Repository added successfully', 'success'); |
|
|
loadDashboardData(); |
|
|
} else { |
|
|
throw new Error('Failed to add repository'); |
|
|
} |
|
|
} catch (error) { |
|
|
console.error('Failed to add repository:', error); |
|
|
showNotification('Failed to add repository', 'error'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function formatDate(dateString) { |
|
|
const date = new Date(dateString); |
|
|
return date.toLocaleDateString('en-US', { |
|
|
year: 'numeric', |
|
|
month: 'short', |
|
|
day: 'numeric', |
|
|
hour: '2-digit', |
|
|
minute: '2-digit' |
|
|
}); |
|
|
} |
|
|
|
|
|
function debounce(func, wait) { |
|
|
let timeout; |
|
|
return function executedFunction(...args) { |
|
|
const later = () => { |
|
|
clearTimeout(timeout); |
|
|
func(...args); |
|
|
}; |
|
|
clearTimeout(timeout); |
|
|
timeout = setTimeout(later, wait); |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
window.CodeScribe = { |
|
|
showNotification, |
|
|
startAgent, |
|
|
stopAgent, |
|
|
addRepository, |
|
|
formatDate |
|
|
}; |