Realtime UI - Socketio tweaks and refactor (#3220)

This commit is contained in:
dgtlmoon
2025-06-03 10:17:19 +02:00
committed by GitHub
parent 7b8d335c43
commit 73f3beda00
112 changed files with 2948 additions and 1524 deletions

View File

@@ -2,20 +2,20 @@
$(document).ready(function () {
function bindAjaxHandlerButtonsEvents() {
$('.ajax-op').on('click.ajaxHandlerNamespace', function (e) {
function bindSocketHandlerButtonsEvents(socket) {
$('.ajax-op').on('click.socketHandlerNamespace', function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: ajax_toggle_url,
data: {'op': $(this).data('op'), 'uuid': $(this).closest('tr').data('watch-uuid')},
statusCode: {
400: function () {
// More than likely the CSRF token was lost when the server restarted
alert("There was a problem processing the request, please reload the page.");
}
}
const op = $(this).data('op');
const uuid = $(this).closest('tr').data('watch-uuid');
console.log(`Socket.IO: Sending watch operation '${op}' for UUID ${uuid}`);
// Emit the operation via Socket.IO
socket.emit('watch_operation', {
'op': op,
'uuid': uuid
});
return false;
});
}
@@ -38,7 +38,7 @@ $(document).ready(function () {
socket.on('connect', function () {
console.log('Socket.IO connected with path:', socketio_url);
console.log('Socket transport:', socket.io.engine.transport.name);
bindAjaxHandlerButtonsEvents();
bindSocketHandlerButtonsEvents(socket);
});
socket.on('connect_error', function(error) {
@@ -55,7 +55,7 @@ $(document).ready(function () {
socket.on('disconnect', function (reason) {
console.log('Socket.IO disconnected, reason:', reason);
$('.ajax-op').off('.ajaxHandlerNamespace')
$('.ajax-op').off('.socketHandlerNamespace')
});
socket.on('queue_size', function (data) {
@@ -63,6 +63,16 @@ $(document).ready(function () {
// Update queue size display if implemented in the UI
})
// Listen for operation results
socket.on('operation_result', function (data) {
if (data.success) {
console.log(`Socket.IO: Operation '${data.operation}' completed successfully for UUID ${data.uuid}`);
} else {
console.error(`Socket.IO: Operation failed: ${data.error}`);
alert("There was a problem processing the request: " + data.error);
}
});
// Listen for periodically emitted watch data
console.log('Adding watch_update event listener');
@@ -87,6 +97,8 @@ $(document).ready(function () {
$($watchRow).toggleClass('has-error', watch.has_error);
$($watchRow).toggleClass('notification_muted', watch.notification_muted);
$($watchRow).toggleClass('paused', watch.paused);
$($watchRow).toggleClass('single-history', watch.history_n === 1);
$($watchRow).toggleClass('multiple-history', watch.history_n >= 2);
$('td.title-col .error-text', $watchRow).html(watch.error_text)