migrating vendor frontend to new architecture

This commit is contained in:
2025-10-28 22:58:55 +01:00
parent b0cc0385f8
commit cd5097fc04
28 changed files with 312 additions and 228 deletions

View File

@@ -1,14 +1,7 @@
// static/admin/js/vendors.js
// Log levels: 0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug
const VENDORS_LOG_LEVEL = 3;
const vendorsLog = {
error: (...args) => VENDORS_LOG_LEVEL >= 1 && console.error('❌ [VENDORS ERROR]', ...args),
warn: (...args) => VENDORS_LOG_LEVEL >= 2 && console.warn('⚠️ [VENDORS WARN]', ...args),
info: (...args) => VENDORS_LOG_LEVEL >= 3 && console.info(' [VENDORS INFO]', ...args),
debug: (...args) => VENDORS_LOG_LEVEL >= 4 && console.log('🔍 [VENDORS DEBUG]', ...args)
};
// ✅ Use centralized logger - ONE LINE!
const vendorsLog = window.LogConfig.loggers.vendors;
// ============================================
// VENDOR LIST FUNCTION
@@ -47,8 +40,10 @@ function adminVendors() {
}
window._vendorsInitialized = true;
vendorsLog.group('Loading vendors data');
await this.loadVendors();
await this.loadStats();
vendorsLog.groupEnd();
vendorsLog.info('=== VENDORS PAGE INITIALIZATION COMPLETE ===');
},
@@ -122,9 +117,15 @@ function adminVendors() {
this.error = null;
try {
const startTime = Date.now();
const response = await apiClient.get('/admin/vendors');
const duration = Date.now() - startTime;
const url = '/admin/vendors';
window.LogConfig.logApiCall('GET', url, null, 'request');
const startTime = performance.now();
const response = await apiClient.get(url);
const duration = performance.now() - startTime;
window.LogConfig.logApiCall('GET', url, response, 'response');
window.LogConfig.logPerformance('Load Vendors', duration);
// Handle different response structures
this.vendors = response.vendors || response.items || response || [];
@@ -142,7 +143,7 @@ function adminVendors() {
this.page = 1;
} catch (error) {
vendorsLog.error('Failed to load vendors:', error);
window.LogConfig.logError(error, 'Load Vendors');
this.error = error.message || 'Failed to load vendors';
Utils.showToast('Failed to load vendors', 'error');
} finally {
@@ -155,15 +156,21 @@ function adminVendors() {
vendorsLog.info('Loading vendor statistics...');
try {
const startTime = Date.now();
const response = await apiClient.get('/admin/vendors/stats');
const duration = Date.now() - startTime;
const url = '/admin/vendors/stats';
window.LogConfig.logApiCall('GET', url, null, 'request');
const startTime = performance.now();
const response = await apiClient.get(url);
const duration = performance.now() - startTime;
window.LogConfig.logApiCall('GET', url, response, 'response');
window.LogConfig.logPerformance('Load Vendor Stats', duration);
this.stats = response;
vendorsLog.info(`Stats loaded in ${duration}ms`, this.stats);
} catch (error) {
vendorsLog.error('Failed to load stats:', error);
window.LogConfig.logError(error, 'Load Vendor Stats');
// Don't show error toast for stats, just log it
}
},
@@ -230,8 +237,13 @@ function adminVendors() {
}
try {
const url = `/admin/vendors/${vendor.vendor_code}`;
window.LogConfig.logApiCall('DELETE', url, null, 'request');
vendorsLog.info('Deleting vendor:', vendor.vendor_code);
await apiClient.delete(`/admin/vendors/${vendor.vendor_code}`);
await apiClient.delete(url);
window.LogConfig.logApiCall('DELETE', url, null, 'response');
Utils.showToast('Vendor deleted successfully', 'success');
vendorsLog.info('Vendor deleted successfully');
@@ -241,7 +253,7 @@ function adminVendors() {
await this.loadStats();
} catch (error) {
vendorsLog.error('Failed to delete vendor:', error);
window.LogConfig.logError(error, 'Delete Vendor');
Utils.showToast(error.message || 'Failed to delete vendor', 'error');
}
},
@@ -249,8 +261,12 @@ function adminVendors() {
// Refresh vendors list
async refresh() {
vendorsLog.info('=== VENDORS REFRESH TRIGGERED ===');
vendorsLog.group('Refreshing vendors data');
await this.loadVendors();
await this.loadStats();
vendorsLog.groupEnd();
Utils.showToast('Vendors list refreshed', 'success');
vendorsLog.info('=== VENDORS REFRESH COMPLETE ===');
}