My Devices filter #548
This commit is contained in:
@@ -42,9 +42,9 @@
|
|||||||
<!-- top small box 1 ------------------------------------------------------- -->
|
<!-- top small box 1 ------------------------------------------------------- -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-2 col-sm-4 col-xs-6">
|
<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="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>
|
<p class="infobox_label"><?= lang('Device_Shortcut_AllDevices');?></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="icon"><i class="fa fa-laptop text-aqua-40"></i></div>
|
<div class="icon"><i class="fa fa-laptop text-aqua-40"></i></div>
|
||||||
@@ -291,10 +291,9 @@ function main () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize components with parameters
|
// Initialize components with parameters
|
||||||
initializeDatatable();
|
initializeDatatable('my');
|
||||||
|
|
||||||
|
|
||||||
// query data
|
|
||||||
getDevicesTotals();
|
|
||||||
|
|
||||||
// check if dat outdated and show spinner if so
|
// check if dat outdated and show spinner if so
|
||||||
handleLoadingDialog()
|
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
|
// Define a function to filter data based on deviceStatus
|
||||||
function filterDataByStatus(data, status) {
|
function filterDataByStatus(data, status) {
|
||||||
return data.filter(function(item) {
|
return data.filter(function(item) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 'all':
|
case 'my':
|
||||||
return true; // Include all items for 'all' status
|
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':
|
case 'connected':
|
||||||
return item.dev_PresentLastScan === 1;
|
return item.dev_PresentLastScan === 1;
|
||||||
case 'favorites':
|
case 'favorites':
|
||||||
@@ -378,7 +441,7 @@ function initializeDatatable (status) {
|
|||||||
|
|
||||||
// Define color & title for the status selected
|
// Define color & title for the status selected
|
||||||
switch (deviceStatus) {
|
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 'connected': tableTitle = getString('Device_Shortcut_Connected'); color = 'green'; break;
|
||||||
case 'favorites': tableTitle = getString('Device_Shortcut_Favorites'); color = 'yellow'; break;
|
case 'favorites': tableTitle = getString('Device_Shortcut_Favorites'); color = 'yellow'; break;
|
||||||
case 'new': tableTitle = getString('Device_Shortcut_NewDevices'); color = 'yellow'; break;
|
case 'new': tableTitle = getString('Device_Shortcut_NewDevices'); color = 'yellow'; break;
|
||||||
@@ -404,6 +467,9 @@ 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
|
// Filter the data based on deviceStatus
|
||||||
var filteredData = filterDataByStatus(result.data, deviceStatus);
|
var filteredData = filterDataByStatus(result.data, deviceStatus);
|
||||||
|
|
||||||
@@ -550,7 +616,7 @@ function initializeDatatable (status) {
|
|||||||
// Random MAC
|
// Random MAC
|
||||||
{targets: [mapIndx(9)],
|
{targets: [mapIndx(9)],
|
||||||
'createdCell': function (td, cellData, rowData, row, col) {
|
'createdCell': function (td, cellData, rowData, row, col) {
|
||||||
console.log(cellData)
|
// console.log(cellData)
|
||||||
if (cellData == 1){
|
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>');
|
$(td).html ('<i data-toggle="tooltip" data-placement="right" title="Random MAC" style="font-size: 16px;" class="text-yellow glyphicon glyphicon-random"></i>');
|
||||||
} else {
|
} else {
|
||||||
@@ -638,26 +704,6 @@ function getDevicesFromTable(table)
|
|||||||
return JSON.stringify (result)
|
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)
|
function getNumberOfChildren(mac, devices)
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ function getDevicesTotals() {
|
|||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
|
f
|
||||||
// combined query
|
// combined query
|
||||||
$result = $db->query(
|
$result = $db->query(
|
||||||
'SELECT
|
'SELECT
|
||||||
|
|||||||
@@ -175,7 +175,7 @@
|
|||||||
"DevDetail_button_Reset": "Reset Changes",
|
"DevDetail_button_Reset": "Reset Changes",
|
||||||
"DevDetail_button_Save": "Save",
|
"DevDetail_button_Save": "Save",
|
||||||
"Device_Searchbox": "Search",
|
"Device_Searchbox": "Search",
|
||||||
"Device_Shortcut_AllDevices": "All Devices",
|
"Device_Shortcut_AllDevices": "My Devices",
|
||||||
"Device_Shortcut_Archived": "Archived",
|
"Device_Shortcut_Archived": "Archived",
|
||||||
"Device_Shortcut_Connected": "Connected",
|
"Device_Shortcut_Connected": "Connected",
|
||||||
"Device_Shortcut_Devices": "Devices",
|
"Device_Shortcut_Devices": "Devices",
|
||||||
@@ -498,7 +498,7 @@
|
|||||||
"Presence_CalHead_year": "year",
|
"Presence_CalHead_year": "year",
|
||||||
"Presence_CallHead_Devices": "Devices",
|
"Presence_CallHead_Devices": "Devices",
|
||||||
"Presence_Loading": "Loading...",
|
"Presence_Loading": "Loading...",
|
||||||
"Presence_Shortcut_AllDevices": "All Devices",
|
"Presence_Shortcut_AllDevices": "My Devices",
|
||||||
"Presence_Shortcut_Archived": "Archived",
|
"Presence_Shortcut_Archived": "Archived",
|
||||||
"Presence_Shortcut_Connected": "Connected",
|
"Presence_Shortcut_Connected": "Connected",
|
||||||
"Presence_Shortcut_Devices": "Devices",
|
"Presence_Shortcut_Devices": "Devices",
|
||||||
@@ -597,6 +597,8 @@
|
|||||||
"UI_LANG_name": "UI Language",
|
"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_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_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...",
|
"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_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",
|
"general_event_title": "Executing an ad-hoc event",
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ LOG_LEVEL = 'verbose'
|
|||||||
TIMEZONE = 'Europe/Berlin'
|
TIMEZONE = 'Europe/Berlin'
|
||||||
UI_LANG = 'English'
|
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_PROTECTION = False
|
||||||
PIALERT_WEB_PASSWORD = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'
|
PIALERT_WEB_PASSWORD = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'
|
||||||
DAYS_TO_KEEP_EVENTS = 90
|
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.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_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_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.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.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')
|
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