From 705a73bda244013218028ca0818978826305bbc7 Mon Sep 17 00:00:00 2001 From: Aaron Daniels Date: Mon, 5 Sep 2016 01:32:03 +1000 Subject: [PATCH] webui: Added Pagination and server side search via Ajax to NTP (#4330) webui: Added Pagination and server side search via Ajax to NTP (#4330) --- html/includes/table/app_ntp.inc.php | 108 ++++++++++++++++++++++++++++ html/pages/apps/ntp.inc.php | 97 +++++-------------------- includes/discovery/ntp.inc.php | 2 +- includes/polling/ntp.inc.php | 2 +- 4 files changed, 129 insertions(+), 80 deletions(-) create mode 100644 html/includes/table/app_ntp.inc.php diff --git a/html/includes/table/app_ntp.inc.php b/html/includes/table/app_ntp.inc.php new file mode 100644 index 0000000000..e7c8cdba91 --- /dev/null +++ b/html/includes/table/app_ntp.inc.php @@ -0,0 +1,108 @@ +getComponents(null, $options); + +$first = $_POST['current']-1; // Which record do we start on. +$last = $first + $_POST['rowCount']; // Which record do we end on. +$count = 0; +// Loop through each device in the component array +foreach ($components as $devid => $comp) { + $device = device_by_id_cache($devid); + + // Loop through each component + foreach ($comp as $compid => $array) { + $display = true; + if ($_POST['view'] == 'error') { + // Only display peers with errors + if ($array['status'] != 2) { + $display = false; + } + } + if ($array['status'] == 2) { + $status = 'class="danger"'; + } else { + $status = ''; + } + + // Let's process some searching.. + if (($display === true) && ($_POST['searchPhrase'] != "")) { + $searchfound = false; + $searchdata = array($device['hostname'],$array['peer'],$array['stratum'],$array['error']); + foreach ($searchdata as $value) { + if (strstr($value, $_POST['searchPhrase'])) { + $searchfound = true; + } + } + + // If we didnt match this record while searching, we should exclude it from the results. + if ($searchfound === false) { + $display = false; + } + } + + if ($display === true) { + $count++; + + // If this record is in the range we want. + if (($count > $first) && ($count <= $last)) { + $device_link = generate_device_link($device, null, array('tab' => 'apps', 'app' => 'ntp')); + + $graph_array = array(); + $graph_array['device'] = $device['device_id']; + $graph_array['width'] = 80; + $graph_array['height'] = 20; + + // Which graph type do we want? + if ($_POST['graph'] == "stratum") { + $graph_array['type'] = 'device_ntp_stratum'; + } elseif ($_POST['graph'] == "offset") { + $graph_array['type'] = 'device_ntp_offset'; + } elseif ($_POST['graph'] == "delay") { + $graph_array['type'] = 'device_ntp_delay'; + } elseif ($_POST['graph'] == "dispersion") { + $graph_array['type'] = 'device_ntp_dispersion'; + } else { + // No Graph + unset($graph_array); + } + + $response[] = array( + 'device' => $device_link, + 'peer' => $array['peer'], + 'stratum' => $array['stratum'], + 'error' => $array['error'], + ); + + // Do we want a graphrow. + if (is_array($graph_array)) { + $return_data = true; + require 'includes/print-graphrow.inc.php'; + unset($return_data); + $response[] = array( + 'device' => $graph_data[0], + 'peer' => $graph_data[1], + 'stratum' => $graph_data[2], + 'error' => $graph_data[3], + ); + } + } // End if in range + } // End if display + } // End foreach component +} // End foreach device + +// If there are no results, let the user know. +if ($count == 0) { + $response = array(); +} + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $count, +); +echo _json_encode($output); diff --git a/html/pages/apps/ntp.inc.php b/html/pages/apps/ntp.inc.php index ab0f612907..e93e161033 100644 --- a/html/pages/apps/ntp.inc.php +++ b/html/pages/apps/ntp.inc.php @@ -80,86 +80,27 @@ echo ''; print_optionbar_end(); ?> - +
- - - - + + + + - $comp) { - $device = device_by_id_cache($devid); - - // Loop through each component - foreach ($comp as $compid => $array) { - $display = true; - if ($vars['view'] == 'error') { - // Only display peers with errors - if ($array['status'] != 2) { - $display = false; - } - } - if ($array['status'] == 2) { - $status = 'class="danger"'; - } else { - $status = ''; - } - - if ($display === true) { - $link = generate_device_link($device, null, array('tab' => 'apps', 'app' => 'ntp')); - $count++; -?> -> - - - - - -'; - echo ''; - echo ''; -} - } // End if display - } // End foreach component -} // End foreach device - - // If there are no results, let the user know. -if ($count == 0) { -?> - - - -
DevicePeerStratumErrorDevicePeerStratumError
'; - require 'includes/print-graphrow.inc.php'; - echo '
No Matching NTP Peers
+ diff --git a/includes/discovery/ntp.inc.php b/includes/discovery/ntp.inc.php index 60638836ca..ac4c3ed9ae 100644 --- a/includes/discovery/ntp.inc.php +++ b/includes/discovery/ntp.inc.php @@ -26,5 +26,5 @@ */ if ($device['os_group'] == 'cisco') { - require_once 'includes/discovery/ntp/cisco.inc.php'; + include 'includes/discovery/ntp/cisco.inc.php'; } diff --git a/includes/polling/ntp.inc.php b/includes/polling/ntp.inc.php index 9a1a552384..3bdb049cfe 100644 --- a/includes/polling/ntp.inc.php +++ b/includes/polling/ntp.inc.php @@ -19,5 +19,5 @@ */ if ($device['os_group'] == 'cisco') { - require_once 'includes/polling/ntp/cisco.inc.php'; + include 'includes/polling/ntp/cisco.inc.php'; }