mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
GraphQL Settings
This commit is contained in:
@@ -14,11 +14,13 @@ from helper import is_random_mac, get_number_of_children, format_ip_long, get_se
|
||||
# Define a base URL with the user's home directory
|
||||
folder = apiPath
|
||||
|
||||
# --- DEVICES ---
|
||||
# Pagination and Sorting Input Types
|
||||
class SortOptionsInput(InputObjectType):
|
||||
field = String()
|
||||
order = String()
|
||||
|
||||
|
||||
class PageQueryOptionsInput(InputObjectType):
|
||||
page = Int()
|
||||
limit = Int()
|
||||
@@ -26,6 +28,7 @@ class PageQueryOptionsInput(InputObjectType):
|
||||
search = String()
|
||||
status = String()
|
||||
|
||||
|
||||
# Device ObjectType
|
||||
class Device(ObjectType):
|
||||
rowid = Int()
|
||||
@@ -70,8 +73,30 @@ class DeviceResult(ObjectType):
|
||||
devices = List(Device)
|
||||
count = Int()
|
||||
|
||||
|
||||
# --- SETTINGS ---
|
||||
|
||||
# Setting ObjectType
|
||||
class Setting(ObjectType):
|
||||
setKey = String()
|
||||
setName = String()
|
||||
setDescription = String()
|
||||
setType = String()
|
||||
setOptions = String()
|
||||
setGroup = String()
|
||||
setValue = String()
|
||||
setEvents = String()
|
||||
setOverriddenByEnv = Boolean()
|
||||
|
||||
|
||||
class SettingResult(ObjectType):
|
||||
settings = List(Setting)
|
||||
count = Int()
|
||||
|
||||
# Define Query Type with Pagination Support
|
||||
class Query(ObjectType):
|
||||
|
||||
# --- DEVICES ---
|
||||
devices = Field(DeviceResult, options=PageQueryOptionsInput())
|
||||
|
||||
def resolve_devices(self, info, options=None):
|
||||
@@ -175,6 +200,28 @@ class Query(ObjectType):
|
||||
|
||||
return DeviceResult(devices=devices, count=total_count)
|
||||
|
||||
# --- SETTINGS ---
|
||||
settings = Field(SettingResult)
|
||||
|
||||
def resolve_settings(root, info):
|
||||
|
||||
try:
|
||||
with open(folder + 'table_settings.json', 'r') as f:
|
||||
settings_data = json.load(f)["data"]
|
||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||
mylog('none', f'[graphql_schema] Error loading settings data: {e}')
|
||||
return SettingResult(settings=[], count=0)
|
||||
|
||||
|
||||
mylog('none', f'[graphql_schema] settings_data: {settings_data}')
|
||||
|
||||
# # Convert to Setting objects
|
||||
settings = [Setting(**setting) for setting in settings_data]
|
||||
|
||||
return SettingResult(settings=settings, count=len(settings))
|
||||
|
||||
|
||||
|
||||
# helps sorting inconsistent dataset mixed integers and strings
|
||||
def mixed_type_sort_key(value):
|
||||
if value is None or value == "":
|
||||
|
||||
Reference in New Issue
Block a user