summaryrefslogtreecommitdiffstats
path: root/static/config-manager.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--static/config-manager.js180
1 files changed, 94 insertions, 86 deletions
diff --git a/static/config-manager.js b/static/config-manager.js
index edb46b2..eea6c91 100644
--- a/static/config-manager.js
+++ b/static/config-manager.js
@@ -1,102 +1,110 @@
/* jshint esversion: 2024, module: true */
-import { ApiClient } from './api-client.js';
-import { ValidationState } from './enums.js';
+import { ApiClient } from "./api-client.js";
+import { ValidationState } from "./enums.js";
/**
* Static Configuration Manager for handling config files
* @class ConfigManager
*/
class ConfigManager {
- /**
- * Refresh configuration file list
- * @static
- * @returns {Promise<Array>} Array of file names
- */
- static async refreshConfigs() {
- try {
- const data = await ApiClient.getConfigFiles();
- return data.files || [];
- } catch (error) {
- throw new Error(`Failed to list configs: ${error.message}`);
- }
- }
+ /**
+ * Refresh configuration file list
+ * @static
+ * @returns {Promise<Array>} Array of file names
+ */
+ static async refreshConfigs() {
+ try {
+ const data = await ApiClient.getConfigFiles();
+ return data.files || [];
+ } catch (error) {
+ throw new Error(`Failed to list configs: ${error.message}`);
+ }
+ }
- /**
- * Load selected configuration file
- * @static
- * @param {string} name - File name
- * @returns {Promise<string>} File content
- */
- static async loadConfig(name) {
- try {
- return await ApiClient.getConfigFile(name);
- } catch (error) {
- throw new Error(`Failed to load: ${error.message}`);
- }
- }
+ /**
+ * Load selected configuration file
+ * @static
+ * @param {string} name - File name
+ * @returns {Promise<string>} File content
+ */
+ static async loadConfig(name) {
+ try {
+ return await ApiClient.getConfigFile(name);
+ } catch (error) {
+ throw new Error(`Failed to load: ${error.message}`);
+ }
+ }
- /**
- * Validate current configuration
- * @static
- * @param {string} name - File name
- * @param {string} content - File content
- * @returns {Promise<Object>} Validation result
- */
- static async validateConfig(name, content) {
- try {
- return await ApiClient.validateConfig(name, content);
- } catch (error) {
- throw new Error(`Validation failed: ${error.message}`);
- }
- }
+ /**
+ * Validate current configuration
+ * @static
+ * @param {string} name - File name
+ * @param {string} content - File content
+ * @returns {Promise<Object>} Validation result
+ */
+ static async validateConfig(name, content) {
+ try {
+ return await ApiClient.validateConfig(name, content);
+ } catch (error) {
+ throw new Error(`Validation failed: ${error.message}`);
+ }
+ }
- /**
- * Save current configuration
- * @static
- * @param {string} name - File name
- * @param {string} content - File content
- * @param {boolean} restart - Restart service
- * @returns {Promise<Object>} Save result
- */
- static async saveConfig(name, content, restart) {
- try {
- return await ApiClient.saveConfig(name, content, restart);
- } catch (error) {
- throw new Error(`Save failed: ${error.message}`);
- }
- }
+ /**
+ * Save current configuration
+ * @static
+ * @param {string} name - File name
+ * @param {string} content - File content
+ * @param {boolean} restart - Restart service
+ * @returns {Promise<Object>} Save result
+ */
+ static async saveConfig(name, content, restart) {
+ try {
+ return await ApiClient.saveConfig(name, content, restart);
+ } catch (error) {
+ throw new Error(`Save failed: ${error.message}`);
+ }
+ }
- /**
- * Get validation state class
- * @static
- * @param {Symbol} state - Validation state
- * @returns {string} CSS class
- */
- static getValidationClass(state) {
- switch (state) {
- case ValidationState.SUCCESS: return 'validation-success';
- case ValidationState.ERROR: return 'validation-error';
- case ValidationState.PENDING: return 'validation-pending';
- default: return '';
- }
- }
+ /**
+ * Get validation state class
+ * @static
+ * @param {Symbol} state - Validation state
+ * @returns {string} CSS class
+ */
+ static getValidationClass(state) {
+ switch (state) {
+ case ValidationState.SUCCESS:
+ return "validation-success";
+ case ValidationState.ERROR:
+ return "validation-error";
+ case ValidationState.PENDING:
+ return "validation-pending";
+ default:
+ return "";
+ }
+ }
- /**
- * Get validation message
- * @static
- * @param {Symbol} state - Validation state
- * @param {string} [message] - Additional message
- * @returns {string} Validation message
- */
- static getValidationMessage(state, message = '') {
- switch (state) {
- case ValidationState.SUCCESS: return '✓ Configuration is valid';
- case ValidationState.ERROR: return `✗ ${message || 'Validation failed'}`;
- case ValidationState.PENDING: return 'Validating...';
- default: return '';
- }
- }
+ /**
+ * Get validation message
+ * @static
+ * @param {Symbol} state - Validation state
+ * @param {string} [message] - Additional message
+ * @returns {string} Validation message
+ */
+ static getValidationMessage(state, message = "") {
+ switch (state) {
+ case ValidationState.SUCCESS:
+ return "✓ Configuration is valid";
+ case ValidationState.ERROR:
+ return `✗ ${message || "Validation failed"}`;
+ case ValidationState.PENDING:
+ return "Validating...";
+ default:
+ return "";
+ }
+ }
}
export { ConfigManager };