Files
orion/static/admin/js/platform-health.js
Samir Boulahtit 265c71f597 fix: resolve all JS architecture violations (JS-005 through JS-009)
Fixed 89 violations across vendor, admin, and shared JavaScript files:

JS-008 (raw fetch → apiClient):
- Added postFormData() and getBlob() methods to api-client.js
- Updated inventory.js, messages.js to use apiClient.postFormData()
- Added noqa for file downloads that need response headers

JS-009 (window.showToast → Utils.showToast):
- Updated admin/messages.js, notifications.js, vendor/messages.js
- Replaced alert() in customers.js

JS-006 (async error handling):
- Added try/catch to all async init() and reload() methods
- Fixed vendor: billing, dashboard, login, messages, onboarding
- Fixed shared: feature-store, upgrade-prompts
- Fixed admin: all page components

JS-005 (init guards):
- Added initialization guards to prevent duplicate init() calls
- Pattern: if (window._componentInitialized) return;

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 21:32:19 +01:00

130 lines
3.6 KiB
JavaScript

// noqa: js-006 - async init pattern is safe, loadData has try/catch
// static/admin/js/platform-health.js
/**
* Admin platform health monitoring page logic
* Displays system metrics, capacity thresholds, and scaling recommendations
*/
const adminPlatformHealthLog = window.LogConfig.loggers.adminPlatformHealth ||
window.LogConfig.createLogger('adminPlatformHealth', false);
adminPlatformHealthLog.info('Loading...');
function adminPlatformHealth() {
adminPlatformHealthLog.info('adminPlatformHealth() called');
return {
// Inherit base layout state
...data(),
// Set page identifier
currentPage: 'platform-health',
// Loading states
loading: true,
error: '',
// Health data
health: null,
// Auto-refresh interval (30 seconds)
refreshInterval: null,
async init() {
adminPlatformHealthLog.info('Platform Health init() called');
// Guard against multiple initialization
if (window._adminPlatformHealthInitialized) {
adminPlatformHealthLog.warn('Already initialized, skipping');
return;
}
window._adminPlatformHealthInitialized = true;
// Load initial data
await this.loadHealth();
// Set up auto-refresh every 30 seconds
this.refreshInterval = setInterval(() => {
this.loadHealth();
}, 30000);
adminPlatformHealthLog.info('Platform Health initialization complete');
},
/**
* Clean up on component destroy
*/
destroy() {
if (this.refreshInterval) {
clearInterval(this.refreshInterval);
this.refreshInterval = null;
}
},
/**
* Load platform health data
*/
async loadHealth() {
this.loading = true;
this.error = '';
try {
const response = await apiClient.get('/admin/platform/health');
this.health = response;
adminPlatformHealthLog.info('Loaded health data:', {
status: response.overall_status,
tier: response.infrastructure_tier
});
} catch (error) {
adminPlatformHealthLog.error('Failed to load health:', error);
this.error = error.message || 'Failed to load platform health';
} finally {
this.loading = false;
}
},
/**
* Manual refresh
*/
async refresh() {
await this.loadHealth();
},
/**
* Format number with locale
*/
formatNumber(num) {
if (num === null || num === undefined) return '0';
if (typeof num === 'number' && num % 1 !== 0) {
return num.toFixed(2);
}
return new Intl.NumberFormat('en-US').format(num);
},
/**
* Format storage size
*/
formatStorage(gb) {
if (gb === null || gb === undefined) return '0 GB';
if (gb < 1) {
return (gb * 1024).toFixed(0) + ' MB';
}
return gb.toFixed(2) + ' GB';
},
/**
* Format timestamp
*/
formatTime(timestamp) {
if (!timestamp) return 'Unknown';
try {
const date = new Date(timestamp);
return date.toLocaleTimeString();
} catch (e) {
return 'Unknown';
}
}
};
}