adding developer tools in admin panel, adding vendor management

This commit is contained in:
2025-10-25 18:07:02 +02:00
parent 7bb69a9a96
commit 49890d4cbe
19 changed files with 3456 additions and 226 deletions

View File

@@ -0,0 +1,135 @@
// 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)
};
function adminVendorDetail() {
return {
// Inherit base layout functionality from init-alpine.js
...data(),
// Vendor detail page specific state
currentPage: 'vendor-detail',
vendor: null,
loading: false,
error: null,
vendorCode: null,
// Initialize
async init() {
detailLog.info('=== VENDOR DETAIL PAGE INITIALIZING ===');
// Prevent multiple initializations
if (window._vendorDetailInitialized) {
detailLog.warn('Vendor detail page already initialized, skipping...');
return;
}
window._vendorDetailInitialized = true;
// Get vendor code from URL
const path = window.location.pathname;
const match = path.match(/\/admin\/vendors\/([^\/]+)$/);
if (match) {
this.vendorCode = match[1];
detailLog.info('Viewing vendor:', this.vendorCode);
await this.loadVendor();
} else {
detailLog.error('No vendor code in URL');
this.error = 'Invalid vendor URL';
Utils.showToast('Invalid vendor URL', 'error');
}
detailLog.info('=== VENDOR DETAIL PAGE INITIALIZATION COMPLETE ===');
},
// Load vendor data
async loadVendor() {
detailLog.info('Loading vendor details...');
this.loading = true;
this.error = null;
try {
const startTime = Date.now();
const response = await apiClient.get(`/admin/vendors/${this.vendorCode}`);
const duration = Date.now() - startTime;
this.vendor = response;
detailLog.info(`Vendor loaded in ${duration}ms`, {
vendor_code: this.vendor.vendor_code,
name: this.vendor.name,
is_verified: this.vendor.is_verified,
is_active: this.vendor.is_active
});
detailLog.debug('Full vendor data:', this.vendor);
} catch (error) {
detailLog.error('Failed to load vendor:', error);
this.error = error.message || 'Failed to load vendor details';
Utils.showToast('Failed to load vendor details', 'error');
} finally {
this.loading = false;
}
},
// Format date (matches dashboard pattern)
formatDate(dateString) {
if (!dateString) {
detailLog.debug('formatDate called with empty dateString');
return '-';
}
const formatted = Utils.formatDate(dateString);
detailLog.debug(`Date formatted: ${dateString} -> ${formatted}`);
return formatted;
},
// Delete vendor
async deleteVendor() {
detailLog.info('Delete vendor requested:', this.vendorCode);
if (!confirm(`Are you sure you want to delete vendor "${this.vendor.name}"?\n\nThis action cannot be undone and will delete:\n- All products\n- All orders\n- All customers\n- All team members`)) {
detailLog.info('Delete cancelled by user');
return;
}
// Second confirmation for safety
if (!confirm(`FINAL CONFIRMATION\n\nType the vendor code to confirm: ${this.vendor.vendor_code}\n\nAre you absolutely sure?`)) {
detailLog.info('Delete cancelled by user (second confirmation)');
return;
}
try {
detailLog.info('Deleting vendor:', this.vendorCode);
await apiClient.delete(`/admin/vendors/${this.vendorCode}?confirm=true`);
Utils.showToast('Vendor deleted successfully', 'success');
detailLog.info('Vendor deleted successfully');
// Redirect to vendors list
setTimeout(() => window.location.href = '/admin/vendors', 1500);
} catch (error) {
detailLog.error('Failed to delete vendor:', error);
Utils.showToast(error.message || 'Failed to delete vendor', 'error');
}
},
// Refresh vendor data
async refresh() {
detailLog.info('=== VENDOR REFRESH TRIGGERED ===');
await this.loadVendor();
Utils.showToast('Vendor details refreshed', 'success');
detailLog.info('=== VENDOR REFRESH COMPLETE ===');
}
};
}
detailLog.info('Vendor detail module loaded');