mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Multi-edit ✏ #571
This commit is contained in:
@@ -472,7 +472,37 @@ function getQueryString(key){
|
||||
});
|
||||
|
||||
tmp = params[key]
|
||||
|
||||
if(emptyArr.includes(tmp))
|
||||
{
|
||||
var queryParams = {};
|
||||
fullUrl = window.location.toString();
|
||||
|
||||
// console.log(fullUrl);
|
||||
|
||||
if (fullUrl.includes('?')) {
|
||||
var queryString = fullUrl.split('?')[1];
|
||||
|
||||
// Split the query string into individual parameters
|
||||
var paramsArray = queryString.split('&');
|
||||
|
||||
// Loop through the parameters array
|
||||
paramsArray.forEach(function(param) {
|
||||
// Split each parameter into key and value
|
||||
var keyValue = param.split('=');
|
||||
var keyTmp = decodeURIComponent(keyValue[0]);
|
||||
var value = decodeURIComponent(keyValue[1] || '');
|
||||
|
||||
// Store key-value pair in the queryParams object
|
||||
queryParams[keyTmp] = value;
|
||||
});
|
||||
}
|
||||
|
||||
// console.log(queryParams);
|
||||
|
||||
tmp = queryParams[key]
|
||||
}
|
||||
|
||||
result = emptyArr.includes(tmp) ? "" : tmp;
|
||||
|
||||
return result
|
||||
@@ -722,9 +752,9 @@ function getGuid() {
|
||||
// UI
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// Genrate work-in-progress icons
|
||||
// Generate work-in-progress icons
|
||||
function workInProgress() {
|
||||
console.log()
|
||||
|
||||
if($(".work-in-progress").html().trim() == "")
|
||||
{
|
||||
$(".work-in-progress").append(`
|
||||
@@ -768,6 +798,25 @@ function hideSpinner()
|
||||
$("#loadingSpinner").hide()
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------
|
||||
// Calls a backend function to add a front-end event to an execution queue
|
||||
function updateApi()
|
||||
{
|
||||
|
||||
// value has to be in format event|param. e.g. run|ARPSCAN
|
||||
action = `update_api|devices,appevents`
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "php/server/util.php",
|
||||
data: { function: "addToExecutionQueue", action: action },
|
||||
success: function(data, textStatus) {
|
||||
console.log(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// initialize
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
92
front/js/ui_components.js
Executable file
92
front/js/ui_components.js
Executable file
@@ -0,0 +1,92 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Pi.Alert
|
||||
* Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
*
|
||||
* ui_components.js - Front module. Common UI components
|
||||
*-------------------------------------------------------------------------------
|
||||
# jokob jokob@duck.com GNU GPLv3
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Initialize device selectors / pickers fields
|
||||
// -----------------------------------------------------------------------------
|
||||
function initDeviceSelectors() {
|
||||
|
||||
console.log(devicesList)
|
||||
// Retrieve device list from session variable
|
||||
var devicesListAll_JSON = sessionStorage.getItem('devicesListAll_JSON');
|
||||
|
||||
console.log(devicesListAll_JSON)
|
||||
|
||||
var devicesList = JSON.parse(devicesListAll_JSON);
|
||||
|
||||
console.log(devicesList)
|
||||
|
||||
// Check if both device list exists
|
||||
if (devicesListAll_JSON) {
|
||||
// Parse the JSON string to get the device list array
|
||||
var devicesList = JSON.parse(devicesListAll_JSON);
|
||||
|
||||
|
||||
|
||||
console.log(devicesList)
|
||||
|
||||
var selectorFieldsHTML = ''
|
||||
|
||||
// Loop through the devices list
|
||||
devicesList.forEach(function(device) {
|
||||
|
||||
selectorFieldsHTML += `<option value="${device.dev_MAC}">${device.dev_Name}</option>`;
|
||||
});
|
||||
|
||||
selector = `<div class="db_info_table_row col-sm-12" >
|
||||
<div class="form-group" >
|
||||
<div class="input-group col-sm-12 " >
|
||||
<select class="form-control select2 select2-hidden-accessible" multiple="" style="width: 100%;" tabindex="-1" aria-hidden="true">
|
||||
${selectorFieldsHTML}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>`
|
||||
|
||||
|
||||
// Find HTML elements with class "deviceSelector" and append selector field
|
||||
$('.deviceSelector').append(selector);
|
||||
}
|
||||
|
||||
// Initialize selected items after a delay so selected macs are available in the context
|
||||
setTimeout(function(){
|
||||
// Retrieve MAC addresses from query string or cache
|
||||
var macs = getQueryString('macs') || getCache('selectedDevices');
|
||||
|
||||
if(macs)
|
||||
{
|
||||
// Split MAC addresses if they are comma-separated
|
||||
macs = macs.split(',');
|
||||
|
||||
console.log(macs)
|
||||
|
||||
// Loop through macs to be selected list
|
||||
macs.forEach(function(mac) {
|
||||
|
||||
// Create the option and append to Select2
|
||||
var option = new Option($('.deviceSelector select option[value="' + mac + '"]').html(), mac, true, true);
|
||||
|
||||
$('.deviceSelector select').append(option).trigger('change');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}, 100);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// initialize
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
initDeviceSelectors();
|
||||
|
||||
console.log("init ui_components.js")
|
||||
Reference in New Issue
Block a user