mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
First part of dashboard update system
This commit is contained in:
parent
de7d6cb87d
commit
8f3a49d7e9
@ -529,6 +529,19 @@ function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) {
|
||||
});
|
||||
}
|
||||
|
||||
// --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
|
||||
// These need to live outsie of the events.push() function to enable the widgets to see them
|
||||
var ajaxspecs = new Array(); // Array to hold widget refresh specifications (objects )
|
||||
var ajaxidx = 0;
|
||||
var ajaxmutex = false;
|
||||
var ajaxcntr = 0;
|
||||
|
||||
// Add a widget refresh object to the array list
|
||||
function register_ajax(ws) {
|
||||
ajaxspecs.push(ws);
|
||||
}
|
||||
// ---------------------------------------------------------------------------------------------------
|
||||
|
||||
events.push(function() {
|
||||
|
||||
// Make panels destroyable
|
||||
@ -585,6 +598,55 @@ events.push(function() {
|
||||
$('#btnstore').removeClass("invisible");
|
||||
}
|
||||
});
|
||||
|
||||
// --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
|
||||
function make_ajax_call(wd) {
|
||||
ajaxmutex = true;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: wd.url,
|
||||
dataType: 'html',
|
||||
data: wd.parms,
|
||||
|
||||
success: function(data){
|
||||
wd.callback(data);
|
||||
ajaxmutex = false;
|
||||
},
|
||||
|
||||
error: function(e){
|
||||
// alert("Error: " + e);
|
||||
ajaxmutex = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Loop through each AJAX widget refresh object, make the AJAX call and pass the
|
||||
// results back to the widget's callback function
|
||||
function executewidget() {
|
||||
if (ajaxspecs.length > 0) {
|
||||
var freq = ajaxspecs[ajaxidx].freq; // widget can specifify it should be called freq times around hte loop
|
||||
|
||||
if (!ajaxmutex) {
|
||||
if (((ajaxcntr % freq) === 0) && (typeof ajaxspecs[ajaxidx].callback === "function" )) {
|
||||
make_ajax_call(ajaxspecs[ajaxidx]);
|
||||
}
|
||||
|
||||
if (++ajaxidx >= ajaxspecs.length) {
|
||||
ajaxidx = 0;
|
||||
|
||||
if (++ajaxcntr >= 4096) {
|
||||
ajaxcntr = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function() { executewidget(); }, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// Kick it off
|
||||
executewidget();
|
||||
});
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
|
||||
@ -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");
|
||||
});
|
||||
//]]>
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user