diff --git a/front/devices.php b/front/devices.php index 3bb2f18c..44a8680c 100755 --- a/front/devices.php +++ b/front/devices.php @@ -378,6 +378,9 @@ function getDeviceStatus(item) // ----------------------------------------------------------------------------- function initializeDatatable_new (status) { + console.log(tableColumnVisible); + + // Build GraphQL query dynamically based on tableColumnVisible let columnsToFetch = [ 'devMac', 'devName', 'devLastConnection', 'devIsArchived', 'devOwner', 'devType', @@ -481,7 +484,7 @@ $.ajax({ } else { $(td).html(''); } - }}, + }} // Other columns (Status, MAC, Date, etc.) can be similarly customized. ], diff --git a/front/settings.php b/front/settings.php index 64e07540..f7ec5800 100755 --- a/front/settings.php +++ b/front/settings.php @@ -464,10 +464,10 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX // INPUT - // console.log(codeName); - // Parse the setType JSON string into an object let inputHtml = ''; + + console.log(codeName); console.log(setType); const setTypeObject = JSON.parse(setType.replace(/'/g, '"')); diff --git a/server/__main__.py b/server/__main__.py index 26f63a8a..ec145397 100755 --- a/server/__main__.py +++ b/server/__main__.py @@ -78,11 +78,6 @@ def main (): #=============================================================================== # 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') diff --git a/server/graphql_server/graphql_schema.py b/server/graphql_server/graphql_schema.py index c87bb591..7b4a7eac 100755 --- a/server/graphql_server/graphql_schema.py +++ b/server/graphql_server/graphql_schema.py @@ -14,12 +14,6 @@ from const import apiPath # Define a base URL with the user's home directory 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 class Device(ObjectType): rowid = Int() @@ -55,49 +49,20 @@ class Device(ObjectType): devSourcePlugin = String() # This should match devSourcePlugin, not devSourcePlugin -# Query ObjectType class Query(ObjectType): devices = List(Device) def resolve_devices(self, info): - # Map the data to match the GraphQL schema's camelCase - mapped_devices = [] - for device in devices_data: - mapped_device = { - 'rowid': device['rowid'], - 'devMac': device['devMac'], # Mapping from snake_case to camelCase - 'devName': device['devName'], - 'devOwner': device['devOwner'], - 'devType': device['devType'], - '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 + # Load JSON data only when the query executes + try: + with open(folder + 'table_devices.json', 'r') as f: + devices_data = json.load(f)["data"] + except (FileNotFoundError, json.JSONDecodeError) as e: + mylog('error', f'[graphql_schema] Error loading devices data: {e}') + return [] + + return devices_data # Directly return the data without mapping + # Schema Definition diff --git a/server/graphql_server/graphql_server_start.py b/server/graphql_server/graphql_server_start.py index dab7f025..ebb7455d 100755 --- a/server/graphql_server/graphql_server_start.py +++ b/server/graphql_server/graphql_server_start.py @@ -39,7 +39,7 @@ def graphql_endpoint(): def start_server(): """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 thread = threading.Thread(target=lambda: app.run(host="0.0.0.0", port=GRAPHQL_PORT, debug=True, use_reloader=False)) diff --git a/server/initialise.py b/server/initialise.py index bf03531d..53e01143 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -75,7 +75,7 @@ def update_or_append(settings_list, item_tuple, key): for index, item in enumerate(settings_list): if item[0] == key: mylog('trace', ['[Import Config] OLD TUPLE : ', item]) - # Keep values marked as "_KEEP_" + # Keep values marked as "_KEEP_" in existing entries updated_tuple = tuple( new_val if new_val != "_KEEP_" else old_val 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 mylog('trace', ['[Import Config] FOUND key : ', key]) 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 - - #-------------------------------------------------------------------------------