'use strict'; // initialisation let previousAlerts = []; let sortOrder = {}; ajaxRequest('GET', 'php/request.php/alertes/', CheckNewAlerts); ajaxRequest('GET', 'php/request.php/devices/', fillSelectDevice); fillSelectRisque(); setInterval(() => { ajaxRequest('GET', 'php/request.php/alertes/', CheckNewAlerts); }, 10000); // initialisation of the filters $('#filter-button').click(() => { const params = []; const device = $('#device-select').val(); const alertlvl = $('#risque-select').val(); // enable parameters only if they are not empty if (device) params.push(`device_product=${encodeURIComponent(device)}`); if (alertlvl) params.push(`agent_severity=${encodeURIComponent(alertlvl)}`); // build the url let url; if (params.length) { url = `php/request.php/alertes/?${params.join('&')}`; console.log(url); } else { url = 'php/request.php/alertes/'; console.log(url); } ajaxRequest('GET', url, displayAlerts); } ); //------------------------------------------------------------------------------ //--- displayAlerts ------------------------------------------------------------ //------------------------------------------------------------------------------ // Display alerts. // \param alerts The alerts data received via the Ajax request. function displayAlerts(alerts) { // Clear the table. $('#tab-alert').empty(); // Fill alerts. console.log(alerts); for (let alert of alerts) $('#tab-alert').append( $('').append( $('').text(alert['id']), $('').text(alert['date_alerte']), $('').text(alert['name']), $('').text(alert['device_product']), $('').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($('