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