2018-09-11 21:00:23 +02:00
|
|
|
(function($, _t) {
|
2018-09-10 16:53:05 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Morris.js barchart.
|
|
|
|
*/
|
|
|
|
function CreateBarChart(placeholder, datasizeunits) {
|
|
|
|
var barchart = new Morris.Bar({
|
|
|
|
element: placeholder,
|
|
|
|
xkey: 'date',
|
|
|
|
ykeys: ['rx', 'tx'],
|
2019-02-27 20:42:36 +01:00
|
|
|
labels: [_t['receive']+' '+datasizeunits.toUpperCase(),
|
|
|
|
_t['send']+' '+datasizeunits.toUpperCase()]
|
2018-09-10 16:53:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return barchart;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-14 01:06:13 +02:00
|
|
|
* Create a jquery bootstrap datatable.
|
2018-09-10 16:53:05 +02:00
|
|
|
*/
|
2018-09-10 21:41:35 +02:00
|
|
|
function CreateDataTable(placeholder, timeunits) {
|
2018-09-11 21:00:23 +02:00
|
|
|
$("#"+placeholder).append('<table id="tableBandwidth'+timeunits+
|
|
|
|
'" class="table table-responsive table-striped container-fluid"><thead>'+
|
|
|
|
'<tr><th>date</th><th>rx</th><th>tx</th></tr></thead><tbody></tbody></table>');
|
2018-09-10 16:53:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Figure out which tab is selected and remove all existing charts and then
|
|
|
|
* construct the proper barchart.
|
|
|
|
*/
|
|
|
|
function ShowBandwidthChartHandler(e) {
|
2018-09-10 21:41:35 +02:00
|
|
|
// Remove all morrisjs charts
|
2019-02-27 20:42:36 +01:00
|
|
|
$('#divChartBandwidthhourly').empty();
|
2018-09-14 01:06:13 +02:00
|
|
|
$('#divChartBandwidthdaily').empty();
|
|
|
|
$('#divChartBandwidthmonthly').empty();
|
2018-09-10 21:41:35 +02:00
|
|
|
// Remove all datatables
|
2019-02-27 20:42:36 +01:00
|
|
|
$('#divTableBandwidthhourly').empty();
|
2018-09-14 01:06:13 +02:00
|
|
|
$('#divTableBandwidthdaily').empty();
|
|
|
|
$('#divTableBandwidthmonthly').empty();
|
2018-09-10 21:41:35 +02:00
|
|
|
// Construct ajax uri for getting the proper data.
|
2018-09-14 01:06:13 +02:00
|
|
|
var timeunit = $('ul#tabbarBandwidth li.active a').attr('href').substr(1);
|
2018-09-10 16:53:05 +02:00
|
|
|
var uri = 'ajax/bandwidth/get_bandwidth.php?';
|
|
|
|
uri += 'inet=';
|
2018-09-14 01:06:13 +02:00
|
|
|
uri += encodeURIComponent($('#cbxInterface'+timeunit+' option:selected').text());
|
2018-09-10 16:53:05 +02:00
|
|
|
uri += '&tu=';
|
|
|
|
uri += encodeURIComponent(timeunit.substr(0, 1));
|
|
|
|
var datasizeunits = 'mb';
|
|
|
|
uri += '&dsu='+encodeURIComponent(datasizeunits);
|
|
|
|
// Init. chart
|
2018-09-10 21:41:35 +02:00
|
|
|
var barchart = CreateBarChart('divChartBandwidth'+timeunit, datasizeunits);
|
|
|
|
// Init. datatable html
|
|
|
|
var datatable = CreateDataTable('divTableBandwidth'+timeunit, timeunit);
|
2018-09-10 16:53:05 +02:00
|
|
|
// Get data for chart
|
|
|
|
$.ajax({
|
|
|
|
url: uri,
|
|
|
|
dataType: 'json',
|
|
|
|
beforeSend: function() {
|
2018-09-14 01:06:13 +02:00
|
|
|
$('#divLoaderBandwidth'+timeunit).removeClass('hidden');
|
2018-09-10 16:53:05 +02:00
|
|
|
}
|
|
|
|
}).done(function(jsondata) {
|
2018-09-14 01:06:13 +02:00
|
|
|
$('#divLoaderBandwidth'+timeunit).addClass('hidden');
|
2018-09-10 16:53:05 +02:00
|
|
|
barchart.setData(jsondata);
|
2018-09-10 21:41:35 +02:00
|
|
|
$('#tableBandwidth'+timeunit).DataTable({
|
2018-09-14 01:06:13 +02:00
|
|
|
'searching': false,
|
|
|
|
'paging': false,
|
|
|
|
'data': jsondata,
|
|
|
|
'order': [[ 0, 'ASC' ]],
|
|
|
|
'columns': [
|
|
|
|
{ 'data': 'date' },
|
2019-02-27 20:42:36 +01:00
|
|
|
{ 'data': 'rx', "title": _t['receive']+' '+datasizeunits.toUpperCase() },
|
|
|
|
{ 'data': 'tx', "title": _t['send']+' '+datasizeunits.toUpperCase() }]
|
2018-09-10 16:53:05 +02:00
|
|
|
});
|
|
|
|
}).fail(function(xhr, textStatus) {
|
|
|
|
if (window.console) {
|
2018-09-14 01:06:13 +02:00
|
|
|
console.error('server error');
|
2018-09-10 16:53:05 +02:00
|
|
|
} else {
|
|
|
|
alert("server error");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-11 21:00:23 +02:00
|
|
|
$(document).ready(function() {
|
2018-09-10 21:41:35 +02:00
|
|
|
$('#tabbarBandwidth a[data-toggle="tab"]').on('shown.bs.tab', ShowBandwidthChartHandler);
|
2019-02-27 20:42:36 +01:00
|
|
|
$('#cbxInterfacehourly').on('change', ShowBandwidthChartHandler);
|
2018-09-10 21:41:35 +02:00
|
|
|
$('#cbxInterfacedaily').on('change', ShowBandwidthChartHandler);
|
|
|
|
$('#cbxInterfacemonthly').on('change', ShowBandwidthChartHandler);
|
|
|
|
ShowBandwidthChartHandler();
|
|
|
|
});
|
2018-09-10 16:53:05 +02:00
|
|
|
|
2018-09-11 21:00:23 +02:00
|
|
|
})(jQuery, t);
|
2018-09-11 16:15:31 +02:00
|
|
|
|