Frontend user events rewrite v0.1
This commit is contained in:
@@ -548,6 +548,15 @@ function isEmpty(value)
|
||||
return emptyArr.includes(value)
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Generate a GUID
|
||||
function getGuid() {
|
||||
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
|
||||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Loading Spinner overlay
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
0
front/js/settings_utils.js
Normal file → Executable file
0
front/js/settings_utils.js
Normal file → Executable file
@@ -760,7 +760,7 @@ function performLogManage() {
|
||||
showModalOk ('Result', data );
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
function scrollDown()
|
||||
|
||||
@@ -13,6 +13,7 @@ require dirname(__FILE__).'/../templates/skinUI.php';
|
||||
|
||||
$FUNCTION = [];
|
||||
$SETTINGS = [];
|
||||
$ACTION = "";
|
||||
|
||||
// init request params
|
||||
if(array_key_exists('function', $_REQUEST) != FALSE)
|
||||
@@ -20,21 +21,39 @@ if(array_key_exists('function', $_REQUEST) != FALSE)
|
||||
$FUNCTION = $_REQUEST['function'];
|
||||
}
|
||||
|
||||
if(array_key_exists('settings', $_REQUEST) != FALSE)
|
||||
{
|
||||
$SETTINGS = $_REQUEST['settings'];
|
||||
}
|
||||
|
||||
// call functions based on requested params
|
||||
if ($FUNCTION == 'savesettings')
|
||||
{
|
||||
saveSettings();
|
||||
}
|
||||
elseif ($FUNCTION == 'cleanLog')
|
||||
{
|
||||
cleanLog($SETTINGS);
|
||||
switch ($FUNCTION) {
|
||||
case 'savesettings':
|
||||
saveSettings();
|
||||
break;
|
||||
|
||||
case 'cleanLog':
|
||||
|
||||
if(array_key_exists('settings', $_REQUEST) != FALSE)
|
||||
{
|
||||
$SETTINGS = $_REQUEST['settings'];
|
||||
}
|
||||
|
||||
cleanLog($SETTINGS);
|
||||
break;
|
||||
|
||||
case 'addToExecutionQueue':
|
||||
|
||||
if(array_key_exists('action', $_REQUEST) != FALSE)
|
||||
{
|
||||
$ACTION = $_REQUEST['action'];
|
||||
}
|
||||
|
||||
addToExecutionQueue($ACTION);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Handle any other cases or errors if needed
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Formatting data functions
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -195,6 +214,25 @@ function displayMessage($message, $logAlert = FALSE, $logConsole = TRUE, $logFil
|
||||
|
||||
}
|
||||
|
||||
// Adds an action to perform into the execution_queue.log file
|
||||
function addToExecutionQueue($action)
|
||||
{
|
||||
global $logFolderPath, $timestamp;
|
||||
|
||||
$logFile = 'execution_queue.log';
|
||||
$fullPath = $logFolderPath . $logFile;
|
||||
|
||||
// Open the file or skip if it can't be opened
|
||||
if ($file = fopen($fullPath, 'a')) {
|
||||
fwrite($file, "[" . $timestamp . "]|" . $action . PHP_EOL);
|
||||
fclose($file);
|
||||
displayMessage('Action "'.$action.'" added to the execution queue.', false, true, true, true);
|
||||
} else {
|
||||
displayMessage('Log file not found or couldn\'t be created.', false, true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
function cleanLog($logFile)
|
||||
{
|
||||
|
||||
@@ -489,7 +489,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
data-myparam="${codeName}"
|
||||
data-myparam-plugin="${group}"
|
||||
data-myevent="${event}"
|
||||
onclick="handleEvent(this)"
|
||||
onclick="addToExecutionQueue(this)"
|
||||
>
|
||||
<i title="${getString(event + "_event_tooltip")}" class="fa ${getString(event + "_event_icon")}">
|
||||
</i>
|
||||
@@ -856,22 +856,73 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
}
|
||||
|
||||
|
||||
function updateModalState(){
|
||||
// function updateModalState(){
|
||||
|
||||
setTimeout(function(){
|
||||
displayedEvent = $('#'+modalEventStatusId).html()
|
||||
// setTimeout(function(){
|
||||
// displayedEvent = $('#'+modalEventStatusId).html()
|
||||
|
||||
// loop until finished
|
||||
if(displayedEvent.indexOf('finished') == -1) // if the message is different from finished, check again in 2s
|
||||
{
|
||||
// // loop until finished
|
||||
// if(displayedEvent.indexOf('finished') == -1) // if the message is different from finished, check again in 2s
|
||||
// {
|
||||
|
||||
getParam(modalEventStatusId,"Front_Event", true)
|
||||
// getParam(modalEventStatusId,"Front_Event", true)
|
||||
|
||||
updateModalState()
|
||||
// updateModalState()
|
||||
|
||||
}
|
||||
// }
|
||||
// }, 2000);
|
||||
// }
|
||||
|
||||
|
||||
// --------------------------------------------------------
|
||||
// Calls a backend function to add a front-end event (specified by the attributes 'data-myevent' and 'data-myparam-plugin' on the passed element) to an execution queue
|
||||
function addToExecutionQueue(element)
|
||||
{
|
||||
|
||||
// value has to be in format event|param. e.g. run|ARPSCAN
|
||||
action = `${getGuid()}|${$(element).attr('data-myevent')}|${$(element).attr('data-myparam-plugin')}`
|
||||
|
||||
// addToExecutionQueue(action)
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "php/server/util.php",
|
||||
data: { function: "addToExecutionQueue", action: action },
|
||||
success: function(data, textStatus) {
|
||||
showModalOk ('Result', data );
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TODO
|
||||
function updateModalState() {
|
||||
setTimeout(function() {
|
||||
// Fetch the content from the log file using an AJAX request
|
||||
$.ajax({
|
||||
url: '~/log/execution_queue.log',
|
||||
type: 'GET',
|
||||
success: function(data) {
|
||||
// Update the content of the HTML element (e.g., a div with id 'logContent')
|
||||
$('#logContent').html(data);
|
||||
|
||||
// Check if the displayed content contains 'finished'
|
||||
if (data.indexOf('finished') === -1) {
|
||||
// If not finished, continue to update
|
||||
updateModalState();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
// Handle error, such as the file not being found
|
||||
$('#logContent').html('Error: Log file not found.');
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
// Call the function to start the periodic updates
|
||||
updateModalState();
|
||||
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user