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,8 @@
// static/admin/js/vendor-detail.js
// Log levels: 0 = None, 1 = Error, 2 = Warning, 3 = Info, 4 = Debug
const VENDOR_DETAIL_LOG_LEVEL = 3;
const detailLog = {
error: (...args) => VENDOR_DETAIL_LOG_LEVEL >= 1 && console.error('❌ [VENDOR_DETAIL ERROR]', ...args),
warn: (...args) => VENDOR_DETAIL_LOG_LEVEL >= 2 && console.warn('⚠️ [VENDOR_DETAIL WARN]', ...args),
info: (...args) => VENDOR_DETAIL_LOG_LEVEL >= 3 && console.info(' [VENDOR_DETAIL INFO]', ...args),
debug: (...args) => VENDOR_DETAIL_LOG_LEVEL >= 4 && console.log('🔍 [VENDOR_DETAIL DEBUG]', ...args)
};
// ✅ Use centralized logger - ONE LINE!
// Create custom logger for vendor detail
const detailLog = window.LogConfig.createLogger('VENDOR-DETAIL');
function adminVendorDetail() {
return {
@@ -57,9 +51,15 @@ function adminVendorDetail() {
this.error = null;
try {
const startTime = Date.now();
const response = await apiClient.get(`/admin/vendors/${this.vendorCode}`);
const duration = Date.now() - startTime;
const url = `/admin/vendors/${this.vendorCode}`;
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 Details', duration);
this.vendor = response;
@@ -72,7 +72,7 @@ function adminVendorDetail() {
detailLog.debug('Full vendor data:', this.vendor);
} catch (error) {
detailLog.error('Failed to load vendor:', error);
window.LogConfig.logError(error, 'Load Vendor Details');
this.error = error.message || 'Failed to load vendor details';
Utils.showToast('Failed to load vendor details', 'error');
} finally {
@@ -107,8 +107,13 @@ function adminVendorDetail() {
}
try {
const url = `/admin/vendors/${this.vendorCode}?confirm=true`;
window.LogConfig.logApiCall('DELETE', url, null, 'request');
detailLog.info('Deleting vendor:', this.vendorCode);
await apiClient.delete(`/admin/vendors/${this.vendorCode}?confirm=true`);
await apiClient.delete(url);
window.LogConfig.logApiCall('DELETE', url, null, 'response');
Utils.showToast('Vendor deleted successfully', 'success');
detailLog.info('Vendor deleted successfully');
@@ -117,7 +122,7 @@ function adminVendorDetail() {
setTimeout(() => window.location.href = '/admin/vendors', 1500);
} catch (error) {
detailLog.error('Failed to delete vendor:', error);
window.LogConfig.logError(error, 'Delete Vendor');
Utils.showToast(error.message || 'Failed to delete vendor', 'error');
}
},