Skip to content

Commit

Permalink
Archived devices were shown #920
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Dec 27, 2024
1 parent fa570b9 commit 4fef6e1
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 56 deletions.
27 changes: 27 additions & 0 deletions front/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,7 @@ input[readonly] {
display: inline-block;
padding: 0.1em;
margin: 0.1em;
/* transition: font-size 0.3s;*/
}

.devicePropAction:hover
Expand All @@ -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 */
/* ----------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion front/deviceDetailsEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function getDeviceData(readAllData){

// 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"
Expand Down
85 changes: 45 additions & 40 deletions front/devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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
}
});
}
// 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;
// }

// 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
Expand Down Expand Up @@ -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)]);

}

});
Expand Down Expand Up @@ -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;
Expand Down
45 changes: 34 additions & 11 deletions front/js/device.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,70 @@


// -----------------------------------------------------------------------------
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
updateApi("devices,appevents")
}

// -----------------------------------------------------------------------------
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")
}



7 changes: 6 additions & 1 deletion front/js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -77,6 +78,10 @@ function showModalWarning(
modalCallbackFunction = callbackFunction;
}

if (triggeredBy != null) {
$('#'+prefix).attr("data-myparam-triggered-by", triggeredBy)
}

// Show modal
$("#modal-warning").modal("show");
}
Expand Down
3 changes: 2 additions & 1 deletion front/js/settings_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});

Expand Down
1 change: 1 addition & 0 deletions front/php/templates/language/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file modified front/php/templates/language/es_es.json
100644 → 100755
Empty file.
Empty file modified log/.gitignore
100644 → 100755
Empty file.
Empty file modified log/plugins/.gitignore
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion server/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
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)
Expand Down
3 changes: 2 additions & 1 deletion server/graphql_server/graphql_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def resolve_devices(self, info, options=None):
(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":
Expand Down

0 comments on commit 4fef6e1

Please sign in to comment.