mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-15 22:51:37 -07:00
GraphQL 0.12 - devices.php use
This commit is contained in:
+81
-23
@@ -159,6 +159,7 @@
|
||||
var tableColumnHide = [];
|
||||
var tableColumnOrder = [];
|
||||
var tableColumnVisible = [];
|
||||
headersDefaultOrder = [];
|
||||
|
||||
// Read parameters & Initialize components
|
||||
callAfterAppInitialized(main)
|
||||
@@ -171,7 +172,7 @@ function main () {
|
||||
|
||||
//initialize the table headers in the correct order
|
||||
var availableColumns = getSettingOptions("UI_device_columns").split(",");
|
||||
var headersDefaultOrder = availableColumns.map(val => getString(val));
|
||||
headersDefaultOrder = availableColumns.map(val => getString(val));
|
||||
var selectedColumns = JSON.parse(getSetting("UI_device_columns").replace(/'/g, '"'));
|
||||
|
||||
// generate default order lists of given length
|
||||
@@ -197,18 +198,6 @@ function main () {
|
||||
// Concatenate the inputArray with the missingNumbers
|
||||
tableColumnOrder = [...tableColumnVisible, ...missingNumbers];
|
||||
|
||||
// render table headers
|
||||
html = '';
|
||||
|
||||
for(index = 0; index < tableColumnOrder.length; index++)
|
||||
{
|
||||
html += '<th>' + headersDefaultOrder[tableColumnOrder[index]] + '</th>';
|
||||
}
|
||||
|
||||
$('#tableDevices tr').html(html);
|
||||
|
||||
hideUIelements("UI_DEV_SECTIONS")
|
||||
|
||||
// Initialize components with parameters
|
||||
initializeDatatable(getUrlAnchor('my_devices'));
|
||||
|
||||
@@ -376,12 +365,13 @@ function getDeviceStatus(item)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function initializeDatatable_new (status) {
|
||||
function initializeDatatable_n (status) {
|
||||
|
||||
console.log(tableColumnVisible);
|
||||
console.log(tableColumnVisible);
|
||||
|
||||
|
||||
// Build GraphQL query dynamically based on tableColumnVisible
|
||||
let requiredColumns = ['devMac', 'devName', 'devIsNew', 'devPresentLastScan', 'devAlertDown', 'devIsArchived']
|
||||
let columnsToFetch = [
|
||||
'devMac', 'devName', 'devLastConnection', 'devIsArchived', 'devOwner', 'devType',
|
||||
'devIcon', 'devFavorite', 'devGroup', 'devFirstConnection', 'devLastIP', 'devNetworkNodeMAC',
|
||||
@@ -391,6 +381,8 @@ let columnsToFetch = [
|
||||
|
||||
let selectedColumns = columnsToFetch.filter(col => tableColumnVisible.includes(col));
|
||||
|
||||
|
||||
|
||||
// Construct the GraphQL query
|
||||
let graphqlQuery = `
|
||||
query {
|
||||
@@ -536,9 +528,10 @@ $.ajax({
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------
|
||||
function initializeDatatable (status) {
|
||||
|
||||
|
||||
if(!status)
|
||||
{
|
||||
status = 'my_devices'
|
||||
@@ -565,6 +558,17 @@ function initializeDatatable (status) {
|
||||
$('#tableDevicesBox')[0].className = 'box box-'+ color;
|
||||
$('#tableDevicesTitle').html (tableTitle);
|
||||
|
||||
// render table headers
|
||||
html = '';
|
||||
|
||||
for(index = 0; index < tableColumnOrder.length; index++)
|
||||
{
|
||||
html += '<th>' + headersDefaultOrder[tableColumnOrder[index]] + '</th>';
|
||||
}
|
||||
|
||||
$('#tableDevices tr').html(html);
|
||||
|
||||
hideUIelements("UI_DEV_SECTIONS")
|
||||
|
||||
for(i = 0; i < tableColumnOrder.length; i++)
|
||||
{
|
||||
@@ -575,18 +579,70 @@ function initializeDatatable (status) {
|
||||
}
|
||||
}
|
||||
|
||||
$.get('api/table_devices.json?nocache=' + Date.now(), function(result) {
|
||||
// Construct the GraphQL query
|
||||
let graphqlQuery = `
|
||||
query {
|
||||
devices {
|
||||
rowid
|
||||
devMac
|
||||
devName
|
||||
devOwner
|
||||
devType
|
||||
devVendor
|
||||
devFavorite
|
||||
devGroup
|
||||
devComments
|
||||
devFirstConnection
|
||||
devLastConnection
|
||||
devLastIP
|
||||
devStaticIP
|
||||
devScan
|
||||
devLogEvents
|
||||
devAlertEvents
|
||||
devAlertDown
|
||||
devSkipRepeated
|
||||
devLastNotification
|
||||
devPresentLastScan
|
||||
devIsNew
|
||||
devLocation
|
||||
devIsArchived
|
||||
devParentMAC
|
||||
devParentPort
|
||||
devIcon
|
||||
devGUID
|
||||
devSite
|
||||
devSSID
|
||||
devSyncHubNode
|
||||
devSourcePlugin
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
console.log(graphqlQuery);
|
||||
|
||||
|
||||
$.ajax({
|
||||
url: 'php/server/query_graphql.php', // PHP endpoint that proxies to the GraphQL server
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
query: graphqlQuery,
|
||||
variables: {} // Optional: pass variables if needed
|
||||
}),
|
||||
success: function(result) {
|
||||
|
||||
// refresh devices cache
|
||||
devicesListAll_JSON = result["data"]
|
||||
devicesListAll_JSON = result["devices"];
|
||||
console.log(devicesListAll_JSON);
|
||||
|
||||
devicesListAll_JSON_str = JSON.stringify(devicesListAll_JSON)
|
||||
setCache('devicesListAll_JSON', devicesListAll_JSON_str)
|
||||
|
||||
// query data
|
||||
getDevicesTotals(result.data);
|
||||
getDevicesTotals(result.devices);
|
||||
|
||||
// Filter the data based on deviceStatus
|
||||
var filteredData = filterDataByStatus(result.data, deviceStatus);
|
||||
var filteredData = filterDataByStatus(result.devices, deviceStatus);
|
||||
|
||||
// Convert JSON data into the desired format
|
||||
var dataArray = {
|
||||
@@ -598,7 +654,6 @@ function initializeDatatable (status) {
|
||||
item.devIcon || "",
|
||||
item.devFavorite || "",
|
||||
item.devGroup || "",
|
||||
// ---
|
||||
item.devFirstConnection || "",
|
||||
item.devLastConnection || "",
|
||||
item.devLastIP || "",
|
||||
@@ -608,7 +663,7 @@ function initializeDatatable (status) {
|
||||
formatIPlong(item.devLastIP) || "", // IP orderable
|
||||
item.rowid || "",
|
||||
item.devParentMAC || "",
|
||||
getNumberOfChildren(item.devMac, result.data) || 0,
|
||||
getNumberOfChildren(item.devMac, result.devices) || 0,
|
||||
item.devLocation || "",
|
||||
item.devVendor || "",
|
||||
item.devParentPort || 0,
|
||||
@@ -836,7 +891,10 @@ function initializeDatatable (status) {
|
||||
|
||||
hideSpinner();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -17,36 +17,36 @@ folder = apiPath
|
||||
# Device ObjectType
|
||||
class Device(ObjectType):
|
||||
rowid = Int()
|
||||
devMac = String() # This should match devMac, not devMac
|
||||
devName = String() # This should match devName, not devName
|
||||
devOwner = String() # This should match devOwner, not devOwner
|
||||
devType = String() # This should match devType, not devType
|
||||
devVendor = String() # This should match devVendor, not devVendor
|
||||
devFavorite = Int() # This should match devFavorite, not devFavorite
|
||||
devGroup = String() # This should match devGroup, not devGroup
|
||||
devComments = String() # This should match devComments, not devComments
|
||||
devFirstConnection = String() # This should match devFirstConnection, not devFirstConnection
|
||||
devLastConnection = String() # This should match devLastConnection, not devLastConnection
|
||||
devLastIP = String() # This should match devLastIP, not devLastIP
|
||||
devStaticIP = Int() # This should match devStaticIP, not devStaticIP
|
||||
devScan = Int() # This should match devScan, not devScan
|
||||
devLogEvents = Int() # This should match devLogEvents, not devLogEvents
|
||||
devAlertEvents = Int() # This should match devAlertEvents, not devAlertEvents
|
||||
devAlertDeviceDown = Int() # This should match devAlertDeviceDown, not devAlertDown
|
||||
devSkipRepeated = Int() # This should match devSkipRepeated, not devSkipRepeated
|
||||
devLastNotification = String() # This should match devLastNotification, not devLastNotification
|
||||
devPresentLastScan = Int() # This should match devPresentLastScan, not devPresentLastScan
|
||||
devNewDevice = Int() # This should match devNewDevice, not devIsNew
|
||||
devLocation = String() # This should match devLocation, not devLocation
|
||||
devArchived = Int() # This should match devArchived, not devIsArchived
|
||||
devNetworkNodeMACADDR = String() # This should match devNetworkNodeMACADDR, not devParentMAC
|
||||
devNetworkNodePort = String() # This should match devNetworkNodePort, not devParentPort
|
||||
devIcon = String() # This should match devIcon, not devIcon
|
||||
devGUID = String() # This should match devGUID, not devGUID
|
||||
devNetworkSite = String() # This should match devNetworkSite, not devSite
|
||||
devSSID = String() # This should match devSSID, not devSSID
|
||||
devSyncHubNodeName = String() # This should match devSyncHubNodeName, not devSyncHubNode
|
||||
devSourcePlugin = String() # This should match devSourcePlugin, not devSourcePlugin
|
||||
devMac = String()
|
||||
devName = String()
|
||||
devOwner = String()
|
||||
devType = String()
|
||||
devVendor = String()
|
||||
devFavorite = Int()
|
||||
devGroup = String()
|
||||
devComments = String()
|
||||
devFirstConnection = String()
|
||||
devLastConnection = String()
|
||||
devLastIP = String()
|
||||
devStaticIP = Int()
|
||||
devScan = Int()
|
||||
devLogEvents = Int()
|
||||
devAlertEvents = Int()
|
||||
devAlertDown = Int()
|
||||
devSkipRepeated = Int()
|
||||
devLastNotification = String()
|
||||
devPresentLastScan = Int()
|
||||
devIsNew = Int()
|
||||
devLocation = String()
|
||||
devIsArchived = Int()
|
||||
devParentMAC = String()
|
||||
devParentPort = String()
|
||||
devIcon = String()
|
||||
devGUID = String()
|
||||
devSite = String()
|
||||
devSSID = String()
|
||||
devSyncHubNode = String()
|
||||
devSourcePlugin = String()
|
||||
|
||||
|
||||
class Query(ObjectType):
|
||||
@@ -68,7 +68,7 @@ class Query(ObjectType):
|
||||
# Schema Definition
|
||||
devicesSchema = graphene.Schema(query=Query)
|
||||
|
||||
|
||||
# # Sample query
|
||||
# $.ajax({
|
||||
# url: 'php/server/query_graphql.php', // The PHP endpoint that proxies to the GraphQL server
|
||||
# type: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user