feat: add save functionality to Powercode config with validation

This commit is contained in:
Herbert Wolverson (aider)
2025-01-22 14:42:01 -06:00
parent 9206aaa618
commit fe3ebbbf61
2 changed files with 45 additions and 2 deletions

View File

@@ -1,4 +1,37 @@
import {loadConfig} from "./config/config_helper";
import {saveConfig, loadConfig} from "./config/config_helper";
function validateConfig() {
// Validate required fields when enabled
if (document.getElementById("enablePowercode").checked) {
const apiKey = document.getElementById("powercodeApiKey").value.trim();
if (!apiKey) {
alert("API Key is required when Powercode integration is enabled");
return false;
}
const apiUrl = document.getElementById("powercodeApiUrl").value.trim();
if (!apiUrl) {
alert("API URL is required when Powercode integration is enabled");
return false;
}
try {
new URL(apiUrl);
} catch {
alert("API URL must be a valid URL");
return false;
}
}
return true;
}
function updateConfig() {
// Update only the powercode_integration section
window.config.powercode_integration = {
enable_powercode: document.getElementById("enablePowercode").checked,
powercode_api_key: document.getElementById("powercodeApiKey").value.trim(),
powercode_api_url: document.getElementById("powercodeApiUrl").value.trim()
};
}
loadConfig(() => {
// window.config now contains the configuration.
@@ -15,6 +48,16 @@ loadConfig(() => {
powercode.powercode_api_key ?? "";
document.getElementById("powercodeApiUrl").value =
powercode.powercode_api_url ?? "";
// Add save button click handler
document.getElementById('saveButton').addEventListener('click', () => {
if (validateConfig()) {
updateConfig();
saveConfig(() => {
alert("Configuration saved successfully!");
});
}
});
} else {
console.error("Powercode integration configuration not found in window.config");
}

View File

@@ -42,7 +42,7 @@
<div class="form-text">Base URL for Powercode API (e.g. https://your-powercode.com)</div>
</div>
<button type="submit" class="btn btn-outline-primary">Save Changes</button>
<button type="button" id="saveButton" class="btn btn-outline-primary">Save Changes</button>
</form>
</div>
</div>