/** * Code Quality Dashboard Component * Manages the code quality dashboard page */ function codeQualityDashboard() { return { loading: false, scanning: false, error: null, successMessage: null, stats: { total_violations: 0, errors: 0, warnings: 0, open: 0, assigned: 0, resolved: 0, ignored: 0, technical_debt_score: 100, trend: [], by_severity: {}, by_rule: {}, by_module: {}, top_files: [], last_scan: null }, async init() { await this.loadStats(); }, async loadStats() { this.loading = true; this.error = null; try { const response = await fetch('/api/v1/admin/code-quality/stats', { headers: { 'Authorization': `Bearer ${getAccessToken()}` } }); if (!response.ok) { if (response.status === 401) { window.location.href = '/admin/login'; return; } throw new Error(`HTTP ${response.status}: ${response.statusText}`); } this.stats = await response.json(); } catch (err) { console.error('Failed to load stats:', err); this.error = err.message; } finally { this.loading = false; } }, async runScan() { this.scanning = true; this.error = null; this.successMessage = null; try { const response = await fetch('/api/v1/admin/code-quality/scan', { method: 'POST', headers: { 'Authorization': `Bearer ${getAccessToken()}`, 'Content-Type': 'application/json' } }); if (!response.ok) { if (response.status === 401) { window.location.href = '/admin/login'; return; } const errorData = await response.json(); throw new Error(errorData.detail || `HTTP ${response.status}`); } const scan = await response.json(); this.successMessage = `Scan completed: ${scan.total_violations} violations found (${scan.errors} errors, ${scan.warnings} warnings)`; // Reload stats after scan await this.loadStats(); // Clear success message after 5 seconds setTimeout(() => { this.successMessage = null; }, 5000); } catch (err) { console.error('Failed to run scan:', err); this.error = err.message; } finally { this.scanning = false; } }, async refresh() { await this.loadStats(); } }; }