devportal2 / static /js /dashboard.js
Akay Borana
Complete Android-first UI rebuild with mobile-first design system
81552f4
Raw
History Blame Contribute Delete
2.28 kB
// static/js/dashboard.js v7
async function initDashboard() {
refreshDashboardFiles();
simulateSystemStatus();
}
async function refreshDashboardFiles() {
if (!currentToken) return;
var list = document.getElementById('dash-recent-files');
if (!list) return;
try {
var res = await fetch('/api/files', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({token: currentToken}) });
var data = await res.json();
list.innerHTML = '';
if (data.files && data.files.length) {
data.files.slice(0, 4).forEach(function(f) {
var ext = f.split('.').pop();
var icons = { py: 'fa-brands fa-python', js: 'fa-brands fa-js', html: 'fa-brands fa-html5', css: 'fa-brands fa-css3-alt' };
var colors = { py: '#4B8BBE', js: '#F7DF1E', html: '#E34F26', css: '#1572B6' };
var html = '<div class="file-row" tabindex="0" onclick="openFileFromDash(\'' + f + '\')">' +
'<div class="file-icon"><i class="' + (icons[ext] || 'fa-solid fa-file') + '" style="color:' + (colors[ext] || 'var(--accent)') + '"></i></div>' +
'<div class="file-meta"><h4>' + f + '</h4><p>Workspace file</p></div></div>';
list.insertAdjacentHTML('beforeend', html);
});
} else {
list.innerHTML = '<div style="color:var(--text-3);font-size:12px;text-align:center;padding:var(--sp-5) 0">No files yet</div>';
}
} catch (e) { console.error(e); }
}
function openFileFromDash(f) {
switchView('editor-view', document.querySelector('.nav-item[data-view=editor-view]'));
if (typeof openFile === 'function') openFile(f);
}
function simulateSystemStatus() {
setInterval(function() {
var cpu = document.getElementById('stat-cpu'), cpuBar = document.getElementById('bar-cpu');
if (cpu && cpuBar) { var v = Math.floor(Math.random() * 20 + 5); cpu.textContent = v + '%'; cpuBar.style.width = v + '%'; }
var ram = document.getElementById('stat-ram'), ramBar = document.getElementById('bar-ram');
if (ram && ramBar) { var v = Math.floor(Math.random() * 15 + 30); ram.textContent = v + '%'; ramBar.style.width = v + '%'; }
}, 3000);
}