feat: add Admin UI for platform module management (Phase 5)
Added a complete Admin UI for managing platform modules:
API endpoints (app/api/v1/admin/modules.py):
- GET /modules - List all available modules
- GET /modules/platforms/{id} - Get platform modules
- PUT /modules/platforms/{id} - Update enabled modules
- POST /modules/platforms/{id}/enable - Enable a module
- POST /modules/platforms/{id}/disable - Disable a module
- POST /modules/platforms/{id}/enable-all - Enable all
- POST /modules/platforms/{id}/disable-optional - Core only
Admin UI:
- New page route: /admin/platforms/{code}/modules
- Template: platform-modules.html
- JavaScript: platform-modules.js
- Link added to platform-detail.html Super Admin section
Features:
- Toggle modules on/off with dependency resolution
- Enable all / Core only bulk actions
- Visual dependency indicators
- Separate sections for core vs optional modules
- Feature list preview per module
Also includes require_menu_access updates to page routes from Phase 2.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
227
static/admin/js/platform-modules.js
Normal file
227
static/admin/js/platform-modules.js
Normal file
@@ -0,0 +1,227 @@
|
||||
// static/admin/js/platform-modules.js
|
||||
// Platform module configuration management
|
||||
|
||||
const moduleConfigLog = window.LogConfig?.loggers?.moduleConfig || window.LogConfig?.createLogger?.('moduleConfig') || console;
|
||||
|
||||
function adminPlatformModules(platformCode) {
|
||||
// Get base data with safety check for standalone usage
|
||||
const baseData = typeof data === 'function' ? data() : {};
|
||||
|
||||
return {
|
||||
// Inherit base layout functionality from init-alpine.js
|
||||
...baseData,
|
||||
|
||||
// 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() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user