77 lines
2.6 KiB
JavaScript
77 lines
2.6 KiB
JavaScript
// frontend/static/js/workdir_config.js
|
|
|
|
async function editWorkDirConfig() {
|
|
if (!currentGroup?.work_dir) {
|
|
showError('No work directory configured');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// Load current configuration
|
|
const config = await apiRequest(`/workdir-config/${currentGroup.id}`);
|
|
|
|
// Load schema from script group
|
|
const schema = await apiRequest(`/script-groups/${currentGroup.id}/schema`);
|
|
|
|
const content = `
|
|
<form id="workDirConfigForm" class="space-y-4">
|
|
${Object.entries(schema.config_schema).map(([key, field]) => `
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700">
|
|
${field.description || key}
|
|
</label>
|
|
${generateFormField(key, field, config[key])}
|
|
</div>
|
|
`).join('')}
|
|
</form>
|
|
`;
|
|
|
|
const modal = createModal('Edit Work Directory Configuration', content, true);
|
|
modal.querySelector('[onclick="saveModal(this)"]').onclick = () => saveWorkDirConfig(modal);
|
|
} catch (error) {
|
|
showError('Error loading work directory configuration');
|
|
}
|
|
}
|
|
|
|
async function saveWorkDirConfig(modal) {
|
|
if (!currentGroup?.work_dir) return;
|
|
|
|
const form = modal.querySelector('#workDirConfigForm');
|
|
const formData = new FormData(form);
|
|
const config = {};
|
|
|
|
formData.forEach((value, key) => {
|
|
if (value === 'true') value = true;
|
|
else if (value === 'false') value = false;
|
|
else if (!isNaN(value) && value !== '') value = Number(value);
|
|
config[key] = value;
|
|
});
|
|
|
|
try {
|
|
await apiRequest(`/workdir-config/${currentGroup.id}`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify(config)
|
|
});
|
|
|
|
closeModal(modal);
|
|
showSuccess('Work directory configuration updated');
|
|
|
|
// Reload configuration display
|
|
const updatedConfig = await apiRequest(`/workdir-config/${currentGroup.id}`);
|
|
updateWorkDirConfig(updatedConfig);
|
|
} catch (error) {
|
|
showError('Error saving work directory configuration');
|
|
}
|
|
}
|
|
|
|
// Initialize configuration when the page loads
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
if (currentGroup?.work_dir) {
|
|
try {
|
|
const config = await apiRequest(`/workdir-config/${currentGroup.id}`);
|
|
updateWorkDirConfig(config);
|
|
} catch (error) {
|
|
console.error('Error loading initial work directory config:', error);
|
|
}
|
|
}
|
|
}); |