Phase 1 - Vendor Router Integration: - Wire up vendor module routers in app/api/v1/vendor/__init__.py - Use lazy imports via __getattr__ to avoid circular dependencies Phase 2 - Extract Remaining Modules: - Create 6 new module directories: customers, cms, analytics, messaging, dev_tools, monitoring - Each module has definition.py and route wrappers - Update registry to import from extracted modules Phase 3 - Database Table Migration: - Add PlatformModule junction table for auditable module tracking - Add migration zc2m3n4o5p6q7_add_platform_modules_table.py - Add modules relationship to Platform model - Update ModuleService with JSON-to-junction-table migration Phase 4 - Module-Specific Configuration UI: - Add /api/v1/admin/module-config/* endpoints - Add module-config.html template and JS Phase 5 - Integration Tests: - Add tests/fixtures/module_fixtures.py - Add tests/integration/api/v1/admin/test_modules.py - Add tests/integration/api/v1/modules/test_module_access.py Architecture fixes: - Fix JS-003 errors: use ...data() directly in Alpine components - Fix JS-005 warnings: add init() guards to prevent duplicate init - Fix API-001 errors: add MenuActionResponse Pydantic model - Add FE-008 noqa for dynamic number input in template Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
232 lines
8.1 KiB
JavaScript
232 lines
8.1 KiB
JavaScript
// static/admin/js/platform-modules.js
|
|
// Platform module configuration management
|
|
|
|
const moduleConfigLog = window.LogConfig?.loggers?.moduleConfig || window.LogConfig?.createLogger?.('moduleConfig') || console;
|
|
|
|
function adminPlatformModules(platformCode) {
|
|
return {
|
|
// Inherit base layout functionality from init-alpine.js
|
|
...data(),
|
|
|
|
// Page-specific state
|
|
currentPage: 'platforms',
|
|
platformCode: platformCode,
|
|
loading: true,
|
|
error: null,
|
|
successMessage: null,
|
|
saving: false,
|
|
|
|
// Data
|
|
platform: null,
|
|
moduleConfig: null,
|
|
|
|
// Computed properties
|
|
get coreModules() {
|
|
if (!this.moduleConfig?.modules) return [];
|
|
return this.moduleConfig.modules.filter(m => m.is_core);
|
|
},
|
|
|
|
get optionalModules() {
|
|
if (!this.moduleConfig?.modules) return [];
|
|
return this.moduleConfig.modules.filter(m => !m.is_core);
|
|
},
|
|
|
|
get coreModulesCount() {
|
|
return this.coreModules.length;
|
|
},
|
|
|
|
get enabledOptionalCount() {
|
|
return this.optionalModules.filter(m => m.is_enabled).length;
|
|
},
|
|
|
|
// Module icons mapping
|
|
getModuleIcon(moduleCode) {
|
|
const icons = {
|
|
'core': 'home',
|
|
'platform-admin': 'building-office',
|
|
'billing': 'credit-card',
|
|
'inventory': 'archive-box',
|
|
'orders': 'shopping-cart',
|
|
'marketplace': 'shopping-bag',
|
|
'customers': 'users',
|
|
'cms': 'document-text',
|
|
'analytics': 'chart-bar',
|
|
'messaging': 'chat-bubble-left-right',
|
|
'dev-tools': 'code-bracket',
|
|
'monitoring': 'chart-bar-square'
|
|
};
|
|
return icons[moduleCode] || 'puzzle';
|
|
},
|
|
|
|
async init() {
|
|
// Guard against duplicate initialization
|
|
if (window._platformModulesInitialized) {
|
|
moduleConfigLog.warn('Already initialized, skipping');
|
|
return;
|
|
}
|
|
window._platformModulesInitialized = true;
|
|
|
|
moduleConfigLog.info('=== PLATFORM MODULES PAGE INITIALIZING ===');
|
|
moduleConfigLog.info('Platform code:', this.platformCode);
|
|
|
|
try {
|
|
await this.loadPlatform();
|
|
await this.loadModuleConfig();
|
|
moduleConfigLog.info('=== PLATFORM MODULES PAGE INITIALIZED ===');
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to initialize modules page:', error);
|
|
this.error = 'Failed to load page data. Please refresh.';
|
|
}
|
|
},
|
|
|
|
async refresh() {
|
|
this.error = null;
|
|
this.successMessage = null;
|
|
await this.loadModuleConfig();
|
|
},
|
|
|
|
async loadPlatform() {
|
|
try {
|
|
this.platform = await apiClient.get(`/admin/platforms/${this.platformCode}`);
|
|
moduleConfigLog.info('Loaded platform:', this.platform?.name);
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to load platform:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
async loadModuleConfig() {
|
|
this.loading = true;
|
|
this.error = null;
|
|
|
|
try {
|
|
const platformId = this.platform?.id;
|
|
if (!platformId) {
|
|
throw new Error('Platform not loaded');
|
|
}
|
|
|
|
this.moduleConfig = await apiClient.get(`/admin/modules/platforms/${platformId}`);
|
|
moduleConfigLog.info('Loaded module config:', {
|
|
total: this.moduleConfig?.total,
|
|
enabled: this.moduleConfig?.enabled,
|
|
disabled: this.moduleConfig?.disabled
|
|
});
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to load module config:', error);
|
|
this.error = error.message || 'Failed to load module configuration';
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
async toggleModule(module) {
|
|
if (module.is_core) {
|
|
moduleConfigLog.warn('Cannot toggle core module:', module.code);
|
|
return;
|
|
}
|
|
|
|
this.saving = true;
|
|
this.error = null;
|
|
this.successMessage = null;
|
|
|
|
const action = module.is_enabled ? 'disable' : 'enable';
|
|
|
|
try {
|
|
const platformId = this.platform?.id;
|
|
const endpoint = `/admin/modules/platforms/${platformId}/${action}`;
|
|
|
|
const result = await apiClient.post(endpoint, {
|
|
module_code: module.code
|
|
});
|
|
|
|
moduleConfigLog.info(`${action}d module:`, module.code, result);
|
|
|
|
// Show success message
|
|
if (result.also_enabled?.length > 0) {
|
|
this.successMessage = `Module '${module.name}' enabled. Also enabled dependencies: ${result.also_enabled.join(', ')}`;
|
|
} else if (result.also_disabled?.length > 0) {
|
|
this.successMessage = `Module '${module.name}' disabled. Also disabled dependents: ${result.also_disabled.join(', ')}`;
|
|
} else {
|
|
this.successMessage = `Module '${module.name}' ${action}d successfully`;
|
|
}
|
|
|
|
// Reload module config to get updated state
|
|
await this.loadModuleConfig();
|
|
|
|
// Clear success message after delay
|
|
setTimeout(() => {
|
|
this.successMessage = null;
|
|
}, 5000);
|
|
|
|
} catch (error) {
|
|
moduleConfigLog.error(`Failed to ${action} module:`, error);
|
|
this.error = error.message || `Failed to ${action} module`;
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
},
|
|
|
|
async enableAll() {
|
|
if (!confirm('This will enable all modules. Continue?')) {
|
|
return;
|
|
}
|
|
|
|
this.saving = true;
|
|
this.error = null;
|
|
this.successMessage = null;
|
|
|
|
try {
|
|
const platformId = this.platform?.id;
|
|
const result = await apiClient.post(`/admin/modules/platforms/${platformId}/enable-all`);
|
|
|
|
moduleConfigLog.info('Enabled all modules:', result);
|
|
this.successMessage = `All ${result.enabled_count} modules enabled`;
|
|
|
|
// Reload module config
|
|
await this.loadModuleConfig();
|
|
|
|
setTimeout(() => {
|
|
this.successMessage = null;
|
|
}, 5000);
|
|
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to enable all modules:', error);
|
|
this.error = error.message || 'Failed to enable all modules';
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
},
|
|
|
|
async disableOptional() {
|
|
if (!confirm('This will disable all optional modules, keeping only core modules. Continue?')) {
|
|
return;
|
|
}
|
|
|
|
this.saving = true;
|
|
this.error = null;
|
|
this.successMessage = null;
|
|
|
|
try {
|
|
const platformId = this.platform?.id;
|
|
const result = await apiClient.post(`/admin/modules/platforms/${platformId}/disable-optional`);
|
|
|
|
moduleConfigLog.info('Disabled optional modules:', result);
|
|
this.successMessage = `Optional modules disabled. Core modules kept: ${result.core_modules.join(', ')}`;
|
|
|
|
// Reload module config
|
|
await this.loadModuleConfig();
|
|
|
|
setTimeout(() => {
|
|
this.successMessage = null;
|
|
}, 5000);
|
|
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to disable optional modules:', error);
|
|
this.error = error.message || 'Failed to disable optional modules';
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
}
|
|
};
|
|
}
|