GraphQl 0.11.17.1 - better api_token initialization + device tiles

This commit is contained in:
jokob-sk
2024-11-17 14:35:39 +11:00
parent 6407ee5c13
commit 78fc9214bb
6 changed files with 140 additions and 66 deletions

View File

@@ -62,6 +62,7 @@ class Device(ObjectType):
devIsRandomMac = Int()
devParentChildrenCount = Int()
devIpLong = Int()
devFilterStatus = String()
class DeviceResult(ObjectType):
@@ -92,6 +93,13 @@ 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:
if options.sort:
@@ -104,9 +112,14 @@ class Query(ObjectType):
# Filter data if a search term is provided
if options.search:
search_term = options.search.lower()
devices_data = [
device for device in devices_data
if options.search.lower() in device.get("devName", "").lower()
if any(
search_term in str(device.get(field, "")).lower()
for field in searchable_fields # Search only predefined fields
)
]
# Then apply pagination

View File

@@ -38,11 +38,11 @@ def graphql_endpoint():
# Return the result as JSON
return jsonify(result.data)
def start_server(graphql_port):
def start_server(graphql_port, app_state):
"""Start the GraphQL server in a background thread."""
state = updateState("GraphQL: Starting", None, None, None, None)
if state.graphQLServerStarted == 0:
if app_state.graphQLServerStarted == 0:
mylog('verbose', [f'[graphql_server] Starting on port: {graphql_port}'])
# Start Flask app in a separate thread
@@ -57,4 +57,4 @@ def start_server(graphql_port):
thread.start()
# Update the state to indicate the server has started
state = updateState("Process: Wait", None, None, None, 1)
app_state = updateState("Process: Wait", None, None, None, 1)