This commit completes the migration to a fully module-driven architecture: ## Models Migration - Moved all domain models from models/database/ to their respective modules: - tenancy: User, Admin, Vendor, Company, Platform, VendorDomain, etc. - cms: MediaFile, VendorTheme - messaging: Email, VendorEmailSettings, VendorEmailTemplate - core: AdminMenuConfig - models/database/ now only contains Base and TimestampMixin (infrastructure) ## Schemas Migration - Moved all domain schemas from models/schema/ to their respective modules: - tenancy: company, vendor, admin, team, vendor_domain - cms: media, image, vendor_theme - messaging: email - models/schema/ now only contains base.py and auth.py (infrastructure) ## Routes Migration - Moved admin routes from app/api/v1/admin/ to modules: - menu_config.py -> core module - modules.py -> tenancy module - module_config.py -> tenancy module - app/api/v1/admin/ now only aggregates auto-discovered module routes ## Menu System - Implemented module-driven menu system with MenuDiscoveryService - Extended FrontendType enum: PLATFORM, ADMIN, VENDOR, STOREFRONT - Added MenuItemDefinition and MenuSectionDefinition dataclasses - Each module now defines its own menu items in definition.py - MenuService integrates with MenuDiscoveryService for template rendering ## Documentation - Updated docs/architecture/models-structure.md - Updated docs/architecture/menu-management.md - Updated architecture validation rules for new exceptions ## Architecture Validation - Updated MOD-019 rule to allow base.py in models/schema/ - Created core module exceptions.py and schemas/ directory - All validation errors resolved (only warnings remain) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
150 lines
5.7 KiB
JavaScript
150 lines
5.7 KiB
JavaScript
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
|
// static/admin/js/company-detail.js
|
|
|
|
// Create custom logger for company detail
|
|
const companyDetailLog = window.LogConfig.createLogger('COMPANY-DETAIL');
|
|
|
|
function adminCompanyDetail() {
|
|
return {
|
|
// Inherit base layout functionality from init-alpine.js
|
|
...data(),
|
|
|
|
// Company detail page specific state
|
|
currentPage: 'company-detail',
|
|
company: null,
|
|
loading: false,
|
|
error: null,
|
|
companyId: null,
|
|
|
|
// Initialize
|
|
async init() {
|
|
// Load i18n translations
|
|
await I18n.loadModule('tenancy');
|
|
|
|
companyDetailLog.info('=== COMPANY DETAIL PAGE INITIALIZING ===');
|
|
|
|
// Prevent multiple initializations
|
|
if (window._companyDetailInitialized) {
|
|
companyDetailLog.warn('Company detail page already initialized, skipping...');
|
|
return;
|
|
}
|
|
window._companyDetailInitialized = true;
|
|
|
|
// Get company ID from URL
|
|
const path = window.location.pathname;
|
|
const match = path.match(/\/admin\/companies\/(\d+)$/);
|
|
|
|
if (match) {
|
|
this.companyId = match[1];
|
|
companyDetailLog.info('Viewing company:', this.companyId);
|
|
await this.loadCompany();
|
|
} else {
|
|
companyDetailLog.error('No company ID in URL');
|
|
this.error = 'Invalid company URL';
|
|
Utils.showToast(I18n.t('tenancy.messages.invalid_company_url'), 'error');
|
|
}
|
|
|
|
companyDetailLog.info('=== COMPANY DETAIL PAGE INITIALIZATION COMPLETE ===');
|
|
},
|
|
|
|
// Load company data
|
|
async loadCompany() {
|
|
companyDetailLog.info('Loading company details...');
|
|
this.loading = true;
|
|
this.error = null;
|
|
|
|
try {
|
|
const url = `/admin/companies/${this.companyId}`;
|
|
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 Company Details', duration);
|
|
|
|
this.company = response;
|
|
|
|
companyDetailLog.info(`Company loaded in ${duration}ms`, {
|
|
id: this.company.id,
|
|
name: this.company.name,
|
|
is_verified: this.company.is_verified,
|
|
is_active: this.company.is_active,
|
|
vendor_count: this.company.vendor_count
|
|
});
|
|
companyDetailLog.debug('Full company data:', this.company);
|
|
|
|
} catch (error) {
|
|
window.LogConfig.logError(error, 'Load Company Details');
|
|
this.error = error.message || 'Failed to load company details';
|
|
Utils.showToast(I18n.t('tenancy.messages.failed_to_load_company_details'), 'error');
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
// Format date (matches dashboard pattern)
|
|
formatDate(dateString) {
|
|
if (!dateString) {
|
|
companyDetailLog.debug('formatDate called with empty dateString');
|
|
return '-';
|
|
}
|
|
const formatted = Utils.formatDate(dateString);
|
|
companyDetailLog.debug(`Date formatted: ${dateString} -> ${formatted}`);
|
|
return formatted;
|
|
},
|
|
|
|
// Delete company
|
|
async deleteCompany() {
|
|
companyDetailLog.info('Delete company requested:', this.companyId);
|
|
|
|
if (this.company?.vendor_count > 0) {
|
|
Utils.showToast(`Cannot delete company with ${this.company.vendor_count} vendor(s). Delete vendors first.`, 'error');
|
|
return;
|
|
}
|
|
|
|
if (!confirm(`Are you sure you want to delete company "${this.company.name}"?\n\nThis action cannot be undone.`)) {
|
|
companyDetailLog.info('Delete cancelled by user');
|
|
return;
|
|
}
|
|
|
|
// Second confirmation for safety
|
|
if (!confirm(`FINAL CONFIRMATION\n\nAre you absolutely sure you want to delete "${this.company.name}"?`)) {
|
|
companyDetailLog.info('Delete cancelled by user (second confirmation)');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const url = `/admin/companies/${this.companyId}?confirm=true`;
|
|
window.LogConfig.logApiCall('DELETE', url, null, 'request');
|
|
|
|
companyDetailLog.info('Deleting company:', this.companyId);
|
|
await apiClient.delete(url);
|
|
|
|
window.LogConfig.logApiCall('DELETE', url, null, 'response');
|
|
|
|
Utils.showToast(I18n.t('tenancy.messages.company_deleted_successfully'), 'success');
|
|
companyDetailLog.info('Company deleted successfully');
|
|
|
|
// Redirect to companies list
|
|
setTimeout(() => window.location.href = '/admin/companies', 1500);
|
|
|
|
} catch (error) {
|
|
window.LogConfig.logError(error, 'Delete Company');
|
|
Utils.showToast(error.message || 'Failed to delete company', 'error');
|
|
}
|
|
},
|
|
|
|
// Refresh company data
|
|
async refresh() {
|
|
companyDetailLog.info('=== COMPANY REFRESH TRIGGERED ===');
|
|
await this.loadCompany();
|
|
Utils.showToast(I18n.t('tenancy.messages.company_details_refreshed'), 'success');
|
|
companyDetailLog.info('=== COMPANY REFRESH COMPLETE ===');
|
|
}
|
|
};
|
|
}
|
|
|
|
companyDetailLog.info('Company detail module loaded');
|