summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/widgets
diff options
context:
space:
mode:
authorSteve Beaver <sbeaver@netgate.com>2017-08-14 15:51:01 -0400
committerSteve Beaver <sbeaver@netgate.com>2017-08-14 17:46:28 -0400
commit8f3a49d7e9c22af2c97f92007aa23d2a45c8e697 (patch)
tree567e35011829b3a66cf5cee178093b6df46db3f0 /src/usr/local/www/widgets
parentde7d6cb87d600c6e093aa3e9f76246fe62824ac7 (diff)
downloadpfsense-8f3a49d7e9c22af2c97f92007aa23d2a45c8e697.zip
pfsense-8f3a49d7e9c22af2c97f92007aa23d2a45c8e697.tar.gz
First part of dashboard update system
Diffstat (limited to 'src/usr/local/www/widgets')
-rw-r--r--src/usr/local/www/widgets/widgets/gateways.widget.php64
-rw-r--r--src/usr/local/www/widgets/widgets/interface_statistics.widget.php44
-rw-r--r--src/usr/local/www/widgets/widgets/interfaces.widget.php40
-rw-r--r--src/usr/local/www/widgets/widgets/system_information.widget.php67
4 files changed, 133 insertions, 82 deletions
diff --git a/src/usr/local/www/widgets/widgets/gateways.widget.php b/src/usr/local/www/widgets/widgets/gateways.widget.php
index f4408b8..35abec8 100644
--- a/src/usr/local/www/widgets/widgets/gateways.widget.php
+++ b/src/usr/local/www/widgets/widgets/gateways.widget.php
@@ -199,36 +199,6 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period
</div>
</form>
-<script>
-//<![CDATA[
-
- function get_gw_stats() {
- var ajaxRequest;
-
- ajaxRequest = $.ajax({
- url: "/widgets/widgets/gateways.widget.php",
- type: "post",
- data: { ajax: "ajax"}
- });
-
- // Deal with the results of the above ajax call
- ajaxRequest.done(function (response, textStatus, jqXHR) {
- $('#gwtblbody').html(response);
- // and do it again
- setTimeout(get_gw_stats, "<?=$widgetperiod?>");
- });
- }
-
- events.push(function(){
- set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallgateways");
-
- // Start polling for updates some small random number of seconds from now (so that all the widgets don't
- // hit the server at exactly the same time)
- setTimeout(get_gw_stats, Math.floor((Math.random() * 10000) + 1000));
- });
-//]]>
-</script>
-
<?php
function compose_table_body_contents() {
global $user_settings;
@@ -359,3 +329,37 @@ function compose_table_body_contents() {
return($rtnstr);
}
?>
+
+<script>
+//<![CDATA[
+
+events.push(function(){
+ // --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
+
+ // Callback function called by refresh system when data is retrieved
+ function gateways_callback(s) {
+ $('#gwtblbody').html(s);
+ }
+
+ // POST data to send via AJAX
+ var postdata = {
+ ajax: "ajax",
+ widgetkey : "<?=$widgetkey?>"
+ };
+
+ // Create an object defining the widget refresh AJAX call
+ var gatewaysObject = new Object();
+ gatewaysObject.name = "Gateways";
+ gatewaysObject.url = "/widgets/widgets/gateways.widget.php";
+ gatewaysObject.callback = gateways_callback;
+ gatewaysObject.parms = postdata;
+ gatewaysObject.freq = 1;
+
+ // Register the AJAX object
+ register_ajax(gatewaysObject);
+
+ // ---------------------------------------------------------------------------------------------------
+});
+
+//]]>
+</script>
diff --git a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php
index ff2cc29..f4e349f 100644
--- a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php
+++ b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php
@@ -201,31 +201,57 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period
<script type="text/javascript">
//<![CDATA[
-
- function get_if_stats() {
+/*
+ function get_if_stats_<?=$widgetkey_nodash?>() {
var ajaxRequest;
ajaxRequest = $.ajax({
url: "/widgets/widgets/interface_statistics.widget.php",
type: "post",
- data: { ajax: "ajax"}
+ data: { ajax: "ajax", widgetkey: "<?=$widgetkey?>"}
});
// Deal with the results of the above ajax call
ajaxRequest.done(function (response, textStatus, jqXHR) {
- $('#iftbl').html(response);
+ $('#<?=$widgetkey?>-iftbl').html(response);
// and do it again
- setTimeout(get_if_stats, "<?=$widgetperiod?>");
+ setTimeout(get_if_stats_<?=$widgetkey_nodash?>, "<?=$widgetperiod?>");
});
}
+*/
+ events.push(function() {
+ // --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
- events.push(function(){
+ // Callback function called by refresh system when data is retrieved
+ function interface_statistics_callback(s) {
+ $('#iftbl').html(s);
+ }
+
+ // POST data to send via AJAX
+ var postdata = {
+ ajax : "ajax",
+ widgetkey :"<?=$widgetkey?>"
+ };
+
+ // Create an object defining the widget refresh AJAX call
+ var ifstatObject = new Object();
+ ifstatObject.name = "IFstats";
+ ifstatObject.url = "/widgets/widgets/interface_statistics.widget.php";
+ ifstatObject.callback = interface_statistics_callback;
+ ifstatObject.parms = postdata;
+ ifstatObject.freq = 1;
+
+ // Register the AJAX object
+ register_ajax(ifstatObject);
+
+ // ---------------------------------------------------------------------------------------------------
+ // Note: This manages all settings checkboxes with id starting with "show"
+ // (i.e. both the interface and stats item selection groups)
+ // using a single All/None button
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallinterfacesforstats");
- // Start polling for updates some small random number of seconds from now (so that all the widgets don't
- // hit the server at exactly the same time)
- setTimeout(get_if_stats, Math.floor((Math.random() * 10000) + 1000));
});
//]]>
</script>
+
diff --git a/src/usr/local/www/widgets/widgets/interfaces.widget.php b/src/usr/local/www/widgets/widgets/interfaces.widget.php
index df3b717..1337c1c 100644
--- a/src/usr/local/www/widgets/widgets/interfaces.widget.php
+++ b/src/usr/local/www/widgets/widgets/interfaces.widget.php
@@ -61,7 +61,7 @@ require_once("/usr/local/www/widgets/include/interfaces.inc");
$ifdescrs = get_configured_interface_with_descr();
-if ($_POST) {
+if ($_POST && !$_REQUEST['ajax']) {
$validNames = array();
@@ -79,9 +79,11 @@ if ($_POST) {
header("Location: /index.php");
}
+if (!$_REQUEST['ajax']) {
?>
-<div class="table-responsive">
+<div id="ifaces_status" class="table-responsive">
+ <?php } ?>
<table class="table table-striped table-hover table-condensed">
<tbody>
<?php
@@ -174,7 +176,15 @@ endif;
?>
</tbody>
</table>
+
+<?php
+/* for AJAX response, we only need the panels */
+if ($_REQUEST['ajax']) {
+ exit;
+}
+?>
</div>
+
<!-- close the body we're wrapped in and add a configuration-panel -->
</div><div id="widget-<?=$widgetname?>_panel-footer" class="panel-footer collapse">
@@ -220,6 +230,32 @@ endif;
<script>
//<![CDATA[
events.push(function(){
+
+ // --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
+
+ // Callback function called by refresh system when data is retrieved
+ function interfaces_callback(s) {
+ $('#ifaces_status').html(s);
+ }
+
+ // POST data to send via AJAX
+ var postdata = {
+ widgetkey :"<?=$widgetkey?>",
+ ajax: "ajax"
+ };
+
+ // Create an object defining the widget refresh AJAX call
+ var interfacesObject = new Object();
+ interfacesObject.name = "Interfaces";
+ interfacesObject.url = "/widgets/widgets/interfaces.widget.php";
+ interfacesObject.callback = interfaces_callback;
+ interfacesObject.parms = postdata;
+ interfacesObject.freq = 1;
+
+ // Register the AJAX object
+ register_ajax(interfacesObject);
+
+ // ---------------------------------------------------------------------------------------------------
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallinterfaces");
});
//]]>
diff --git a/src/usr/local/www/widgets/widgets/system_information.widget.php b/src/usr/local/www/widgets/widgets/system_information.widget.php
index 868554e..fd7295d 100644
--- a/src/usr/local/www/widgets/widgets/system_information.widget.php
+++ b/src/usr/local/www/widgets/widgets/system_information.widget.php
@@ -553,41 +553,6 @@ $rows_displayed = false;
<script type="text/javascript">
//<![CDATA[
-<?php if (!isset($config['system']['firmware']['disablecheck'])): ?>
-function systemStatusGetUpdateStatus() {
- $.ajax({
- type: 'get',
- url: '/widgets/widgets/system_information.widget.php',
- data: 'getupdatestatus=1',
- dataFilter: function(raw){
- // We reload the entire widget, strip this block of javascript from it
- return raw.replace(/<script>([\s\S]*)<\/script>/gi, '');
- },
- dataType: 'html',
- success: function(data){
- $('#widget-system_information #updatestatus').html(data);
- }
- });
-}
-
-setTimeout('systemStatusGetUpdateStatus()', 4000);
-<?php endif; ?>
-
-function updateMeters() {
- url = '/getstats.php';
-
- $.ajax(url, {
- type: 'get',
- success: function(data) {
- response = data || "";
- if (response != "")
- stats(data);
- }
- });
-
- setTimer();
-
-}
events.push(function(){
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallsysinfoitems");
@@ -599,10 +564,6 @@ function setProgress(barName, percent) {
$('#' + barName).css('width', percent + '%').attr('aria-valuenow', percent);
}
-function setTimer() {
- timeout = window.setTimeout('updateMeters()', update_interval);
-}
-
function stats(x) {
var values = x.split("|");
if ($.each(values,function(key,value) {
@@ -773,9 +734,33 @@ function widgetActive(x) {
}
}
-/* start updater */
+
events.push(function(){
- setTimer();
+ // --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
+
+ // Callback function called by refresh system when data is retrieved
+ function meters_callback(s) {
+ stats(s);
+ }
+
+ // POST data to send via AJAX
+ var postdata = {
+ ajax: "ajax"
+ };
+
+ // Create an object defining the widget refresh AJAX call
+ var metersObject = new Object();
+ metersObject.name = "Meters";
+ metersObject.url = "/getstats.php";
+ metersObject.callback = meters_callback;
+ metersObject.parms = postdata;
+ metersObject.freq = 1;
+
+ // Register the AJAX object
+ register_ajax(metersObject);
+
+ //set_widget_checkbox_events("#<?=$widget_panel_footer_id?> [id^=show]", "<?=$widget_showallnone_id?>");
+
});
//]]>
</script>
OpenPOWER on IntegriCloud