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>
150 lines
5.2 KiB
JavaScript
150 lines
5.2 KiB
JavaScript
// static/admin/js/module-config.js
|
|
// Module configuration management for platform modules
|
|
|
|
const moduleConfigLog = window.LogConfig?.loggers?.moduleConfig || window.LogConfig?.createLogger?.('moduleConfig') || console;
|
|
|
|
function adminModuleConfig(platformCode, moduleCode) {
|
|
return {
|
|
// Inherit base layout functionality from init-alpine.js
|
|
...data(),
|
|
|
|
// Page-specific state
|
|
currentPage: 'platforms',
|
|
platformCode: platformCode,
|
|
moduleCode: moduleCode,
|
|
loading: true,
|
|
error: null,
|
|
successMessage: null,
|
|
saving: false,
|
|
|
|
// Data
|
|
platformId: null,
|
|
platformName: '',
|
|
moduleInfo: null,
|
|
config: {},
|
|
|
|
async init() {
|
|
// Guard against duplicate initialization
|
|
if (window._moduleConfigInitialized) {
|
|
moduleConfigLog.warn('Already initialized, skipping');
|
|
return;
|
|
}
|
|
window._moduleConfigInitialized = true;
|
|
|
|
moduleConfigLog.info('=== MODULE CONFIG PAGE INITIALIZING ===');
|
|
moduleConfigLog.info('Platform code:', this.platformCode);
|
|
moduleConfigLog.info('Module code:', this.moduleCode);
|
|
|
|
try {
|
|
await this.loadPlatform();
|
|
await this.loadModuleConfig();
|
|
moduleConfigLog.info('=== MODULE CONFIG PAGE INITIALIZED ===');
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to initialize module config 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 {
|
|
const platform = await apiClient.get(`/admin/platforms/${this.platformCode}`);
|
|
this.platformId = platform.id;
|
|
this.platformName = platform.name;
|
|
moduleConfigLog.info('Loaded platform:', platform.name);
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to load platform:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
async loadModuleConfig() {
|
|
this.loading = true;
|
|
this.error = null;
|
|
|
|
try {
|
|
if (!this.platformId) {
|
|
throw new Error('Platform not loaded');
|
|
}
|
|
|
|
this.moduleInfo = await apiClient.get(
|
|
`/admin/module-config/platforms/${this.platformId}/modules/${this.moduleCode}/config`
|
|
);
|
|
|
|
// Initialize config with current values
|
|
this.config = { ...this.moduleInfo.config };
|
|
|
|
moduleConfigLog.info('Loaded module config:', {
|
|
moduleCode: this.moduleCode,
|
|
config: this.config
|
|
});
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to load module config:', error);
|
|
this.error = error.message || 'Failed to load module configuration';
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
async saveConfig() {
|
|
this.saving = true;
|
|
this.error = null;
|
|
this.successMessage = null;
|
|
|
|
try {
|
|
const response = await apiClient.put(
|
|
`/admin/module-config/platforms/${this.platformId}/modules/${this.moduleCode}/config`,
|
|
{ config: this.config }
|
|
);
|
|
|
|
// Update local state with response
|
|
this.moduleInfo = response;
|
|
this.config = { ...response.config };
|
|
|
|
this.successMessage = 'Configuration saved successfully';
|
|
moduleConfigLog.info('Saved module config:', this.config);
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to save module config:', error);
|
|
this.error = error.message || 'Failed to save configuration';
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
},
|
|
|
|
async resetToDefaults() {
|
|
if (!confirm('This will reset all configuration options to their default values. Continue?')) {
|
|
return;
|
|
}
|
|
|
|
this.saving = true;
|
|
this.error = null;
|
|
this.successMessage = null;
|
|
|
|
try {
|
|
const response = await apiClient.post(
|
|
`/admin/module-config/platforms/${this.platformId}/modules/${this.moduleCode}/reset`
|
|
);
|
|
|
|
// Update local state with defaults
|
|
this.config = { ...response.config };
|
|
|
|
// Reload full config to get schema_info
|
|
await this.loadModuleConfig();
|
|
|
|
this.successMessage = 'Configuration reset to defaults';
|
|
moduleConfigLog.info('Reset module config to defaults');
|
|
} catch (error) {
|
|
moduleConfigLog.error('Failed to reset module config:', error);
|
|
this.error = error.message || 'Failed to reset configuration';
|
|
} finally {
|
|
this.saving = false;
|
|
}
|
|
}
|
|
};
|
|
}
|