mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-14 02:56:36 +00:00
refactor(web): drop the two dead client-side config-form renderers
generateConfigForm and generateSimpleConfigForm (580 lines) were defined on the Alpine component and never called: server-side Jinja replaced them, as pages_v3.py:641 records. Nothing in any template invokes them -- there is no x-html in the templates and no bracket access on the component. They carried their own x-widget dispatch, which made them an active trap: the next person adding a widget would reasonably think both renderers needed updating. plugins/config_manager.js (PluginConfigManager, 133 lines) goes for the same reason -- loaded on every page from base.html, referenced only by itself and by an archived doc. Kept, having checked them: widgets/example-color-picker.js is the worked example docs/widget-guide.md points plugin authors at, and widgets/plugin-loader.js is the client half of a documented feature (manifest-declared plugin widgets) whose server route is missing -- soccer-scoreboard already ships a widgets/custom-leagues.js that this loader is meant to fetch. That is an unfinished feature to complete, not dead code to delete. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
/**
|
||||
* Plugin configuration form management.
|
||||
*
|
||||
* Handles configuration form generation, validation, and submission.
|
||||
*/
|
||||
|
||||
const PluginConfigManager = {
|
||||
/**
|
||||
* Current plugin configuration state.
|
||||
*/
|
||||
currentState: {
|
||||
pluginId: null,
|
||||
config: null,
|
||||
schema: null,
|
||||
jsonEditor: null
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize configuration for a plugin.
|
||||
*
|
||||
* @param {string} pluginId - Plugin identifier
|
||||
* @returns {Promise<Object>} Configuration and schema
|
||||
*/
|
||||
async initialize(pluginId) {
|
||||
try {
|
||||
const [config, schema] = await Promise.all([
|
||||
window.PluginAPI.getPluginConfig(pluginId),
|
||||
window.PluginAPI.getPluginSchema(pluginId)
|
||||
]);
|
||||
|
||||
this.currentState = {
|
||||
pluginId,
|
||||
config,
|
||||
schema,
|
||||
jsonEditor: null
|
||||
};
|
||||
|
||||
return { config, schema };
|
||||
} catch (error) {
|
||||
if (window.errorHandler) {
|
||||
window.errorHandler.displayError(error, `Failed to initialize config for ${pluginId}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset configuration to defaults.
|
||||
*
|
||||
* @param {string} pluginId - Plugin identifier
|
||||
* @returns {Promise<Object>} Default configuration
|
||||
*/
|
||||
async resetToDefaults(pluginId) {
|
||||
try {
|
||||
const result = await window.PluginAPI.resetPluginConfig(pluginId);
|
||||
|
||||
// Reload configuration
|
||||
if (this.currentState.pluginId === pluginId) {
|
||||
await this.initialize(pluginId);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (window.errorHandler) {
|
||||
window.errorHandler.displayError(error, `Failed to reset config for ${pluginId}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Save configuration.
|
||||
*
|
||||
* @param {string} pluginId - Plugin identifier
|
||||
* @param {Object} config - Configuration data
|
||||
* @returns {Promise<Object>} Save result
|
||||
*/
|
||||
async save(pluginId, config) {
|
||||
try {
|
||||
const result = await window.PluginAPI.savePluginConfig(pluginId, config);
|
||||
|
||||
// Update local state
|
||||
if (this.currentState.pluginId === pluginId) {
|
||||
this.currentState.config = config;
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (window.errorHandler) {
|
||||
window.errorHandler.displayError(error, `Failed to save config for ${pluginId}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Validate configuration against schema.
|
||||
*
|
||||
* @param {Object} config - Configuration data
|
||||
* @param {Object} schema - JSON schema
|
||||
* @returns {Object} Validation result with errors
|
||||
*/
|
||||
validate(config, schema) {
|
||||
// Basic validation - full validation happens on server
|
||||
const errors = [];
|
||||
|
||||
if (!schema || !schema.properties) {
|
||||
return { valid: true, errors: [] };
|
||||
}
|
||||
|
||||
// Check required fields
|
||||
if (schema.required) {
|
||||
for (const field of schema.required) {
|
||||
if (!(field in config)) {
|
||||
errors.push(`Required field '${field}' is missing`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
valid: errors.length === 0,
|
||||
errors: errors
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Export
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = PluginConfigManager;
|
||||
} else {
|
||||
window.PluginConfigManager = PluginConfigManager;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user