diff --git a/static/admin/js/code-quality-dashboard.js b/static/admin/js/code-quality-dashboard.js index eba055fd..601e8d39 100644 --- a/static/admin/js/code-quality-dashboard.js +++ b/static/admin/js/code-quality-dashboard.js @@ -5,6 +5,13 @@ function codeQualityDashboard() { return { + // Extend base data + ...data(), + + // Set current page for navigation + currentPage: 'code-quality', + + // Dashboard-specific data loading: false, scanning: false, error: null, @@ -35,24 +42,16 @@ function codeQualityDashboard() { 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(); + const stats = await apiClient.get('/admin/code-quality/stats'); + this.stats = stats; } catch (err) { console.error('Failed to load stats:', err); this.error = err.message; + + // Redirect to login if unauthorized + if (err.message.includes('Unauthorized')) { + window.location.href = '/admin/login'; + } } finally { this.loading = false; } @@ -64,24 +63,7 @@ function codeQualityDashboard() { 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(); + const scan = await apiClient.post('/admin/code-quality/scan'); this.successMessage = `Scan completed: ${scan.total_violations} violations found (${scan.errors} errors, ${scan.warnings} warnings)`; // Reload stats after scan @@ -94,6 +76,11 @@ function codeQualityDashboard() { } catch (err) { console.error('Failed to run scan:', err); this.error = err.message; + + // Redirect to login if unauthorized + if (err.message.includes('Unauthorized')) { + window.location.href = '/admin/login'; + } } finally { this.scanning = false; } diff --git a/static/admin/js/code-quality-violations.js b/static/admin/js/code-quality-violations.js index 98f6273c..9fd536b3 100644 --- a/static/admin/js/code-quality-violations.js +++ b/static/admin/js/code-quality-violations.js @@ -5,6 +5,13 @@ function codeQualityViolations() { return { + // Extend base data + ...data(), + + // Set current page for navigation + currentPage: 'code-quality', + + // Violations-specific data loading: false, error: null, violations: [], @@ -38,31 +45,18 @@ function codeQualityViolations() { try { // Build query params - const params = new URLSearchParams({ + const params = { page: this.pagination.page.toString(), page_size: this.pagination.page_size.toString() - }); + }; - if (this.filters.severity) params.append('severity', this.filters.severity); - if (this.filters.status) params.append('status', this.filters.status); - if (this.filters.rule_id) params.append('rule_id', this.filters.rule_id); - if (this.filters.file_path) params.append('file_path', this.filters.file_path); + if (this.filters.severity) params.severity = this.filters.severity; + if (this.filters.status) params.status = this.filters.status; + if (this.filters.rule_id) params.rule_id = this.filters.rule_id; + if (this.filters.file_path) params.file_path = this.filters.file_path; - const response = await fetch(`/api/v1/admin/code-quality/violations?${params.toString()}`, { - headers: { - 'Authorization': `Bearer ${getAccessToken()}` - } - }); + const data = await apiClient.get('/admin/code-quality/violations', params); - if (!response.ok) { - if (response.status === 401) { - window.location.href = '/admin/login'; - return; - } - throw new Error(`HTTP ${response.status}: ${response.statusText}`); - } - - const data = await response.json(); this.violations = data.violations; this.pagination = { page: data.page, @@ -76,6 +70,11 @@ function codeQualityViolations() { } catch (err) { console.error('Failed to load violations:', err); this.error = err.message; + + // Redirect to login if unauthorized + if (err.message.includes('Unauthorized')) { + window.location.href = '/admin/login'; + } } finally { this.loading = false; }