mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-03-30 23:03:03 -07:00
Add db_count to DeviceResult and update GraphQL response handling; localize Device_NoMatch_Title in multiple languages
This commit is contained in:
@@ -108,6 +108,7 @@ class Device(ObjectType):
|
||||
class DeviceResult(ObjectType):
|
||||
devices = List(Device)
|
||||
count = Int()
|
||||
db_count = Int(description="Total device count in the database, before any status/filter/search is applied")
|
||||
|
||||
|
||||
# --- SETTINGS ---
|
||||
@@ -198,7 +199,7 @@ class Query(ObjectType):
|
||||
devices_data = json.load(f)["data"]
|
||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||
mylog("none", f"[graphql_schema] Error loading devices data: {e}")
|
||||
return DeviceResult(devices=[], count=0)
|
||||
return DeviceResult(devices=[], count=0, db_count=0)
|
||||
|
||||
# Int fields that may arrive from the DB as empty strings — coerce to None
|
||||
_INT_FIELDS = [
|
||||
@@ -223,6 +224,10 @@ class Query(ObjectType):
|
||||
|
||||
mylog("trace", f"[graphql_schema] devices_data: {devices_data}")
|
||||
|
||||
# Raw DB count — before any status, filter, or search is applied.
|
||||
# Used by the frontend to distinguish "no devices in DB" from "filter returned nothing".
|
||||
db_count = len(devices_data)
|
||||
|
||||
# initialize total_count
|
||||
total_count = len(devices_data)
|
||||
|
||||
@@ -439,7 +444,7 @@ class Query(ObjectType):
|
||||
# Convert dict objects to Device instances to enable field resolution
|
||||
devices = [Device(**device) for device in devices_data]
|
||||
|
||||
return DeviceResult(devices=devices, count=total_count)
|
||||
return DeviceResult(devices=devices, count=total_count, db_count=db_count)
|
||||
|
||||
# --- SETTINGS ---
|
||||
settings = Field(SettingResult, filters=List(FilterOptionsInput))
|
||||
|
||||
Reference in New Issue
Block a user