migrating vendor frontend to new architecture
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
// static/admin/js/dashboard.js
|
||||
|
||||
// Log levels: 0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug
|
||||
const DASHBOARD_LOG_LEVEL = 3; // Set to 3 for production, 4 for full debugging
|
||||
|
||||
const dashLog = {
|
||||
error: (...args) => DASHBOARD_LOG_LEVEL >= 1 && console.error('❌ [DASHBOARD ERROR]', ...args),
|
||||
warn: (...args) => DASHBOARD_LOG_LEVEL >= 2 && console.warn('⚠️ [DASHBOARD WARN]', ...args),
|
||||
info: (...args) => DASHBOARD_LOG_LEVEL >= 3 && console.info('ℹ️ [DASHBOARD INFO]', ...args),
|
||||
debug: (...args) => DASHBOARD_LOG_LEVEL >= 4 && console.log('🔍 [DASHBOARD DEBUG]', ...args)
|
||||
};
|
||||
// ✅ Use centralized logger - ONE LINE!
|
||||
const dashLog = window.LogConfig.loggers.dashboard;
|
||||
|
||||
function adminDashboard() {
|
||||
return {
|
||||
@@ -49,7 +42,11 @@ function adminDashboard() {
|
||||
window._dashboardInitialized = true;
|
||||
dashLog.debug('Dashboard initialization flag set');
|
||||
|
||||
const startTime = performance.now();
|
||||
await this.loadDashboard();
|
||||
const duration = performance.now() - startTime;
|
||||
|
||||
window.LogConfig.logPerformance('Dashboard Init', duration);
|
||||
dashLog.info('=== DASHBOARD INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
@@ -63,8 +60,8 @@ function adminDashboard() {
|
||||
dashLog.debug('Dashboard state: loading=true, error=null');
|
||||
|
||||
try {
|
||||
dashLog.info('Starting parallel data fetch...');
|
||||
const startTime = Date.now();
|
||||
dashLog.group('Loading dashboard data');
|
||||
const startTime = performance.now();
|
||||
|
||||
// Load stats and vendors in parallel
|
||||
await Promise.all([
|
||||
@@ -72,17 +69,14 @@ function adminDashboard() {
|
||||
this.loadRecentVendors()
|
||||
]);
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
const duration = performance.now() - startTime;
|
||||
dashLog.groupEnd();
|
||||
|
||||
window.LogConfig.logPerformance('Load Dashboard Data', duration);
|
||||
dashLog.info(`Dashboard data loaded successfully in ${duration}ms`);
|
||||
|
||||
} catch (error) {
|
||||
dashLog.error('Dashboard load error:', error);
|
||||
dashLog.error('Error details:', {
|
||||
message: error.message,
|
||||
name: error.name,
|
||||
stack: error.stack
|
||||
});
|
||||
|
||||
window.LogConfig.logError(error, 'Dashboard Load');
|
||||
this.error = error.message;
|
||||
Utils.showToast('Failed to load dashboard data', 'error');
|
||||
|
||||
@@ -98,15 +92,17 @@ function adminDashboard() {
|
||||
*/
|
||||
async loadStats() {
|
||||
dashLog.info('Loading platform statistics...');
|
||||
dashLog.debug('API endpoint: /admin/dashboard/stats/platform');
|
||||
const url = '/admin/dashboard/stats/platform';
|
||||
|
||||
window.LogConfig.logApiCall('GET', url, null, 'request');
|
||||
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
const data = await apiClient.get('/admin/dashboard/stats/platform');
|
||||
const duration = Date.now() - startTime;
|
||||
const startTime = performance.now();
|
||||
const data = await apiClient.get(url);
|
||||
const duration = performance.now() - startTime;
|
||||
|
||||
dashLog.info(`Stats loaded in ${duration}ms`);
|
||||
dashLog.debug('Raw stats data:', data);
|
||||
window.LogConfig.logApiCall('GET', url, data, 'response');
|
||||
window.LogConfig.logPerformance('Load Stats', duration);
|
||||
|
||||
// Map API response to stats cards
|
||||
this.stats = {
|
||||
@@ -129,18 +125,17 @@ function adminDashboard() {
|
||||
*/
|
||||
async loadRecentVendors() {
|
||||
dashLog.info('Loading recent vendors...');
|
||||
dashLog.debug('API endpoint: /admin/dashboard');
|
||||
const url = '/admin/dashboard';
|
||||
|
||||
window.LogConfig.logApiCall('GET', url, null, 'request');
|
||||
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
const data = await apiClient.get('/admin/dashboard');
|
||||
const duration = Date.now() - startTime;
|
||||
const startTime = performance.now();
|
||||
const data = await apiClient.get(url);
|
||||
const duration = performance.now() - startTime;
|
||||
|
||||
dashLog.info(`Recent vendors loaded in ${duration}ms`);
|
||||
dashLog.debug('Vendors data:', {
|
||||
count: data.recent_vendors?.length || 0,
|
||||
hasData: !!data.recent_vendors
|
||||
});
|
||||
window.LogConfig.logApiCall('GET', url, data, 'response');
|
||||
window.LogConfig.logPerformance('Load Recent Vendors', duration);
|
||||
|
||||
this.recentVendors = data.recent_vendors || [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user