Archived devices were shown #920

This commit is contained in:
jokob-sk
2024-12-28 09:19:25 +11:00
parent fa570b9bc9
commit 4fef6e156b
12 changed files with 117 additions and 54 deletions

View File

@@ -1416,6 +1416,7 @@ input[readonly] {
display: inline-block;
padding: 0.1em;
margin: 0.1em;
/* transition: font-size 0.3s;*/
}
.devicePropAction:hover
@@ -1426,6 +1427,32 @@ input[readonly] {
}
#panDetails .dataTables_wrapper .bottom div
{
max-width: 34%;
display: block;
float:inline-end;
height: 2em;
}
#panDetails .dataTables_wrapper .bottom .dataTables_info
{
float:inline-start;
}
#panDetails .dataTables_wrapper .bottom .dataTables_length
{
padding: 0.3em;
}
/* #panDetails .dataTables_wrapper .bottom .paging_simple_numbers */
#panDetails #NEWDEV_devCustomProps_label
{
display: none;
}
/* ----------------------------------------------------------------- */
/* MODAL popups */
/* ----------------------------------------------------------------- */

View File

@@ -211,7 +211,7 @@
// Generate the input field HTML
const inputFormHtml = `<div class="form-group col-xs-12">
<label class="${obj.labelClasses}"> ${setting.setName}
<label id="${setting.setKey}_label" class="${obj.labelClasses}" > ${setting.setName}
<i my-set-key="${setting.setKey}"
title="${getString("Settings_Show_Description")}"
class="fa fa-circle-info pointer helpIconSmallTopRight"

View File

@@ -295,46 +295,46 @@ function renderInfoboxes(customData) {
});
}
// -----------------------------------------------------------------------------
// Define a function to filter data based on deviceStatus
function filterDataByStatus(data, status) {
return data.filter(function(item) {
switch (status) {
case 'my_devices':
to_display = getSetting('UI_MY_DEVICES');
// // -----------------------------------------------------------------------------
// // Define a function to filter data based on deviceStatus
// function filterDataByStatus(data, status) {
// return data.filter(function(item) {
// switch (status) {
// case 'my_devices':
// to_display = getSetting('UI_MY_DEVICES');
let result = true;
// let result = true;
if (!to_display.includes('down') && item.devPresentLastScan === 0 && item.devAlertDown !== 0) {
result = false;
} else if (!to_display.includes('new') && item.devIsNew === 1) {
result = false;
} else if (!to_display.includes('archived') && item.devIsArchived === 1) {
result = false;
} else if (!to_display.includes('offline') && item.devPresentLastScan === 0) {
result = false;
} else if (!to_display.includes('online') && item.devPresentLastScan === 1) {
result = false;
}
// if (!to_display.includes('down') && item.devPresentLastScan === 0 && item.devAlertDown !== 0) {
// result = false;
// } else if (!to_display.includes('new') && item.devIsNew === 1) {
// result = false;
// } else if (!to_display.includes('archived') && item.devIsArchived === 1) {
// result = false;
// } else if (!to_display.includes('offline') && item.devPresentLastScan === 0) {
// result = false;
// } else if (!to_display.includes('online') && item.devPresentLastScan === 1) {
// result = false;
// }
return result; // Include all items for 'my_devices' status
case 'connected':
return item.devPresentLastScan === 1;
case 'favorites':
return item.devFavorite === 1;
case 'new':
return item.devIsNew === 1;
case 'offline':
return item.devPresentLastScan === 0;
case 'down':
return (item.devPresentLastScan === 0 && item.devAlertDown !== 0);
case 'archived':
return item.devIsArchived === 1;
default:
return true; // Include all items for unknown statuses
}
});
}
// return result; // Include all items for 'my_devices' status
// case 'connected':
// return item.devPresentLastScan === 1;
// case 'favorites':
// return item.devFavorite === 1;
// case 'new':
// return item.devIsNew === 1;
// case 'offline':
// return item.devPresentLastScan === 0;
// case 'down':
// return (item.devPresentLastScan === 0 && item.devAlertDown !== 0);
// case 'archived':
// return item.devIsArchived === 1;
// default:
// return true; // Include all items for unknown statuses
// }
// });
// }
// Map column index to column name for GraphQL query
@@ -792,6 +792,11 @@ function initializeDatatable (status) {
hideSpinner();
},
createdRow: function(row, data, dataIndex) {
// add devMac to the table row
$(row).attr('my-devMac', data[mapIndx(11)]);
}
});
@@ -919,7 +924,7 @@ function renderCustomProps(custProps, mac) {
onClickEvent = `alert('Not implemented')`;
break;
case "delete_dev":
onClickEvent = `deleteDeviceByMac('${mac}')`;
onClickEvent = `askDelDevDTInline('${mac}')`;
break;
default:
break;

View File

@@ -1,28 +1,47 @@
// -----------------------------------------------------------------------------
function askDeleteDevice () {
function askDeleteDevice() {
// Check MAC
if (mac == '') {
return;
}
// Ask delete device
showModalWarning ('Delete Device', 'Are you sure you want to delete this device?<br>(maybe you prefer to archive it)',
getString('Gen_Cancel'), getString('Gen_Delete'), 'deleteDevice');
showModalWarning(
getString("DevDetail_button_Delete"),
getString("DevDetail_button_Delete_ask"),
getString('Gen_Cancel'),
getString('Gen_Delete'),
'deleteDevice');
}
// -----------------------------------------------------------------------------
function askDelDevDTInline(mac) {
// Check MAC
if (mac == '') {
return;
}
showModalWarning(
getString("DevDetail_button_Delete"),
getString("DevDetail_button_Delete_ask"),
getString('Gen_Cancel'),
getString('Gen_Delete'),
() => deleteDeviceByMac(mac))
}
// -----------------------------------------------------------------------------
function deleteDevice () {
function deleteDevice() {
// Check MAC
if (mac == '') {
return;
}
// Delete device
$.get('php/server/devices.php?action=deleteDevice&mac='+ mac, function(msg) {
showMessage (msg);
$.get('php/server/devices.php?action=deleteDevice&mac=' + mac, function (msg) {
showMessage(msg);
});
// refresh API
@@ -30,18 +49,22 @@ function deleteDevice () {
}
// -----------------------------------------------------------------------------
function deleteDeviceByMac (mac) {
function deleteDeviceByMac(mac) {
// Check MAC
if (mac == '') {
return;
return;
}
// alert(mac)
// return;
// Delete device
$.get('php/server/devices.php?action=deleteDevice&mac='+ mac, function(msg) {
showMessage (msg);
$.get('php/server/devices.php?action=deleteDevice&mac=' + mac, function (msg) {
showMessage(msg);
});
// refresh API
updateApi("devices,appevents")
}

View File

@@ -65,7 +65,8 @@ function showModalWarning(
message,
btnCancel = getString("Gen_Cancel"),
btnOK = getString("Gen_Okay"),
callbackFunction = null
callbackFunction = null,
triggeredBy = null
) {
// set captions
$("#modal-warning-title").html(title);
@@ -77,6 +78,10 @@ function showModalWarning(
modalCallbackFunction = callbackFunction;
}
if (triggeredBy != null) {
$('#'+prefix).attr("data-myparam-triggered-by", triggeredBy)
}
// Show modal
$("#modal-warning").modal("show");
}

View File

@@ -1159,7 +1159,8 @@ function generateFormHtml(settingsData, set, overrideValue, overrideOptions, ori
$(document).ready(() => {
$(`#${tableId}`).DataTable({
ordering: false, // Disables sorting on all columns
searching: false // Disables the search box
searching: false, // Disables the search box
dom: "<'top'rt><'bottom'ipl>", // Move length dropdown to the bottom
});
});

View File

@@ -183,6 +183,7 @@
"DevDetail_button_AddIcon_Help": "Paste in an SVG html tag or Font Awesome html tag icon. Read the <a href=\"https://github.com/jokob-sk/NetAlertX/blob/main/docs/ICONS.md\" target=\"_blank\">Icons docs</a> for details.",
"DevDetail_button_AddIcon_Tooltip": "Add a new Icon to this device that is not yet available in the dropdown.",
"DevDetail_button_Delete": "Delete Device",
"DevDetail_button_Delete_ask": "Are you sure you want to delete this device? You may also archive it instead.",
"DevDetail_button_DeleteEvents": "Delete Events",
"DevDetail_button_DeleteEvents_Warning": "Are you sure you want to delete all Events of this device?<br><br>(this will clear the <b>Events history</b> and the <b>Sessions</b> and might help with constant (persistent) notifications)",
"DevDetail_button_OverwriteIcons": "Overwrite Icons",

0
front/php/templates/language/es_es.json Normal file → Executable file
View File

0
log/.gitignore vendored Normal file → Executable file
View File

0
log/plugins/.gitignore vendored Normal file → Executable file
View File

View File

@@ -88,7 +88,7 @@ sql_devices_tiles = """
FROM Devices
WHERE
(instr((SELECT setValue FROM Statuses), 'online') > 0 AND devPresentLastScan = 1) OR
(instr((SELECT setValue FROM Statuses), 'offline') > 0 AND devPresentLastScan = 0) OR
(instr((SELECT setValue FROM Statuses), 'offline') > 0 AND devPresentLastScan = 0 AND devIsArchived = 0) OR
(instr((SELECT setValue FROM Statuses), 'down') > 0 AND devPresentLastScan = 0 AND devAlertDown = 1) OR
(instr((SELECT setValue FROM Statuses), 'new') > 0 AND devIsNew = 1) OR
(instr((SELECT setValue FROM Statuses), 'archived') > 0 AND devIsArchived = 1)

View File

@@ -142,7 +142,8 @@ class Query(ObjectType):
(device["devPresentLastScan"] == 1 and 'online' in allowed_statuses) or
(device["devIsNew"] == 1 and 'new' in allowed_statuses) or
(device["devPresentLastScan"] == 0 and device["devAlertDown"] and 'down' in allowed_statuses) or
(device["devPresentLastScan"] == 0 and 'offline' in allowed_statuses)
(device["devPresentLastScan"] == 0 and 'offline' in allowed_statuses) and device["devIsArchived"] == 0 or
(device["devIsArchived"] == 1 and 'archived' in allowed_statuses)
)
]
elif status == "connected":