summaryrefslogtreecommitdiffstats
path: root/static/config-manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/config-manager.js')
-rw-r--r--static/config-manager.js50
1 files changed, 11 insertions, 39 deletions
diff --git a/static/config-manager.js b/static/config-manager.js
index 8dc629b..ebaf9f2 100644
--- a/static/config-manager.js
+++ b/static/config-manager.js
@@ -17,34 +17,25 @@ class ConfigManager {
}
/**
- * Set up configuration event listeners
- * @method setupEventListeners
- */
- setupEventListeners() {
- this.elements.buttons.refreshConfigs?.addEventListener('click', () => this.refreshConfigs());
- this.elements.buttons.saveConfig?.addEventListener('click', () => this.saveConfig());
- this.elements.buttons.validateConfig?.addEventListener('click', () => this.validateConfig());
- this.elements.inputs.configSelect?.addEventListener('change', () => this.loadConfig());
- }
-
- /**
* Refresh configuration file list
* @method refreshConfigs
*/
async refreshConfigs() {
try {
const data = await this.apiClient.get('/api/configs');
-
+
this.elements.inputs.configSelect.innerHTML = '';
data.files?.forEach(file => {
const option = new Option(file, file);
this.elements.inputs.configSelect.add(option);
});
-
+
if (data.files?.length > 0) {
+ this.state.currentConfigFile = data.files[0];
await this.loadConfig();
} else {
this.elements.inputs.cfgEditor.value = '';
+ this.state.currentConfigFile = null;
}
} catch (error) {
alert(`Failed to list configs: ${error.message}`);
@@ -58,7 +49,9 @@ class ConfigManager {
async loadConfig() {
const name = this.elements.inputs.configSelect.value;
if (!name) return;
-
+
+ this.state.currentConfigFile = name;
+
try {
const text = await this.apiClient.getText(`/api/config/${encodeURIComponent(name)}`);
this.elements.inputs.cfgEditor.value = text;
@@ -75,13 +68,13 @@ class ConfigManager {
async validateConfig() {
const name = this.elements.inputs.configSelect.value;
const content = this.elements.inputs.cfgEditor.value;
-
+
this.elements.outputs.validateResult.textContent = 'Validating...';
this.elements.outputs.validateResult.className = 'validation-pending';
-
+
try {
const result = await this.apiClient.post('/api/validate', { name, content });
-
+
if (result.ok) {
this.elements.outputs.validateResult.textContent = '✓ Configuration is valid';
this.elements.outputs.validateResult.className = 'validation-success';
@@ -94,27 +87,6 @@ class ConfigManager {
this.elements.outputs.validateResult.className = 'validation-error';
}
}
-
- /**
- * Save current configuration
- * @method saveConfig
- */
- async saveConfig() {
- const name = this.elements.inputs.configSelect.value;
- const content = this.elements.inputs.cfgEditor.value;
- const restart = this.elements.inputs.restartAfterSave.checked;
-
- if (!confirm(`Save file ${name}? This will create a backup and ${restart ? 'restart' : 'not restart'} networkd.`)) {
- return;
- }
-
- try {
- const result = await this.apiClient.post('/api/save', { name, content, restart });
- alert(`Saved: ${result.status ?? 'ok'}`);
- } catch (error) {
- alert(`Save failed: ${error.message}`);
- }
- }
}
-export { ConfigManager };
+export { ConfigManager }; \ No newline at end of file