mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
GraphQL 0.11 - Load devices json on Query, _KEEP_ bugfix for old settings
This commit is contained in:
@@ -378,6 +378,9 @@ function getDeviceStatus(item)
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
function initializeDatatable_new (status) {
|
function initializeDatatable_new (status) {
|
||||||
|
|
||||||
|
console.log(tableColumnVisible);
|
||||||
|
|
||||||
|
|
||||||
// Build GraphQL query dynamically based on tableColumnVisible
|
// Build GraphQL query dynamically based on tableColumnVisible
|
||||||
let columnsToFetch = [
|
let columnsToFetch = [
|
||||||
'devMac', 'devName', 'devLastConnection', 'devIsArchived', 'devOwner', 'devType',
|
'devMac', 'devName', 'devLastConnection', 'devIsArchived', 'devOwner', 'devType',
|
||||||
@@ -481,7 +484,7 @@ $.ajax({
|
|||||||
} else {
|
} else {
|
||||||
$(td).html('');
|
$(td).html('');
|
||||||
}
|
}
|
||||||
}},
|
}}
|
||||||
|
|
||||||
// Other columns (Status, MAC, Date, etc.) can be similarly customized.
|
// Other columns (Status, MAC, Date, etc.) can be similarly customized.
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -464,10 +464,10 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
|
|||||||
|
|
||||||
// INPUT
|
// INPUT
|
||||||
|
|
||||||
// console.log(codeName);
|
|
||||||
|
|
||||||
// Parse the setType JSON string into an object
|
// Parse the setType JSON string into an object
|
||||||
let inputHtml = '';
|
let inputHtml = '';
|
||||||
|
|
||||||
|
console.log(codeName);
|
||||||
console.log(setType);
|
console.log(setType);
|
||||||
|
|
||||||
const setTypeObject = JSON.parse(setType.replace(/'/g, '"'));
|
const setTypeObject = JSON.parse(setType.replace(/'/g, '"'));
|
||||||
|
|||||||
@@ -78,11 +78,6 @@ def main ():
|
|||||||
#===============================================================================
|
#===============================================================================
|
||||||
# This is the main loop of NetAlertX
|
# This is the main loop of NetAlertX
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
mylog('debug', '[MAIN] Starting GraphQL server')
|
|
||||||
|
|
||||||
# Path to your `graphql_server.py` file
|
|
||||||
flask_app_path = applicationPath + '/server/graphql_server.py'
|
|
||||||
|
|
||||||
mylog('debug', '[MAIN] Starting loop')
|
mylog('debug', '[MAIN] Starting loop')
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,6 @@ from const import apiPath
|
|||||||
# Define a base URL with the user's home directory
|
# Define a base URL with the user's home directory
|
||||||
folder = apiPath
|
folder = apiPath
|
||||||
|
|
||||||
# Load your JSON data
|
|
||||||
with open(folder + 'table_devices.json', 'r') as f:
|
|
||||||
devices_data = json.load(f)["data"]
|
|
||||||
|
|
||||||
# mylog('none', [f'[graphql_schema] devices_data {devices_data}'])
|
|
||||||
|
|
||||||
# Device ObjectType
|
# Device ObjectType
|
||||||
class Device(ObjectType):
|
class Device(ObjectType):
|
||||||
rowid = Int()
|
rowid = Int()
|
||||||
@@ -55,49 +49,20 @@ class Device(ObjectType):
|
|||||||
devSourcePlugin = String() # This should match devSourcePlugin, not devSourcePlugin
|
devSourcePlugin = String() # This should match devSourcePlugin, not devSourcePlugin
|
||||||
|
|
||||||
|
|
||||||
# Query ObjectType
|
|
||||||
class Query(ObjectType):
|
class Query(ObjectType):
|
||||||
devices = List(Device)
|
devices = List(Device)
|
||||||
|
|
||||||
def resolve_devices(self, info):
|
def resolve_devices(self, info):
|
||||||
# Map the data to match the GraphQL schema's camelCase
|
# Load JSON data only when the query executes
|
||||||
mapped_devices = []
|
try:
|
||||||
for device in devices_data:
|
with open(folder + 'table_devices.json', 'r') as f:
|
||||||
mapped_device = {
|
devices_data = json.load(f)["data"]
|
||||||
'rowid': device['rowid'],
|
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||||
'devMac': device['devMac'], # Mapping from snake_case to camelCase
|
mylog('error', f'[graphql_schema] Error loading devices data: {e}')
|
||||||
'devName': device['devName'],
|
return []
|
||||||
'devOwner': device['devOwner'],
|
|
||||||
'devType': device['devType'],
|
return devices_data # Directly return the data without mapping
|
||||||
'devVendor': device['devVendor'],
|
|
||||||
'devFavorite': device['devFavorite'],
|
|
||||||
'devGroup': device['devGroup'],
|
|
||||||
'devComments': device['devComments'],
|
|
||||||
'devFirstConnection': device['devFirstConnection'],
|
|
||||||
'devLastConnection': device['devLastConnection'],
|
|
||||||
'devLastIP': device['devLastIP'],
|
|
||||||
'devStaticIP': device['devStaticIP'],
|
|
||||||
'devScan': device['devScan'],
|
|
||||||
'devLogEvents': device['devLogEvents'],
|
|
||||||
'devAlertEvents': device['devAlertEvents'],
|
|
||||||
'devAlertDown': device['devAlertDown'],
|
|
||||||
'devSkipRepeated': device['devSkipRepeated'],
|
|
||||||
'devLastNotification': device['devLastNotification'],
|
|
||||||
'devPresentLastScan': device['devPresentLastScan'],
|
|
||||||
'devIsNew': device['devIsNew'],
|
|
||||||
'devLocation': device['devLocation'],
|
|
||||||
'devIsArchived': device['devIsArchived'],
|
|
||||||
'devParentMAC': device['devParentMAC'],
|
|
||||||
'devParentPort': device['devParentPort'],
|
|
||||||
'devIcon': device['devIcon'],
|
|
||||||
'devGUID': device['devGUID'],
|
|
||||||
'devSite': device['devSite'],
|
|
||||||
'devSSID': device['devSSID'],
|
|
||||||
'devSyncHubNode': device['devSyncHubNode'],
|
|
||||||
'devSourcePlugin': device['devSourcePlugin']
|
|
||||||
}
|
|
||||||
mapped_devices.append(mapped_device)
|
|
||||||
return mapped_devices
|
|
||||||
|
|
||||||
|
|
||||||
# Schema Definition
|
# Schema Definition
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def graphql_endpoint():
|
|||||||
|
|
||||||
def start_server():
|
def start_server():
|
||||||
"""Function to start the GraphQL server in a background thread."""
|
"""Function to start the GraphQL server in a background thread."""
|
||||||
mylog('none', [f'[graphql_server] Started'])
|
mylog('none', [f'[graphql_server] Starting on port "{GRAPHQL_PORT}"'])
|
||||||
|
|
||||||
# Start the Flask app in a separate thread
|
# Start the Flask app in a separate thread
|
||||||
thread = threading.Thread(target=lambda: app.run(host="0.0.0.0", port=GRAPHQL_PORT, debug=True, use_reloader=False))
|
thread = threading.Thread(target=lambda: app.run(host="0.0.0.0", port=GRAPHQL_PORT, debug=True, use_reloader=False))
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ def update_or_append(settings_list, item_tuple, key):
|
|||||||
for index, item in enumerate(settings_list):
|
for index, item in enumerate(settings_list):
|
||||||
if item[0] == key:
|
if item[0] == key:
|
||||||
mylog('trace', ['[Import Config] OLD TUPLE : ', item])
|
mylog('trace', ['[Import Config] OLD TUPLE : ', item])
|
||||||
# Keep values marked as "_KEEP_"
|
# Keep values marked as "_KEEP_" in existing entries
|
||||||
updated_tuple = tuple(
|
updated_tuple = tuple(
|
||||||
new_val if new_val != "_KEEP_" else old_val
|
new_val if new_val != "_KEEP_" else old_val
|
||||||
for old_val, new_val in zip(item, item_tuple)
|
for old_val, new_val in zip(item, item_tuple)
|
||||||
@@ -84,12 +84,15 @@ def update_or_append(settings_list, item_tuple, key):
|
|||||||
settings_list[index] = updated_tuple
|
settings_list[index] = updated_tuple
|
||||||
mylog('trace', ['[Import Config] FOUND key : ', key])
|
mylog('trace', ['[Import Config] FOUND key : ', key])
|
||||||
return settings_list
|
return settings_list
|
||||||
|
|
||||||
|
|
||||||
settings_list.append(item_tuple)
|
# Append the item only if no values are "_KEEP_"
|
||||||
|
if "_KEEP_" not in item_tuple:
|
||||||
|
settings_list.append(item_tuple)
|
||||||
|
mylog('trace', ['[Import Config] ADDED key : ', key])
|
||||||
|
else:
|
||||||
|
mylog('none', ['[Import Config] Skipped saving _KEEP_ for key : ', key])
|
||||||
|
|
||||||
return settings_list
|
return settings_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user