diff --git a/web2/js/alerts.js b/web2/js/alerts.js index 3e88dd2..5242c16 100644 --- a/web2/js/alerts.js +++ b/web2/js/alerts.js @@ -3,27 +3,26 @@ // initialisation let previousAlerts = []; let sortOrder = {}; -ajaxRequest('GET', 'php/request.php/alertes/', CheckNewAlerts); -// ajaxRequest('GET', 'php/request.php/alertes/', displayAlerts); -setInterval(() => { - ajaxRequest('GET', 'php/request.php/alertes/', CheckNewAlerts); - // Effectuer une requête AJAX pour récupérer les nouvelles alertes -}, 10000); +ajaxRequest('GET', 'php/request.php/alertes/', CheckNewAlerts); ajaxRequest('GET', 'php/request.php/devices/', fillSelectDevice); fillSelectRisque(); -// filtrage +setInterval(() => { + ajaxRequest('GET', 'php/request.php/alertes/', CheckNewAlerts); +}, 10000); + +// initialisation of the filters $('#filter-button').click(() => { - const params = []; // Initialise le tableau des paramètres + const params = []; const device = $('#device-select').val(); const alertlvl = $('#risque-select').val(); - - // Ajouter les paramètres uniquement s'ils sont définis + + // enable parameters only if they are not empty if (device) params.push(`device_product=${encodeURIComponent(device)}`); if (alertlvl) params.push(`agent_severity=${encodeURIComponent(alertlvl)}`); - - // Construire l'URL avec les paramètres + + // build the url let url; if (params.length) { url = `php/request.php/alertes/?${params.join('&')}`; @@ -32,23 +31,12 @@ $('#filter-button').click(() => { url = 'php/request.php/alertes/'; console.log(url); } - - // Effectuer la requête AJAX - ajaxRequest('GET', url, displayAlerts); + + ajaxRequest('GET', url, displayAlerts); } ); -// $('#tweets').on('click', '.del', () => { -// console.log('delete'); -// ajaxRequest('DELETE', 'php/request.php/tweets/' + -// $(event.target).closest('.del').attr('value') + '?login=' + login, () => { -// ajaxRequest('GET', 'php/request.php/tweets/', displayTweets); -// } -// ); -// } -// ); - //------------------------------------------------------------------------------ //--- displayAlerts ------------------------------------------------------------ //------------------------------------------------------------------------------ @@ -66,55 +54,68 @@ function displayAlerts(alerts) { $('').text(alert['date_alerte']), $('').text(alert['name']), $('').text(alert['device_product']), - $('').text(alert['src']+":"+alert['spt']), - $('').text(alert['dst']+":"+alert['dpt']), + $('').text(alert['src'] + ":" + alert['spt']), + $('').text(alert['dst'] + ":" + alert['dpt']), $('').text(alert['agent_severity']), $('').text(alert['reason']) ) ); } +//------------------------------------------------------------------------------ +//--- fillSelectDevice ------------------------------------------------------------ +//------------------------------------------------------------------------------ +// fill select with devices. +// \param devices The devices data received via the Ajax request. function fillSelectDevice(devices) { for (let device of devices) $('#device-select').append($('