From 6796085288fbc527f29a113ff6213642bb459288 Mon Sep 17 00:00:00 2001 From: Ludovic <54670129+lbr38@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:40:13 +0100 Subject: [PATCH] patch --- www/models/Connection.php | 12 +- .../resources/js/events/task/actions.js | 7 +- www/public/resources/js/general.js | 104 +++++++------- .../resources/js/pre/functions/global.js | 133 +++++++++--------- 4 files changed, 137 insertions(+), 119 deletions(-) diff --git a/www/models/Connection.php b/www/models/Connection.php index d84188cc..91a5fd9f 100644 --- a/www/models/Connection.php +++ b/www/models/Connection.php @@ -986,9 +986,9 @@ private function generateTaskLogTables() Identifier VARCHAR(255), Title VARCHAR(255), Status CHAR(9), /* running, completed, error */ - Start VARCHAR(255), - End VARCHAR(255), - Duration VARCHAR(255), + Start REAL, + End REAL, + Duration REAL, Message VARCHAR(255), Task_id INTEGER)"); @@ -999,9 +999,9 @@ private function generateTaskLogTables() Title VARCHAR(255), Note VARCHAR(255), Status CHAR(9), /* new, running, completed, error */ - Start VARCHAR(255), - End VARCHAR(255), - Duration VARCHAR(255), + Start REAL, + End REAL, + Duration REAL, Output TEXT, Step_id INTEGER)"); diff --git a/www/public/resources/js/events/task/actions.js b/www/public/resources/js/events/task/actions.js index 1d86012a..25fd3931 100644 --- a/www/public/resources/js/events/task/actions.js +++ b/www/public/resources/js/events/task/actions.js @@ -33,8 +33,11 @@ $(document).on('click','.show-task-btn',function () { // Change URL without reloading the page history.pushState(null, null, '/run/' + taskId); - // Reload task container - reloadContainer('tasks/log'); + // Reload task container to print the new task log + reloadContainer('tasks/log').then(function () { + // Restart log scroll event listener + scrollEvent(); + }); }); /** diff --git a/www/public/resources/js/general.js b/www/public/resources/js/general.js index 352ea21c..5993489d 100644 --- a/www/public/resources/js/general.js +++ b/www/public/resources/js/general.js @@ -249,54 +249,62 @@ function reloadPanel(name, params = ['']) */ function reloadContainer(container) { - /** - * If the container to reload does not exist, return - */ - if (!$('.reloadable-container[container="' + container + '"]').length) { - return; - } - - /** - * Print a loading icon on the bottom of the page - */ - printLoading(); - - /** - * Check if container has children with class .veil-on-reload - * If so print a veil on them - */ - printLoadingVeilByParentClass('reloadable-container[container="' + container + '"]'); - - ajaxRequest( - // Controller: - 'general', - // Action: - 'getContainer', - // Data: - { - sourceUrl: window.location.href, - sourceUri: window.location.pathname, - container: container - }, - // Print success alert: - false, - // Print error alert: - true, - // Reload container: - [], - // Execute functions on success: - [ - // Replace container with itself, with new content - "$('.reloadable-container[container=\"" + container + "\"]').replaceWith(jsonValue.message)", - // Reload opened or closed elements that were opened/closed before reloading - "reloadOpenedClosedElements()" - ] - ); - - /** - * Hide loading icon - */ - hideLoading(); + return new Promise((resolve, reject) => { + try { + /** + * If the container to reload does not exist, reject promise + */ + if (!$('.reloadable-container[container="' + container + '"]').length) { + reject('Container not found'); + } + + /** + * Print a loading icon on the bottom of the page + */ + printLoading(); + + /** + * Check if container has children with class .veil-on-reload + * If so print a veil on them + */ + printLoadingVeilByParentClass('reloadable-container[container="' + container + '"]'); + + ajaxRequest( + // Controller: + 'general', + // Action: + 'getContainer', + // Data: + { + sourceUrl: window.location.href, + sourceUri: window.location.pathname, + container: container + }, + // Print success alert: + false, + // Print error alert: + true, + // Reload container: + [], + // Execute functions on success: + [ + // Replace container with itself, with new content + "$('.reloadable-container[container=\"" + container + "\"]').replaceWith(jsonValue.message)", + // Reload opened or closed elements that were opened/closed before reloading + "reloadOpenedClosedElements()" + ] + ).then(() => { + // Hide loading icon + hideLoading(); + + // Resolve promise + resolve('Container reloaded'); + }); + } catch (error) { + // Reject promise + reject('Failed to reload container'); + } + }); } /** diff --git a/www/public/resources/js/pre/functions/global.js b/www/public/resources/js/pre/functions/global.js index e3b92611..987fd94f 100644 --- a/www/public/resources/js/pre/functions/global.js +++ b/www/public/resources/js/pre/functions/global.js @@ -29,77 +29,84 @@ function ajaxRequest(controller, action, additionalData = null, printSuccessAler */ // console.log(data); - /** - * Ajax request - */ - $.ajax({ - type: "POST", - url: "/ajax/controller.php", - data: data, - dataType: "json", - success: function (data, textStatus, jqXHR) { - /** - * Retrieve and print success message - */ - jsonValue = jQuery.parseJSON(jqXHR.responseText); + return new Promise((resolve, reject) => { + /** + * Ajax request + */ + $.ajax({ + type: "POST", + url: "/ajax/controller.php", + data: data, + dataType: "json", + success: function (data, textStatus, jqXHR) { + /** + * Retrieve and print success message + */ + jsonValue = jQuery.parseJSON(jqXHR.responseText); - /** - * Print success message - */ - // Print alert - if (printSuccessAlert === true) { - printAlert(jsonValue.message, 'success'); - } - // Print to console - if (printSuccessAlert == 'console') { - console.log(jsonValue.message); - } + /** + * Print success message + */ + // Print alert + if (printSuccessAlert === true) { + printAlert(jsonValue.message, 'success'); + } + // Print to console + if (printSuccessAlert == 'console') { + console.log(jsonValue.message); + } - /** - * Reload containers if specified - */ - if (reloadContainers != null) { - for (let i = 0; i < reloadContainers.length; i++) { - reloadContainer(reloadContainers[i]); + /** + * Reload containers if specified + */ + if (reloadContainers != null) { + for (let i = 0; i < reloadContainers.length; i++) { + reloadContainer(reloadContainers[i]); + } } - } - /** - * Execute function(s) if specified - */ - if (execOnSuccess != null) { - for (let i = 0; i < execOnSuccess.length; i++) { - eval(execOnSuccess[i]); + /** + * Execute function(s) if specified + */ + if (execOnSuccess != null) { + for (let i = 0; i < execOnSuccess.length; i++) { + eval(execOnSuccess[i]); + } } - } - }, - error: function (jqXHR, textStatus, thrownError) { - /** - * Retrieve and print error message - */ - jsonValue = jQuery.parseJSON(jqXHR.responseText); - /** - * Print error message - */ - // Print alert - if (printErrorAlert === true) { - printAlert(jsonValue.message, 'error'); - } - // Print to console - if (printErrorAlert == 'console') { - console.log(jsonValue.message); - } + resolve('Ajax request executed successfully'); + }, - /** - * Execute function(s) if specified - */ - if (execOnError != null) { - for (let i = 0; i < execOnError.length; i++) { - eval(execOnError[i]); + error: function (jqXHR, textStatus, thrownError) { + /** + * Retrieve and print error message + */ + jsonValue = jQuery.parseJSON(jqXHR.responseText); + + /** + * Print error message + */ + // Print alert + if (printErrorAlert === true) { + printAlert(jsonValue.message, 'error'); + } + // Print to console + if (printErrorAlert == 'console') { + console.log(jsonValue.message); } - } - }, + + /** + * Execute function(s) if specified + */ + if (execOnError != null) { + for (let i = 0; i < execOnError.length; i++) { + eval(execOnError[i]); + } + } + + reject('Failed to execute ajax request'); + }, + }); }); }