Add ability to rename http functions

This commit is contained in:
Peter Stockings
2024-01-03 16:37:36 +11:00
parent 6e172f568f
commit 2d9c0b9d53
3 changed files with 21 additions and 9 deletions

View File

@@ -2,11 +2,9 @@
<div class="flex space-x-2 p-2 border-b border-gray-200 dark:border-gray-800">
<h1 class="font-semibold text-lg text-gray-400 font-mono flex items-center" data-id="52">Code</h1>
{% if is_add|default(false, true) %}
<input type="text" id="function-name"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 max-w-fit"
placeholder="foo" required="" value="{{ name }}">
{% endif %}
<button
class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 text-gray-600 dark:text-gray-400 justify-between"
@@ -233,7 +231,8 @@
</button>
<script>
document.querySelector('#edit-http-function').addEventListener('click', () => {
let name = '{{ name }}';
let name = "{{ name }}";
let updated_name = document.querySelector('#function-name').value;
let script_content = editor.getValue().trim();
let environment_info = editor_environment.getValue().trim();
let is_public = document.querySelector('#is_public').checked
@@ -245,10 +244,21 @@
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, script_content, environment_info, is_public, log_request, log_response }),
body: JSON.stringify({ name, updated_name, script_content, environment_info, is_public, log_request, log_response }),
})
.then(response => response.json())
.then(json => showAlert(json.message, json.status))
.then(json => {
if (name != updated_name) {
htmx.ajax('GET', "{{ url_for('get_http_function_edit_form') }}", {
target: '#container',
swap: 'innerHTML',
values: { name: updated_name }
});
}
else {
showAlert(json.message, json.status)
}
})
})
</script>
{% endif %}