Packaging a few small changes
* Make edit http function endpoint accept function id rather than name * Move show alert js function to function editor template as its only used here * Added a note that previous commit (API -> isolator request was changed from global routing to inter app routing) (It sped things up, but not its regressed; need to look into this further)
This commit is contained in:
@@ -83,32 +83,4 @@
|
||||
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
<div id="alert-container" class="fixed top-10 right-10 z-50"></div>
|
||||
|
||||
<script>
|
||||
function showAlert(message, type = 'success', duration = 1500) {
|
||||
const alertContainer = document.getElementById('alert-container');
|
||||
const alertDiv = document.createElement('div');
|
||||
|
||||
const icon = type === 'success'
|
||||
? '<svg class="w-6 h-6 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>' // SVG for success icon
|
||||
: '<svg class="w-6 h-6 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01"></path></svg>'; // SVG for error icon
|
||||
|
||||
const baseClasses = "flex items-center p-4 mb-4 text-sm text-white rounded-lg shadow-md transition-opacity duration-300";
|
||||
alertDiv.className = `${baseClasses} ${type === 'success' ? 'bg-green-400' : 'bg-red-400'}`;
|
||||
alertDiv.innerHTML = `${icon}<span class="ml-3">${message}</span>`;
|
||||
|
||||
|
||||
|
||||
// Append alert div to the container
|
||||
alertContainer.appendChild(alertDiv);
|
||||
|
||||
// Remove the alert after 'duration' milliseconds
|
||||
setTimeout(() => {
|
||||
alertDiv.style.opacity = '0';
|
||||
setTimeout(() => alertContainer.removeChild(alertDiv), 300);
|
||||
}, duration);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
@@ -288,32 +288,29 @@
|
||||
</button>
|
||||
<script>
|
||||
document.querySelector('#edit-http-function').addEventListener('click', () => {
|
||||
let name = "{{ name }}";
|
||||
let updated_name = document.querySelector('#function-name').value;
|
||||
let 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
|
||||
let log_request = document.querySelector('#log_request').checked
|
||||
let log_response = document.querySelector('#log_response').checked
|
||||
|
||||
fetch("{{ url_for('edit_http_function') }}", {
|
||||
fetch("{{ url_for('edit_http_function', function_id=function_id) }}", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ name, updated_name, script_content, environment_info, is_public, log_request, log_response }),
|
||||
body: JSON.stringify({ name, script_content, environment_info, is_public, log_request, log_response }),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if (name != updated_name) {
|
||||
if ("{{ name }}" != name) {
|
||||
htmx.ajax('GET', "{{ url_for('get_http_function_edit_form', function_id=function_id) }}", {
|
||||
target: '#container',
|
||||
swap: 'innerHTML'
|
||||
});
|
||||
}
|
||||
else {
|
||||
showAlert(json.message, json.status)
|
||||
}
|
||||
showAlert(json.message, json.status)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@@ -362,4 +359,37 @@
|
||||
<!-- Execution results will appear here -->
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function showAlert(message, type = 'success', duration = 1500) {
|
||||
// Create a new div element
|
||||
var alertContainerDiv = document.createElement('div');
|
||||
|
||||
// Add the required classes to the alertContainerDiv
|
||||
alertContainerDiv.classList.add('fixed', 'top-10', 'right-10', 'z-50');
|
||||
|
||||
// Append the new div to the body of the document
|
||||
document.body.appendChild(alertContainerDiv);
|
||||
|
||||
const alertContainer = document.getElementById('alert-container');
|
||||
const alertDiv = document.createElement('div');
|
||||
|
||||
const icon = type === 'success'
|
||||
? '<svg class="w-6 h-6 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>' // SVG for success icon
|
||||
: '<svg class="w-6 h-6 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01"></path></svg>'; // SVG for error icon
|
||||
|
||||
const baseClasses = "flex items-center p-4 mb-4 text-sm text-white rounded-lg shadow-md transition-opacity duration-300";
|
||||
alertDiv.className = `${baseClasses} ${type === 'success' ? 'bg-green-400' : 'bg-red-400'}`;
|
||||
alertDiv.innerHTML = `${icon}<span class="ml-3">${message}</span>`;
|
||||
|
||||
// Append alert div to the container
|
||||
alertContainerDiv.appendChild(alertDiv);
|
||||
|
||||
// Remove the alert after 'duration' milliseconds
|
||||
setTimeout(() => {
|
||||
alertDiv.style.opacity = '0';
|
||||
setTimeout(() => alertContainerDiv.parentElement.removeChild(alertContainerDiv), 300);
|
||||
}, duration);
|
||||
}
|
||||
</script>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user