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

@@ -151,20 +151,6 @@
<table id="tableDevices" class="table table-bordered table-hover table-striped"> <table id="tableDevices" class="table table-bordered table-hover table-striped">
<thead> <thead>
<tr> <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> </thead>
@@ -206,7 +192,8 @@
var parTableOrder = 'Front_Devices_Order'; var parTableOrder = 'Front_Devices_Order';
var tableRows = 10; var tableRows = 10;
var tableOrder = [[3,'desc'], [0,'asc']]; 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] var tableColumnAll = [0,1,2,3,4,5,6,7,8,9,10,12,13]
// Read parameters & Initialize components // Read parameters & Initialize components
@@ -216,12 +203,42 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function main () { function main () {
// get parameter value // 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', function(data) { $.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) {
tableColumnVisible = numberArrayFromString(data);
// 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);
//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');?>'];
html = '';
for(index = 0; index < tableColumnOrder.length; index++)
{
html += '<th>' + headersDefaultOrder[tableColumnOrder[index]] + '</th>';
}
$('#tableDevices tr').html(html);
tableColumnShow = numberArrayFromString(data);
console.log(tableColumnShow);
// get parameter value // get parameter value
$.get('php/server/parameters.php?action=get&defaultValue=50&parameter='+ parTableRows, function(data) { $.get('php/server/parameters.php?action=get&defaultValue=50&parameter='+ parTableRows, function(data) {
@@ -253,6 +270,7 @@ function main () {
}); });
}); });
}); });
});
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -260,24 +278,31 @@ var tableColumnHide = [];
function mapIndx(oldIndex) function mapIndx(oldIndex)
{ {
newIndex = oldIndex; for(i=0;i<tableColumnOrder.length;i++)
return newIndex; {
if(tableColumnOrder[i] == oldIndex)
{
// console.log('newIndex')
// console.log(i)
return i;
}
}
} }
// -----------------------------------------------------------------------------
function initializeDatatable () { 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 // hide this column if not in the tableColumnVisible variable
if(tableColumnShow.includes(tableColumnAll[i]) == false) 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 the device has a small width (mobile) only show name, ip, and status columns.
if (window.screen.width < 400) { if (window.screen.width < 400) {
// var tableColumnHide = [11,12,13,1,2,4,5,6,7,9];
tableColumnHide = [11,12,13,1,2,4,5,6,7,9]; tableColumnHide = [11,12,13,1,2,4,5,6,7,9];
} }
// else { // else {
@@ -310,7 +335,7 @@ function initializeDatatable () {
// Device Name // Device Name
{targets: [mapIndx(0)], {targets: [mapIndx(0)],
'createdCell': function (td, cellData, rowData, row, col) { '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 // Icon
@@ -323,7 +348,6 @@ function initializeDatatable () {
} }
} }, } },
// Favorite // Favorite
// {targets: [3],
{targets: [mapIndx(4)], {targets: [mapIndx(4)],
'createdCell': function (td, cellData, rowData, row, col) { 'createdCell': function (td, cellData, rowData, row, col) {
if (cellData == 1){ if (cellData == 1){
@@ -334,14 +358,12 @@ function initializeDatatable () {
} }, } },
// Dates // Dates
// {targets: [5, 6],
{targets: [mapIndx(6), mapIndx(7)], {targets: [mapIndx(6), mapIndx(7)],
'createdCell': function (td, cellData, rowData, row, col) { 'createdCell': function (td, cellData, rowData, row, col) {
$(td).html (translateHTMLcodes (cellData)); $(td).html (translateHTMLcodes (cellData));
} }, } },
// Random MAC // Random MAC
// {targets: [8],
{targets: [mapIndx(9)], {targets: [mapIndx(9)],
'createdCell': function (td, cellData, rowData, row, col) { 'createdCell': function (td, cellData, rowData, row, col) {
if (cellData == 1){ if (cellData == 1){
@@ -352,7 +374,6 @@ function initializeDatatable () {
} }, } },
// Status color // Status color
// {targets: [9],
{targets: [mapIndx(10)], {targets: [mapIndx(10)],
'createdCell': function (td, cellData, rowData, row, col) { 'createdCell': function (td, cellData, rowData, row, col) {
switch (cellData) { switch (cellData) {

View File

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

View File

@@ -761,14 +761,36 @@ function scrollDown()
// -------------------------------------------------------- // --------------------------------------------------------
function saveSelectedColumns () { function saveSelectedColumns () {
$.get('php/server/parameters.php?action=set&expireMinutes=525600&value=['+ $('#columnsSelect').val().toString() +']&parameter=Front_Devices_Columns', function(data) { $.get('php/server/parameters.php?action=set&expireMinutes=525600&value=['+ $('#columnsSelect').val().toString() +']&parameter=Front_Devices_Columns_Visible', function(data) {
showMessage(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 () { 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); tableColumnShow = numberArrayFromString(data);

View File

@@ -569,48 +569,37 @@ function getDevicesTotals() {
function getDevicesList() { function getDevicesList() {
global $db; 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( $columnOrderMapping = array(
array("dev_Name", 0, -1), // 2 array("dev_Name", 0, -1),
array("dev_Owner", 1, -1), // 5 array("dev_Owner", 1, -1),
array("dev_DeviceType", 2, -1), // 6 array("dev_DeviceType", 2, -1),
array("dev_Icon", 3, -1), // 0 array("dev_Icon", 3, -1),
array("dev_Favorite", 4, -1), // 7 array("dev_Favorite", 4, -1),
array("dev_Group", 5, -1), // 8 array("dev_Group", 5, -1),
array("dev_FirstConnection", 6, -1), // 9 array("dev_FirstConnection", 6, -1),
array("dev_LastConnection", 7, -1), // 10 array("dev_LastConnection", 7, -1),
array("dev_LastIP", 8, -1), // 4 array("dev_LastIP", 8, -1),
array("dev_MAC", 9, -1), // 11 array("dev_MAC", 9, -1),
array("dev_Status", 10, -1), // 1 array("dev_Status", 10, -1),
array("dev_MAC_full", 11, -1), // 3 array("dev_MAC_full", 11, -1),
array("dev_LastIP_orderable", 12, -1), // 12 array("dev_LastIP_orderable", 12, -1),
array("rowid", 13, -1) // 13 array("rowid", 13, -1)
); );
// get device columns order // 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); $result = $db->query($sql);
$row = $result -> fetchArray (SQLITE3_NUM); $row = $result -> fetchArray (SQLITE3_NUM);
if($row != NULL && count($row) == 1) if($row != NULL && count($row) == 1)
{ {
$displayedColumns = createArray($row[0]); // ordered columns setting from the maintenance page
$orderedColumns = createArray($row[0]);
// init ordered columns // init ordered columns
$index = 0; for($i = 0; $i < count($orderedColumns); $i++) {
foreach ($displayedColumns as $columnIndex) { $columnOrderMapping[$i][2] = $orderedColumns[$i];
$columnOrderMapping[$columnIndex][2] = $index;
$index = $index + 1;
}
foreach ($columnOrderMapping as $mapping) {
if($mapping[2] == -1)
{
$mapping[2] = $index;
$index = $index + 1;
}
} }
} }
@@ -626,13 +615,11 @@ function getDevicesList() {
FROM Devices '. $condition; FROM Devices '. $condition;
$result = $db->query($sql); $result = $db->query($sql);
// arrays of rows // arrays of rows
$tableData = array(); $tableData = array();
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
$tableData['data'][] = array ($row['dev_Name'], $defaultOrder = array ($row['dev_Name'],
$row['dev_Owner'], $row['dev_Owner'],
$row['dev_DeviceType'], $row['dev_DeviceType'],
$row['dev_Icon'], $row['dev_Icon'],
@@ -646,8 +633,17 @@ function getDevicesList() {
$row['dev_MAC'], // MAC (hidden) $row['dev_MAC'], // MAC (hidden)
formatIPlong ($row['dev_LastIP']), // IP orderable formatIPlong ($row['dev_LastIP']), // IP orderable
$row['rowid'] // Rowid (hidden) $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 // Control no rows

View File

@@ -79,6 +79,24 @@ function createArray($input){
return $options; 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) { function formatDate ($date1) {
return date_format (new DateTime ($date1) , 'Y-m-d H:i'); 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_Shortcut_DownAlerts' => 'Down Alerts',
'DevDetail_Tab_Details' => '<i class="fa fa-info-circle"></i> Details', 'DevDetail_Tab_Details' => '<i class="fa fa-info-circle"></i> Details',
'DevDetail_Tab_Nmap' => '<i class="fa fa-ethernet"></i> Nmap', '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_Presence' => '<i class="fa fa-calendar"></i> Presence',
'DevDetail_Tab_Events' => '<i class="fa fa-bolt"></i> Events', 'DevDetail_Tab_Events' => '<i class="fa fa-bolt"></i> Events',
'DevDetail_Tab_Pholus' => '<i class="fa fa-search"></i> Pholus', 'DevDetail_Tab_Pholus' => '<i class="fa fa-search"></i> Pholus',