Devices Columns 0.3

This commit is contained in:
Jokob-sk
2023-01-20 23:44:33 +11:00
parent 5498035ca9
commit ab98382984
6 changed files with 168 additions and 112 deletions

View File

@@ -150,21 +150,7 @@
<div class="box-body table-responsive">
<table id="tableDevices" class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th><?php echo lang('Device_TableHead_Name');?></th>
<th><?php echo lang('Device_TableHead_Owner');?></th>
<th><?php echo lang('Device_TableHead_Type');?></th>
<th><?php echo lang('Device_TableHead_Icon');?></th>
<th><?php echo lang('Device_TableHead_Favorite');?></th>
<th><?php echo lang('Device_TableHead_Group');?></th>
<th><?php echo lang('Device_TableHead_FirstSession');?></th>
<th><?php echo lang('Device_TableHead_LastSession');?></th>
<th><?php echo lang('Device_TableHead_LastIP');?></th>
<th><?php echo lang('Device_TableHead_MAC');?></th>
<th><?php echo lang('Device_TableHead_Status');?></th>
<th><?php echo lang('Device_TableHead_MAC_full');?></th>
<th><?php echo lang('Device_TableHead_LastIPOrder');?></th>
<th><?php echo lang('Device_TableHead_Rowid');?></th>
<tr>
</tr>
</thead>
@@ -206,7 +192,8 @@
var parTableOrder = 'Front_Devices_Order';
var tableRows = 10;
var tableOrder = [[3,'desc'], [0,'asc']];
var tableColumnShow = [0,1,2,3,4,5,6,7,8,9,10,12,13]
var tableColumnVisible = [0,1,2,3,4,5,6,7,8,9,10,12,13]
var tableColumnOrder = [0,1,2,3,4,5,6,7,8,9,10,12,13]
var tableColumnAll = [0,1,2,3,4,5,6,7,8,9,10,12,13]
// Read parameters & Initialize components
@@ -215,41 +202,72 @@
// -----------------------------------------------------------------------------
function main () {
// get parameter value
$.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue=[0,1,2,3,4,5,6,7,8,9,10,11,12,13]&parameter=Front_Devices_Columns', function(data) {
// get visible columns
$.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue=[0,1,2,3,4,5,6,7,8,9,10,11,12,13]&parameter=Front_Devices_Columns_Visible', function(data) {
tableColumnShow = numberArrayFromString(data);
tableColumnVisible = numberArrayFromString(data);
console.log(tableColumnShow);
// get the custom order specified by the user
$.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue=[0,1,2,3,4,5,6,7,8,9,10,11,12,13]&parameter=Front_Devices_Columns_Order', function(data) {
tableColumnOrder = numberArrayFromString(data);
// get parameter value
$.get('php/server/parameters.php?action=get&defaultValue=50&parameter='+ parTableRows, function(data) {
var result = JSON.parse(data);
//initialize the table headers in the correct order
var headersDefaultOrder = [ '<?php echo lang('Device_TableHead_Name');?>',
'<?php echo lang('Device_TableHead_Owner');?>',
'<?php echo lang('Device_TableHead_Type');?>',
'<?php echo lang('Device_TableHead_Icon');?>',
'<?php echo lang('Device_TableHead_Favorite');?>',
'<?php echo lang('Device_TableHead_Group');?>',
'<?php echo lang('Device_TableHead_FirstSession');?>',
'<?php echo lang('Device_TableHead_LastSession');?>',
'<?php echo lang('Device_TableHead_LastIP');?>',
'<?php echo lang('Device_TableHead_MAC');?>',
'<?php echo lang('Device_TableHead_Status');?>',
'<?php echo lang('Device_TableHead_MAC_full');?>',
'<?php echo lang('Device_TableHead_LastIPOrder');?>',
'<?php echo lang('Device_TableHead_Rowid');?>'];
result = parseInt(result, 10)
if (Number.isInteger (result) ) {
tableRows = result;
html = '';
for(index = 0; index < tableColumnOrder.length; index++)
{
html += '<th>' + headersDefaultOrder[tableColumnOrder[index]] + '</th>';
}
$('#tableDevices tr').html(html);
// get parameter value
$.get('php/server/parameters.php?action=get&defaultValue=[[3,"desc"],[0,"asc"]]&parameter='+ parTableOrder, function(data) {
$.get('php/server/parameters.php?action=get&defaultValue=50&parameter='+ parTableRows, function(data) {
var result = JSON.parse(data);
result = JSON.parse(result);
result = parseInt(result, 10)
if (Array.isArray (result) ) {
tableOrder = result;
if (Number.isInteger (result) ) {
tableRows = result;
}
// Initialize components with parameters
initializeDatatable();
// get parameter value
$.get('php/server/parameters.php?action=get&defaultValue=[[3,"desc"],[0,"asc"]]&parameter='+ parTableOrder, function(data) {
var result = JSON.parse(data);
result = JSON.parse(result);
// query data
getDevicesTotals();
getDevicesList (deviceStatus);
if (Array.isArray (result) ) {
tableOrder = result;
}
// Initialize components with parameters
initializeDatatable();
// query data
getDevicesTotals();
getDevicesList (deviceStatus);
});
});
});
});
@@ -260,24 +278,31 @@ var tableColumnHide = [];
function mapIndx(oldIndex)
{
newIndex = oldIndex;
return newIndex;
for(i=0;i<tableColumnOrder.length;i++)
{
if(tableColumnOrder[i] == oldIndex)
{
// console.log('newIndex')
// console.log(i)
return i;
}
}
}
// -----------------------------------------------------------------------------
function initializeDatatable () {
for(i = 0; i < tableColumnAll.length; i++)
for(i = 0; i < tableColumnOrder.length; i++)
{
// hide this coolumn if not in the tableColumnShow variable
if(tableColumnShow.includes(tableColumnAll[i]) == false)
// hide this column if not in the tableColumnVisible variable
if(tableColumnVisible.includes(tableColumnOrder[i]) == false)
{
tableColumnHide.push(tableColumnAll[i]);
tableColumnHide.push(mapIndx(tableColumnOrder[i]));
}
}
// If the device has a small width (mobile) only show name, ip, and status columns.
if (window.screen.width < 400) {
// var tableColumnHide = [11,12,13,1,2,4,5,6,7,9];
if (window.screen.width < 400) {
tableColumnHide = [11,12,13,1,2,4,5,6,7,9];
}
// else {
@@ -310,7 +335,7 @@ function initializeDatatable () {
// Device Name
{targets: [mapIndx(0)],
'createdCell': function (td, cellData, rowData, row, col) {
$(td).html ('<b><a href="deviceDetails.php?mac='+ rowData[11] +'" class="">'+ cellData +'</a></b>');
$(td).html ('<b><a href="deviceDetails.php?mac='+ rowData[mapIndx(11)] +'" class="">'+ cellData +'</a></b>');
} },
// Icon
@@ -322,8 +347,7 @@ function initializeDatatable () {
$(td).html ('');
}
} },
// Favorite
// {targets: [3],
// Favorite
{targets: [mapIndx(4)],
'createdCell': function (td, cellData, rowData, row, col) {
if (cellData == 1){
@@ -333,15 +357,13 @@ function initializeDatatable () {
}
} },
// Dates
// {targets: [5, 6],
// Dates
{targets: [mapIndx(6), mapIndx(7)],
'createdCell': function (td, cellData, rowData, row, col) {
$(td).html (translateHTMLcodes (cellData));
} },
// Random MAC
// {targets: [8],
// Random MAC
{targets: [mapIndx(9)],
'createdCell': function (td, cellData, rowData, row, col) {
if (cellData == 1){
@@ -351,8 +373,7 @@ function initializeDatatable () {
}
} },
// Status color
// {targets: [9],
// Status color
{targets: [mapIndx(10)],
'createdCell': function (td, cellData, rowData, row, col) {
switch (cellData) {

View File

@@ -1 +0,0 @@
var deviceColumns = {'Icon':4, 'Owner':5}

View File

@@ -761,14 +761,36 @@ function scrollDown()
// --------------------------------------------------------
function saveSelectedColumns () {
$.get('php/server/parameters.php?action=set&expireMinutes=525600&value=['+ $('#columnsSelect').val().toString() +']&parameter=Front_Devices_Columns', function(data) {
showMessage(data)
$.get('php/server/parameters.php?action=set&expireMinutes=525600&value=['+ $('#columnsSelect').val().toString() +']&parameter=Front_Devices_Columns_Visible', function(data) {
// save full order of all columns to simplify mapping later on
colDisplayed = $('#columnsSelect').val();
colDefaultOrder = ['0','1','2','3','4','5','6','7','8','9','10','12','13'];
colNewOrder = colDisplayed;
for(i = 0; i < colDefaultOrder.length; i++)
{
if(!colDisplayed.includes(colDefaultOrder[i]))
{
colNewOrder.push(colDefaultOrder[i])
}
}
console.log(colNewOrder);
$.get('php/server/parameters.php?action=set&expireMinutes=525600&value=['+ colNewOrder.toString() +']&parameter=Front_Devices_Columns_Order', function(data) {
showMessage(data);
});
});
}
// --------------------------------------------------------
function initializeSelectedColumns () {
$.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue=[0,1,2,3,4,5,6,7,8,9,10,12,13]&parameter=Front_Devices_Columns', function(data) {
$.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue=[0,1,2,3,4,5,6,7,8,9,10,12,13]&parameter=Front_Devices_Columns_Visible', function(data) {
tableColumnShow = numberArrayFromString(data);

View File

@@ -569,50 +569,39 @@ function getDevicesTotals() {
function getDevicesList() {
global $db;
// This object is used to map from the old order ( second parameter, first number) to the 3rd parameter (Second number (here initialized to -1))
$columnOrderMapping = array(
array("dev_Name", 0, -1), // 2
array("dev_Owner", 1, -1), // 5
array("dev_DeviceType", 2, -1), // 6
array("dev_Icon", 3, -1), // 0
array("dev_Favorite", 4, -1), // 7
array("dev_Group", 5, -1), // 8
array("dev_FirstConnection", 6, -1), // 9
array("dev_LastConnection", 7, -1), // 10
array("dev_LastIP", 8, -1), // 4
array("dev_MAC", 9, -1), // 11
array("dev_Status", 10, -1), // 1
array("dev_MAC_full", 11, -1), // 3
array("dev_LastIP_orderable", 12, -1), // 12
array("rowid", 13, -1) // 13
array("dev_Name", 0, -1),
array("dev_Owner", 1, -1),
array("dev_DeviceType", 2, -1),
array("dev_Icon", 3, -1),
array("dev_Favorite", 4, -1),
array("dev_Group", 5, -1),
array("dev_FirstConnection", 6, -1),
array("dev_LastConnection", 7, -1),
array("dev_LastIP", 8, -1),
array("dev_MAC", 9, -1),
array("dev_Status", 10, -1),
array("dev_MAC_full", 11, -1),
array("dev_LastIP_orderable", 12, -1),
array("rowid", 13, -1)
);
// get device columns order
$sql = 'SELECT par_Value FROM Parameters where par_ID = "Front_Devices_Columns"';
$sql = 'SELECT par_Value FROM Parameters where par_ID = "Front_Devices_Columns_Order"';
$result = $db->query($sql);
$row = $result -> fetchArray (SQLITE3_NUM);
if($row != NULL && count($row) == 1)
{
$displayedColumns = createArray($row[0]);
// ordered columns setting from the maintenance page
$orderedColumns = createArray($row[0]);
// init ordered columns
$index = 0;
foreach ($displayedColumns as $columnIndex) {
$columnOrderMapping[$columnIndex][2] = $index;
$index = $index + 1;
// init ordered columns
for($i = 0; $i < count($orderedColumns); $i++) {
$columnOrderMapping[$i][2] = $orderedColumns[$i];
}
foreach ($columnOrderMapping as $mapping) {
if($mapping[2] == -1)
{
$mapping[2] = $index;
$index = $index + 1;
}
}
}
}
// SQL
$condition = getDeviceCondition ($_REQUEST['status']);
@@ -625,29 +614,36 @@ function getDevicesList() {
END AS dev_Status
FROM Devices '. $condition;
$result = $db->query($sql);
// arrays of rows
$tableData = array();
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
$tableData['data'][] = array ($row['dev_Name'],
$row['dev_Owner'],
$row['dev_DeviceType'],
$row['dev_Icon'],
$row['dev_Favorite'],
$row['dev_Group'],
formatDate ($row['dev_FirstConnection']),
formatDate ($row['dev_LastConnection']),
$row['dev_LastIP'],
( in_array($row['dev_MAC'][1], array("2","6","A","E","a","e")) ? 1 : 0),
$row['dev_Status'],
$row['dev_MAC'], // MAC (hidden)
formatIPlong ($row['dev_LastIP']), // IP orderable
$row['rowid'] // Rowid (hidden)
);
$defaultOrder = array ($row['dev_Name'],
$row['dev_Owner'],
$row['dev_DeviceType'],
$row['dev_Icon'],
$row['dev_Favorite'],
$row['dev_Group'],
formatDate ($row['dev_FirstConnection']),
formatDate ($row['dev_LastConnection']),
$row['dev_LastIP'],
( in_array($row['dev_MAC'][1], array("2","6","A","E","a","e")) ? 1 : 0),
$row['dev_Status'],
$row['dev_MAC'], // MAC (hidden)
formatIPlong ($row['dev_LastIP']), // IP orderable
$row['rowid'] // Rowid (hidden)
);
$newOrder = array();
for($index = 0; $index < count($columnOrderMapping); $index++)
{
array_push($newOrder, $defaultOrder[$columnOrderMapping[$index][2]]);
}
$tableData['data'][] = $newOrder;
}
// Control no rows

View File

@@ -79,6 +79,24 @@ function createArray($input){
return $options;
}
// -------------------------------------------------------------------------------------------
// For debugging - Print arrays
function printArray ($array) {
echo '[';
foreach ($array as $val)
{
if(is_array($val))
{
echo '<br/>';
printArray($val);
} else
{
echo $val.', ';
}
}
echo ']<br/>';
}
// -------------------------------------------------------------------------------------------
function formatDate ($date1) {
return date_format (new DateTime ($date1) , 'Y-m-d H:i');

View File

@@ -155,7 +155,7 @@ $lang['en_us'] = array(
'DevDetail_Shortcut_DownAlerts' => 'Down Alerts',
'DevDetail_Tab_Details' => '<i class="fa fa-info-circle"></i> Details',
'DevDetail_Tab_Nmap' => '<i class="fa fa-ethernet"></i> Nmap',
'DevDetail_Tab_Sessions' => '<i class="fa fa-calendar"></i> Sessions',
'DevDetail_Tab_Sessions' => '<i class="fa fa-list-ol"></i> Sessions',
'DevDetail_Tab_Presence' => '<i class="fa fa-calendar"></i> Presence',
'DevDetail_Tab_Events' => '<i class="fa fa-bolt"></i> Events',
'DevDetail_Tab_Pholus' => '<i class="fa fa-search"></i> Pholus',