mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Filters UI_columns_filters #953
This commit is contained in:
@@ -5,7 +5,7 @@ import datetime
|
||||
|
||||
# Register NetAlertX modules
|
||||
import conf
|
||||
from const import (apiPath, sql_appevents, sql_devices_all, sql_events_pending_alert, sql_settings, sql_plugins_events, sql_plugins_history, sql_plugins_objects,sql_language_strings, sql_notifications_all, sql_online_history, sql_devices_tiles)
|
||||
from const import (apiPath, sql_appevents, sql_devices_all, sql_events_pending_alert, sql_settings, sql_plugins_events, sql_plugins_history, sql_plugins_objects,sql_language_strings, sql_notifications_all, sql_online_history, sql_devices_tiles, sql_devices_filters)
|
||||
from logger import mylog
|
||||
from helper import write_file, get_setting_value, timeNowTZ
|
||||
from app_state import updateState
|
||||
@@ -50,6 +50,7 @@ def update_api(db, all_plugins, forceUpdate, updateOnlyDataSources=[], is_ad_hoc
|
||||
["notifications", sql_notifications_all],
|
||||
["online_history", sql_online_history],
|
||||
["devices_tiles", sql_devices_tiles],
|
||||
["devices_filters", sql_devices_filters],
|
||||
["custom_endpoint", conf.API_CUSTOM_SQL],
|
||||
]
|
||||
|
||||
|
||||
@@ -105,6 +105,35 @@ sql_devices_tiles = """
|
||||
(SELECT COUNT(*) FROM MyDevicesFilter) AS my_devices
|
||||
FROM Statuses;
|
||||
"""
|
||||
sql_devices_filters = """
|
||||
SELECT DISTINCT 'devSite' AS columnName, devSite AS columnValue
|
||||
FROM Devices WHERE devSite NOT IN ('', 'null') AND devSite IS NOT NULL
|
||||
UNION
|
||||
SELECT DISTINCT 'devSourcePlugin' AS columnName, devSourcePlugin AS columnValue
|
||||
FROM Devices WHERE devSourcePlugin NOT IN ('', 'null') AND devSourcePlugin IS NOT NULL
|
||||
UNION
|
||||
SELECT DISTINCT 'devOwner' AS columnName, devOwner AS columnValue
|
||||
FROM Devices WHERE devOwner NOT IN ('', 'null') AND devOwner IS NOT NULL
|
||||
UNION
|
||||
SELECT DISTINCT 'devType' AS columnName, devType AS columnValue
|
||||
FROM Devices WHERE devType NOT IN ('', 'null') AND devType IS NOT NULL
|
||||
UNION
|
||||
SELECT DISTINCT 'devGroup' AS columnName, devGroup AS columnValue
|
||||
FROM Devices WHERE devGroup NOT IN ('', 'null') AND devGroup IS NOT NULL
|
||||
UNION
|
||||
SELECT DISTINCT 'devLocation' AS columnName, devLocation AS columnValue
|
||||
FROM Devices WHERE devLocation NOT IN ('', 'null') AND devLocation IS NOT NULL
|
||||
UNION
|
||||
SELECT DISTINCT 'devVendor' AS columnName, devVendor AS columnValue
|
||||
FROM Devices WHERE devVendor NOT IN ('', 'null') AND devVendor IS NOT NULL
|
||||
UNION
|
||||
SELECT DISTINCT 'devSyncHubNode' AS columnName, devSyncHubNode AS columnValue
|
||||
FROM Devices WHERE devSyncHubNode NOT IN ('', 'null') AND devSyncHubNode IS NOT NULL
|
||||
UNION
|
||||
SELECT DISTINCT 'devSSID' AS columnName, devSSID AS columnValue
|
||||
FROM Devices WHERE devSSID NOT IN ('', 'null') AND devSSID IS NOT NULL
|
||||
ORDER BY columnName;
|
||||
"""
|
||||
sql_devices_stats = """SELECT Online_Devices as online, Down_Devices as down, All_Devices as 'all', Archived_Devices as archived,
|
||||
(select count(*) from Devices a where devIsNew = 1 ) as new,
|
||||
(select count(*) from Devices a where devName = '(unknown)' or devName = '(name not found)' ) as unknown
|
||||
|
||||
@@ -20,6 +20,10 @@ class SortOptionsInput(InputObjectType):
|
||||
field = String()
|
||||
order = String()
|
||||
|
||||
class FilterOptionsInput(InputObjectType):
|
||||
filterColumn = String()
|
||||
filterValue = String()
|
||||
|
||||
|
||||
class PageQueryOptionsInput(InputObjectType):
|
||||
page = Int()
|
||||
@@ -27,6 +31,7 @@ class PageQueryOptionsInput(InputObjectType):
|
||||
sort = List(SortOptionsInput)
|
||||
search = String()
|
||||
status = String()
|
||||
filters = List(FilterOptionsInput)
|
||||
|
||||
|
||||
# Device ObjectType
|
||||
@@ -162,7 +167,14 @@ class Query(ObjectType):
|
||||
elif status == "offline":
|
||||
devices_data = [device for device in devices_data if device["devPresentLastScan"] == 0]
|
||||
|
||||
|
||||
# additional filters
|
||||
if options.filters:
|
||||
for filter in options.filters:
|
||||
if filter.filterColumn and filter.filterValue:
|
||||
devices_data = [
|
||||
device for device in devices_data
|
||||
if str(device.get(filter.filterColumn, "")).lower() == str(filter.filterValue).lower()
|
||||
]
|
||||
|
||||
# Filter data if a search term is provided
|
||||
if options.search:
|
||||
|
||||
Reference in New Issue
Block a user