mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-01-03 04:18:15 -05:00
GraphQl 0.2.17.2 - device tiles + filtering
This commit is contained in:
@@ -286,7 +286,7 @@ function processDeviceTotals(devicesData) {
|
||||
(getSetting('UI_shown_cards') == "" || getSetting('UI_shown_cards').includes(filter.status))
|
||||
) {
|
||||
dataArray.push({
|
||||
onclickEvent: `initializeDatatable('${filter.status}')`,
|
||||
onclickEvent: `forceLoadUrl('/devices.php#${filter.status}')`,
|
||||
color: filter.color,
|
||||
title: count,
|
||||
label: filter.label,
|
||||
@@ -444,6 +444,8 @@ function initializeDatatable (status) {
|
||||
}
|
||||
}
|
||||
|
||||
// todo: dynamically filter based on status
|
||||
|
||||
|
||||
var table = $('#tableDevices').DataTable({
|
||||
"serverSide": true,
|
||||
@@ -514,8 +516,10 @@ function initializeDatatable (status) {
|
||||
"field": mapColumnIndexToFieldName(d.order[0].column, tableColumnVisible), // Sort field from DataTable column
|
||||
"order": d.order[0].dir.toUpperCase() // Sort direction (ASC/DESC)
|
||||
}] : [], // Default to an empty array if no sorting is defined
|
||||
"search": d.search.value // Search query
|
||||
"search": d.search.value, // Search query
|
||||
"status": deviceStatus
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -689,6 +689,13 @@ function openUrl(urls) {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// force laod URL in current window with specific anchor
|
||||
function forceLoadUrl(relativeUrl) {
|
||||
window.location.replace(relativeUrl);
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function navigateToDeviceWithIp (ip) {
|
||||
|
||||
@@ -255,28 +255,28 @@
|
||||
</a>
|
||||
<ul class="treeview-menu" style="display: <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('devices.php', 'deviceDetails.php') ) ){ echo 'block'; } else {echo 'none';} ?>;">
|
||||
<li>
|
||||
<a href="devices.php#my" onclick="initializeDatatable('my')" > <?= lang("Device_Shortcut_AllDevices");?> </a>
|
||||
<a href="#" onclick="forceLoadUrl('/devices.php#my_devices')" > <?= lang("Device_Shortcut_AllDevices");?> </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="devices.php#connected" onclick="initializeDatatable('connected')" > <?= lang("Device_Shortcut_Connected");?> </a>
|
||||
<a href="#" onclick="forceLoadUrl('/devices.php#connected')" > <?= lang("Device_Shortcut_Connected");?> </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="devices.php#favorites" onclick="initializeDatatable('favorites')" > <?= lang("Device_Shortcut_Favorites");?> </a>
|
||||
<a href="#" onclick="forceLoadUrl('/devices.php#favorites')" > <?= lang("Device_Shortcut_Favorites");?> </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="devices.php#new" onclick="initializeDatatable('new')" > <?= lang("Device_Shortcut_NewDevices");?> </a>
|
||||
<a href="#" onclick="forceLoadUrl('/devices.php#new')" > <?= lang("Device_Shortcut_NewDevices");?> </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="devices.php#down" onclick="initializeDatatable('down')" > <?= lang("Device_Shortcut_DownOnly");?> </a>
|
||||
<a href="#" onclick="forceLoadUrl('/devices.php#down')" > <?= lang("Device_Shortcut_DownOnly");?> </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="devices.php#offline" onclick="initializeDatatable('offline')" > <?= lang("Gen_Offline");?> </a>
|
||||
<a href="#" onclick="forceLoadUrl('/devices.php#offline')" > <?= lang("Gen_Offline");?> </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="devices.php#archived" onclick="initializeDatatable('archived')" > <?= lang("Device_Shortcut_Archived");?> </a>
|
||||
<a href="#" onclick="forceLoadUrl('/devices.php#archived')" > <?= lang("Device_Shortcut_Archived");?> </a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
|
||||
<!-- Monitoring menu item -->
|
||||
|
||||
@@ -112,7 +112,7 @@ def execute_arpscan(userSubnets):
|
||||
re_ip = r'(?P<ip>((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9]))'
|
||||
re_mac = r'(?P<mac>([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2}))'
|
||||
re_hw = r'(?P<hw>.*)'
|
||||
re_pattern = re.compile (re_ip + '\s+' + re_mac + '\s' + re_hw)
|
||||
re_pattern = re.compile(rf"{re_ip}\s+{re_mac}\s{re_hw}")
|
||||
|
||||
devices_list_tmp = [
|
||||
{**device.groupdict(), "interface": interface}
|
||||
|
||||
@@ -9,7 +9,7 @@ sys.path.extend([f"{INSTALL_PATH}/server"])
|
||||
|
||||
from logger import mylog
|
||||
from const import apiPath
|
||||
from helper import is_random_mac, get_number_of_children, format_ip_long
|
||||
from helper import is_random_mac, get_number_of_children, format_ip_long, get_setting_value
|
||||
|
||||
# Define a base URL with the user's home directory
|
||||
folder = apiPath
|
||||
@@ -24,6 +24,7 @@ class PageQueryOptionsInput(InputObjectType):
|
||||
limit = Int()
|
||||
sort = List(SortOptionsInput)
|
||||
search = String()
|
||||
status = String()
|
||||
|
||||
# Device ObjectType
|
||||
class Device(ObjectType):
|
||||
@@ -74,7 +75,7 @@ class Query(ObjectType):
|
||||
devices = Field(DeviceResult, options=PageQueryOptionsInput())
|
||||
|
||||
def resolve_devices(self, info, options=None):
|
||||
mylog('none', f'[graphql_schema] resolve_devices: {self}')
|
||||
# mylog('none', f'[graphql_schema] resolve_devices: {self}')
|
||||
try:
|
||||
with open(folder + 'table_devices.json', 'r') as f:
|
||||
devices_data = json.load(f)["data"]
|
||||
@@ -93,15 +94,50 @@ class Query(ObjectType):
|
||||
|
||||
mylog('none', f'[graphql_schema] devices_data: {devices_data}')
|
||||
|
||||
# Define static list of searchable fields
|
||||
searchable_fields = [
|
||||
"devName", "devMac", "devOwner", "devType", "devVendor",
|
||||
"devGroup", "devComments", "devLocation", "devStatus",
|
||||
"devSSID", "devSite", "devSourcePlugin", "devSyncHubNode"
|
||||
]
|
||||
|
||||
|
||||
# Apply sorting if options are provided
|
||||
if options:
|
||||
|
||||
|
||||
# Define status-specific filtering
|
||||
if options.status:
|
||||
status = options.status
|
||||
mylog('none', f'[graphql_schema] Applying status filter: {status}')
|
||||
|
||||
# Example filtering based on the "status"
|
||||
if status == "my_devices":
|
||||
# Include devices matching criteria in UI_MY_DEVICES
|
||||
allowed_statuses = get_setting_value("UI_MY_DEVICES")
|
||||
|
||||
mylog('none', f'[graphql_schema] allowed_statuses: {allowed_statuses}')
|
||||
|
||||
devices_data = [
|
||||
device for device in devices_data
|
||||
if (
|
||||
(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)
|
||||
)
|
||||
]
|
||||
elif status == "connected":
|
||||
devices_data = [device for device in devices_data if device["devPresentLastScan"] == 1]
|
||||
elif status == "favorites":
|
||||
devices_data = [device for device in devices_data if device["devFavorite"] == 1]
|
||||
elif status == "new":
|
||||
devices_data = [device for device in devices_data if device["devIsNew"] == 1]
|
||||
elif status == "down":
|
||||
devices_data = [
|
||||
device for device in devices_data
|
||||
if device["devPresentLastScan"] == 0 and device["devAlertDown"]
|
||||
]
|
||||
elif status == "archived":
|
||||
devices_data = [device for device in devices_data if device["devIsArchived"] == 1]
|
||||
elif status == "offline":
|
||||
devices_data = [device for device in devices_data if device["devPresentLastScan"] == 0]
|
||||
|
||||
# sorting
|
||||
if options.sort:
|
||||
for sort_option in options.sort:
|
||||
devices_data = sorted(
|
||||
@@ -112,6 +148,13 @@ class Query(ObjectType):
|
||||
|
||||
# Filter data if a search term is provided
|
||||
if options.search:
|
||||
# Define static list of searchable fields
|
||||
searchable_fields = [
|
||||
"devName", "devMac", "devOwner", "devType", "devVendor",
|
||||
"devGroup", "devComments", "devLocation", "devStatus",
|
||||
"devSSID", "devSite", "devSourcePlugin", "devSyncHubNode"
|
||||
]
|
||||
|
||||
search_term = options.search.lower()
|
||||
|
||||
devices_data = [
|
||||
|
||||
Reference in New Issue
Block a user