mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
My Devices filter #548
This commit is contained in:
@@ -148,7 +148,7 @@ fi
|
||||
# Activate the virtual python environment
|
||||
source myenv/bin/activate
|
||||
|
||||
echo "[INSTALL] 🚀 Starting app - navigate to your <server IP>:$LISTEN_ADDR "
|
||||
echo "[INSTALL] 🚀 Starting app - navigate to your <server IP>:$LISTEN_ADDR"
|
||||
|
||||
# Start the PiAlert python script
|
||||
python $INSTALL_DIR/pialert/pialert/
|
||||
|
||||
@@ -42,9 +42,9 @@
|
||||
<!-- top small box 1 ------------------------------------------------------- -->
|
||||
<div class="row">
|
||||
<div class="col-lg-2 col-sm-4 col-xs-6">
|
||||
<a href="#" onclick="javascript: initializeDatatable('all');">
|
||||
<a href="#" onclick="javascript: initializeDatatable('my');">
|
||||
<div class="small-box bg-aqua">
|
||||
<div class="inner"><h3 id="devicesAll"> -- </h3>
|
||||
<div class="inner"><h3 id="devicesMy"> -- </h3>
|
||||
<p class="infobox_label"><?= lang('Device_Shortcut_AllDevices');?></p>
|
||||
</div>
|
||||
<div class="icon"><i class="fa fa-laptop text-aqua-40"></i></div>
|
||||
@@ -291,10 +291,9 @@ function main () {
|
||||
}
|
||||
|
||||
// Initialize components with parameters
|
||||
initializeDatatable();
|
||||
initializeDatatable('my');
|
||||
|
||||
|
||||
// query data
|
||||
getDevicesTotals();
|
||||
|
||||
// check if dat outdated and show spinner if so
|
||||
handleLoadingDialog()
|
||||
@@ -319,13 +318,77 @@ function mapIndx(oldIndex)
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Query total numbers of Devices by status
|
||||
//------------------------------------------------------------------------------
|
||||
function getDevicesTotals(devicesData) {
|
||||
|
||||
let resultJSON = "";
|
||||
|
||||
if (getCache("getDevicesTotals") !== "") {
|
||||
resultJSON = getCache("getDevicesTotals");
|
||||
} else {
|
||||
// combined query
|
||||
const devices = filterDataByStatus(devicesData, 'my');
|
||||
const connectedDevices = filterDataByStatus(devicesData, 'connected');
|
||||
const favoritesDevices = filterDataByStatus(devicesData, 'favorites');
|
||||
const newDevices = filterDataByStatus(devicesData, 'new');
|
||||
const downDevices = filterDataByStatus(devicesData, 'down');
|
||||
const archivedDevices = filterDataByStatus(devicesData, 'archived');
|
||||
|
||||
|
||||
$('#devicesMy').html (devices.length);
|
||||
$('#devicesConnected').html (connectedDevices.length);
|
||||
$('#devicesFavorites').html (favoritesDevices.length);
|
||||
$('#devicesNew').html (newDevices.length);
|
||||
$('#devicesDown').html (downDevices.length);
|
||||
$('#devicesArchived').html (archivedDevices.length);
|
||||
|
||||
// save to cache
|
||||
setCache("getDevicesTotals", resultJSON);
|
||||
}
|
||||
|
||||
console.log(resultJSON);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Define a function to filter data based on deviceStatus
|
||||
function filterDataByStatus(data, status) {
|
||||
return data.filter(function(item) {
|
||||
switch (status) {
|
||||
case 'all':
|
||||
return true; // Include all items for 'all' status
|
||||
case 'my':
|
||||
to_display = getSetting('UI_MY_DEVICES')
|
||||
|
||||
console.log(to_display)
|
||||
|
||||
result = false;
|
||||
|
||||
if (to_display.includes('online') && item.dev_PresentLastScan === 1)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (to_display.includes('offline') && item.dev_PresentLastScan === 0)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (to_display.includes('archived') && item.dev_Archived === 1)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (to_display.includes('new') && item.dev_NewDevice === 1)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (to_display.includes('down') && item.dev_PresentLastScan === 0 && item.dev_AlertDeviceDown !== 0)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result; // Include all items for 'my' status
|
||||
case 'connected':
|
||||
return item.dev_PresentLastScan === 1;
|
||||
case 'favorites':
|
||||
@@ -378,7 +441,7 @@ function initializeDatatable (status) {
|
||||
|
||||
// Define color & title for the status selected
|
||||
switch (deviceStatus) {
|
||||
case 'all': tableTitle = getString('Device_Shortcut_AllDevices'); color = 'aqua'; break;
|
||||
case 'my': tableTitle = getString('Device_Shortcut_AllDevices'); color = 'aqua'; break;
|
||||
case 'connected': tableTitle = getString('Device_Shortcut_Connected'); color = 'green'; break;
|
||||
case 'favorites': tableTitle = getString('Device_Shortcut_Favorites'); color = 'yellow'; break;
|
||||
case 'new': tableTitle = getString('Device_Shortcut_NewDevices'); color = 'yellow'; break;
|
||||
@@ -402,7 +465,10 @@ function initializeDatatable (status) {
|
||||
}
|
||||
}
|
||||
|
||||
$.get('api/table_devices.json?nocache=' + Date.now(), function(result) {
|
||||
$.get('api/table_devices.json?nocache=' + Date.now(), function(result) {
|
||||
|
||||
// query data
|
||||
getDevicesTotals(result.data);
|
||||
|
||||
// Filter the data based on deviceStatus
|
||||
var filteredData = filterDataByStatus(result.data, deviceStatus);
|
||||
@@ -550,7 +616,7 @@ function initializeDatatable (status) {
|
||||
// Random MAC
|
||||
{targets: [mapIndx(9)],
|
||||
'createdCell': function (td, cellData, rowData, row, col) {
|
||||
console.log(cellData)
|
||||
// console.log(cellData)
|
||||
if (cellData == 1){
|
||||
$(td).html ('<i data-toggle="tooltip" data-placement="right" title="Random MAC" style="font-size: 16px;" class="text-yellow glyphicon glyphicon-random"></i>');
|
||||
} else {
|
||||
@@ -638,26 +704,6 @@ function getDevicesFromTable(table)
|
||||
return JSON.stringify (result)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function getDevicesTotals () {
|
||||
// stop timer
|
||||
stopTimerRefreshData();
|
||||
|
||||
// get totals and put in boxes
|
||||
$.get('php/server/devices.php?action=getDevicesTotals', function(data) {
|
||||
var totalsDevices = JSON.parse(data);
|
||||
|
||||
$('#devicesAll').html (totalsDevices[0].toLocaleString());
|
||||
$('#devicesConnected').html (totalsDevices[1].toLocaleString());
|
||||
$('#devicesFavorites').html (totalsDevices[2].toLocaleString());
|
||||
$('#devicesNew').html (totalsDevices[3].toLocaleString());
|
||||
$('#devicesDown').html (totalsDevices[4].toLocaleString());
|
||||
$('#devicesArchived').html (totalsDevices[5].toLocaleString());
|
||||
|
||||
// Timer for refresh data
|
||||
newTimerRefreshData (getDevicesTotals);
|
||||
} );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function getNumberOfChildren(mac, devices)
|
||||
|
||||
@@ -541,7 +541,7 @@ function getDevicesTotals() {
|
||||
} else
|
||||
{
|
||||
global $db;
|
||||
|
||||
f
|
||||
// combined query
|
||||
$result = $db->query(
|
||||
'SELECT
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
"DevDetail_button_Reset": "Reset Changes",
|
||||
"DevDetail_button_Save": "Save",
|
||||
"Device_Searchbox": "Search",
|
||||
"Device_Shortcut_AllDevices": "All Devices",
|
||||
"Device_Shortcut_AllDevices": "My Devices",
|
||||
"Device_Shortcut_Archived": "Archived",
|
||||
"Device_Shortcut_Connected": "Connected",
|
||||
"Device_Shortcut_Devices": "Devices",
|
||||
@@ -498,7 +498,7 @@
|
||||
"Presence_CalHead_year": "year",
|
||||
"Presence_CallHead_Devices": "Devices",
|
||||
"Presence_Loading": "Loading...",
|
||||
"Presence_Shortcut_AllDevices": "All Devices",
|
||||
"Presence_Shortcut_AllDevices": "My Devices",
|
||||
"Presence_Shortcut_Archived": "Archived",
|
||||
"Presence_Shortcut_Connected": "Connected",
|
||||
"Presence_Shortcut_Devices": "Devices",
|
||||
@@ -597,6 +597,8 @@
|
||||
"UI_LANG_name": "UI Language",
|
||||
"UI_PRESENCE_description": "Select what statuses should be shown in the <b>Device presence</b> chart in the <a href=\"/devices.php\" target=\"_blank\">Devices</a> page. (<code>CTRL + Click</code> to select/deselect)",
|
||||
"UI_PRESENCE_name": "Show in presence chart",
|
||||
"UI_MY_DEVICES_description": "Devices of which statuses should be shown in the default My Devices view. (<code>CTRL + Click</code> to select/deselect)",
|
||||
"UI_MY_DEVICES_name": "Show in My Devices view",
|
||||
"devices_old": "Refreshing...",
|
||||
"general_event_description": "The event you have triggered might take a while until background processes finish. The execution ended once the below execution queue empties (Check the <a href='/maintenance.php#tab_Logging'>error log</a> if you encounter issues). <br/> <br/> Execution queue:",
|
||||
"general_event_title": "Executing an ad-hoc event",
|
||||
|
||||
@@ -33,7 +33,8 @@ SCAN_SUBNETS = ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interfac
|
||||
LOG_LEVEL = 'verbose'
|
||||
TIMEZONE = 'Europe/Berlin'
|
||||
UI_LANG = 'English'
|
||||
UI_PRESENCE = ['online', 'offline', 'archived']
|
||||
UI_PRESENCE = ['online', 'offline', 'archived']
|
||||
UI_MY_DEVICES = ['online', 'offline', 'archived', 'new', 'down']
|
||||
PIALERT_WEB_PROTECTION = False
|
||||
PIALERT_WEB_PASSWORD = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'
|
||||
DAYS_TO_KEEP_EVENTS = 90
|
||||
|
||||
@@ -107,6 +107,7 @@ def importConfigs (db):
|
||||
conf.REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://pi.alert/' , c_d, 'PiAlert URL', 'text', '', 'General')
|
||||
conf.UI_LANG = ccd('UI_LANG', 'English' , c_d, 'Language Interface', 'text.select', "['English', 'German', 'Spanish']", 'General')
|
||||
conf.UI_PRESENCE = ccd('UI_PRESENCE', ['online', 'offline', 'archived'] , c_d, 'Include in presence', 'text.multiselect', "['online', 'offline', 'archived']", 'General')
|
||||
conf.UI_MY_DEVICES = ccd('UI_MY_DEVICES', ['online', 'offline', 'archived', 'new', 'down'] , c_d, 'Include in My Devices', 'text.multiselect', "['online', 'offline', 'archived', 'new', 'down']", 'General')
|
||||
conf.DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', 'integer', '', 'General')
|
||||
conf.HRS_TO_KEEP_NEWDEV = ccd('HRS_TO_KEEP_NEWDEV', 0 , c_d, 'Keep new devices for', 'integer', "0", 'General')
|
||||
conf.API_CUSTOM_SQL = ccd('API_CUSTOM_SQL', 'SELECT * FROM Devices WHERE dev_PresentLastScan = 0' , c_d, 'Custom endpoint', 'text', '', 'General')
|
||||
|
||||
Reference in New Issue
Block a user