Fix Network scaling, DeviceDetials link, missing lang string, incorrectly mapped columns, default device values

This commit is contained in:
Jokob-sk
2023-01-23 21:18:27 +11:00
parent 7baae289d1
commit 35d9c0e548
6 changed files with 91 additions and 49 deletions

View File

@@ -192,9 +192,9 @@
var parTableOrder = 'Front_Devices_Order';
var tableRows = 10;
var tableOrder = [[3,'desc'], [0,'asc']];
var tableColumnVisible = [0,1,2,3,4,5,6,7,8,9,10,12,13,14];
var columnsStr = '[0,1,2,3,4,5,6,7,8,9,10,12,13,14]';
var tableColumnOrder = [0,1,2,3,4,5,6,7,8,9,10,12,13,14] ;
var tableColumnVisible = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14];
var columnsStr = '[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]';
var tableColumnOrder = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] ;
// Read parameters & Initialize components
main();
@@ -461,7 +461,7 @@ function getDevicesFromTable(table)
rowIDs.map(function(rowID, index){
result.push({
"rowid": rowID,
"mac":rowMACs[index],
"mac" : rowMACs[index],
"name" : rowNames[index],
"type" : rowTypes[index],
"icon" : rowIcons[index],

View File

@@ -454,7 +454,7 @@
<script src="js/pialert_common.js"></script>
<script>
<script defer>
// ---------------------------------------------------------------------------
// Tree functionality
// ---------------------------------------------------------------------------
@@ -580,7 +580,11 @@
renderNode: nodeData => {
// calculate the font size of the leaf nodes to fit everything into the tree area
var fontSize = (nodeData.data.hasChildren) ? "" : "font-size:"+((600/(20*leafNodesCount)).toFixed(2))+"em;";
leafNodesCount == 0 ? 1 : leafNodesCount;
emSize = ((600/(20*leafNodesCount)).toFixed(2));
emSize = emSize > 1 ? 1 : emSize;
var fontSize = (nodeData.data.hasChildren) ? "" : "font-size:"+emSize+"em;";
deviceIcon = (!emptyArr.includes(nodeData.data.icon )) ? "<div class='netIcon '><i class='fa fa-"+nodeData.data.icon +"'></i></div>" : "";
collapseExpandIcon = nodeData.data.hiddenChildren ? "square-plus" :"square-minus";
@@ -589,7 +593,7 @@
selectedNodeMac = $(".nav-tabs-custom .active a").attr('data-mytabmac')
highlightedCss = nodeData.data.mac == selectedNodeMac ? " highlightedNode" : "";
highlightedCss = nodeData.data.mac == selectedNodeMac ? " highlightedNode" : "";
return result = "<div class='box "+statusCss+" "+highlightedCss+"' data-mytreemacmain='"+nodeData.data.mac+"' \
style='height:"+nodeData.settings.nodeHeight+"px;\
@@ -637,25 +641,7 @@
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
// init parent node
var currentNodeMac = $(".tab-content .active td[data-mynodemac]").attr('data-mynodemac');
initButtons(currentNodeMac);
// change highlighted node in the tree
selNode = $("#networkTree .highlightedNode")[0]
// console.log(selNode)
if(selNode)
{
$(selNode).attr('class', $(selNode).attr('class').replace('highlightedNode'))
}
newSelNode = $("#networkTree div[data-mytreemacmain='"+currentNodeMac+"']")[0]
$(newSelNode).attr('class', $(newSelNode).attr('class') + ' highlightedNode')
initButtons()
});
@@ -696,8 +682,26 @@
}
// ---------------------------------------------------------------------------
function initButtons(currentNodeMac)
{
function initButtons()
{
var currentNodeMac = $(".tab-content .active td[data-mynodemac]").attr('data-mynodemac');
// change highlighted node in the tree
selNode = $("#networkTree .highlightedNode")[0]
// console.log(selNode)
if(selNode)
{
$(selNode).attr('class', $(selNode).attr('class').replace('highlightedNode'))
}
newSelNode = $("#networkTree div[data-mytreemacmain='"+currentNodeMac+"']")[0]
$(newSelNode).attr('class', $(newSelNode).attr('class') + ' highlightedNode')
// init the Assign buttons
$('#unassignedDevices button[data-myleafmac]').each(function(){
$(this).attr('onclick', 'updateLeaf("'+$(this).attr('data-myleafmac')+'","'+currentNodeMac+'")')
@@ -712,6 +716,8 @@
// ---------------------------------------------------------------------------
function updateLeaf(leafMac,nodeMac)
{
console.log(leafMac)
console.log(nodeMac)
saveData('updateNetworkLeaf', leafMac, nodeMac);
setTimeout("location.reload();", 1000); // refresh page after 1s
}
@@ -726,6 +732,9 @@
// attach on-click events
attachTreeEvents();
// init Assign/Unassign buttons
initButtons()
</script>

View File

@@ -622,8 +622,8 @@ function getDevicesList() {
$defaultOrder = array ($row['dev_Name'],
$row['dev_Owner'],
$row['dev_DeviceType'],
$row['dev_Icon'],
handleNull($row['dev_DeviceType']),
handleNull($row['dev_Icon'], "laptop"),
$row['dev_Favorite'],
$row['dev_Group'],
formatDate ($row['dev_FirstConnection']),
@@ -634,12 +634,12 @@ function getDevicesList() {
$row['dev_MAC'], // MAC (hidden)
formatIPlong ($row['dev_LastIP']), // IP orderable
$row['rowid'], // Rowid (hidden)
$row['dev_Network_Node_MAC_ADDR'] //
handleNull($row['dev_Network_Node_MAC_ADDR']) //
);
$newOrder = array();
// reorder columns based on user settings
for($index = 0; $index < count($columnOrderMapping); $index++)
{
array_push($newOrder, $defaultOrder[$columnOrderMapping[$index][2]]);
@@ -757,10 +757,11 @@ function getIcons() {
// arrays of rows
$tableData = array();
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
$icon = handleNull($row['dev_Icon'], "laptop");
// Push row data
$tableData[] = array('id' => $row['dev_Icon'],
'name' => '<i class="fa fa-'.$row['dev_Icon'].'"></i> - '.$row['dev_Icon'] );
$tableData[] = array('id' => $icon,
'name' => '<i class="fa fa-'.$icon.'"></i> - '.$icon );
}
// Control no rows

View File

@@ -80,6 +80,9 @@ function getParameter($skipCache, $defaultValue, $expireMinutes) {
$value = $row[0];
} else{
$value = $defaultValue;
// Nothing found in the DB, Insert new value
insertNew($parameter, $value);
}
// update cache
@@ -113,15 +116,7 @@ function setParameter($expireMinutes) {
$changes = $db->changes();
if ($changes == 0) {
// Insert new value
$sql = 'INSERT INTO Parameters (par_ID, par_Value)
VALUES ("'. quotes($parameter) .'",
"'. quotes($value) .'")';
$result = $db->query($sql);
if (! $result == TRUE) {
echo "Error creating parameter\n\n$sql \n\n". $db->lastErrorMsg();
return;
}
insertNew($parameter, $value);
}
// update cache
@@ -130,4 +125,21 @@ function setParameter($expireMinutes) {
echo 'OK';
}
function insertNew($parameter, $value)
{
global $db;
// Insert new value
$sql = 'INSERT INTO Parameters (par_ID, par_Value)
VALUES ("'. quotes($parameter) .'",
"'. quotes($value) .'")';
$result = $db->query($sql);
if (! $result == TRUE) {
echo "Error creating parameter\n\n$sql \n\n". $db->lastErrorMsg();
return;
}
}
?>

View File

@@ -353,6 +353,18 @@ function logServerConsole ($text) {
$x = array();
$y = $x['__________'. $text .'__________'];
}
// -------------------------------------------------------------------------------------------
function handleNull ($text, $default = "") {
if($text == NULL || $text == 'NULL')
{
return $default;
} else
{
return $text;
}
}
// -------------------------------------------------------------------------------------------