Browse Source

Properly terminate functions. Cache selectors in variables. Reformating dashboard JS.

windows
Alex Butum 12 years ago
parent
commit
1cb442a917
  1. 138
      static/js/dashboard.js

138
static/js/dashboard.js

@ -2,18 +2,18 @@
//Sort file size data.
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"file-size-units": {
K : 1024,
M : Math.pow(1024, 2),
G : Math.pow(1024, 3),
T : Math.pow(1024, 4),
P : Math.pow(1024, 5),
E : Math.pow(1024, 6)
K: 1024,
M: Math.pow(1024, 2),
G: Math.pow(1024, 3),
T: Math.pow(1024, 4),
P: Math.pow(1024, 5),
E: Math.pow(1024, 6)
},
"file-size-pre": function(a) {
"file-size-pre": function (a) {
var x = a.substring(0, a.length - 1);
var x_unit = a.substring(a.length - 1, a.length);
if(jQuery.fn.dataTableExt.oSort['file-size-units'][x_unit]) {
if (jQuery.fn.dataTableExt.oSort['file-size-units'][x_unit]) {
return parseInt(x * jQuery.fn.dataTableExt.oSort['file-size-units'][x_unit], 10);
}
else {
@ -21,11 +21,11 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
}
},
"file-size-asc": function(a, b) {
"file-size-asc": function (a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"file-size-desc": function(a, b) {
"file-size-desc": function (a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
@ -33,16 +33,16 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
//DataTables
//Sort numeric data which has a percent sign with it.
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"percent-pre": function(a) {
"percent-pre": function (a) {
var x = (a === "-") ? 0 : a.replace(/%/, "");
return parseFloat(x);
},
"percent-asc": function(a, b) {
"percent-asc": function (a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"percent-desc": function(a, b) {
"percent-desc": function (a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
@ -50,7 +50,7 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
//DataTables
//Sort IP addresses
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"ip-address-pre": function(a) {
"ip-address-pre": function (a) {
// split the address into octets
//
var x = a.split('.');
@ -59,24 +59,24 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
//
function zeroPad(num, places) {
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;
return new Array(+(zero > 0 && zero)).join("0") + num;
}
// build the resulting IP
var r = '';
for(var i=0; i<x.length; i++)
r = r + zeroPad(x[i],3);
for (var i = 0; i < x.length; i++)
r = r + zeroPad(x[i], 3);
// return the formatted IP address
//
return r;
},
"ip-address-asc": function(a, b) {
"ip-address-asc": function (a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"ip-address-desc": function(a, b) {
"ip-address-desc": function (a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
@ -92,36 +92,42 @@ function destroy_dataTable(table_id) {
}
function get_os_data(url, element) {
$.get(url, function(data) {
$.get(url, function (data) {
$(element).text(data);
}, "json");
}
var dashboard = {};
dashboard.getUptime = function() {
dashboard.getUptime = function () {
get_os_data('/info/uptime/', "#get-uptime");
}
dashboard.getOSname = function() {
};
dashboard.getOSname = function () {
get_os_data('/info/platform/osname/', "#get-osname");
}
dashboard.getHostname = function() {
};
dashboard.getHostname = function () {
get_os_data('/info/platform/hostname/', "#get-hostname");
}
dashboard.getKernel = function() {
};
dashboard.getKernel = function () {
get_os_data('/info/platform/kernel/', "#get-kernel");
}
dashboard.getCPUcount = function() {
};
dashboard.getCPUcount = function () {
get_os_data('/info/getcpus/count/', "#get-cpucount");
}
dashboard.getCPUtype = function() {
};
dashboard.getCPUtype = function () {
get_os_data('/info/getcpus/type/', "#get-cputype");
}
dashboard.getDisk = function() {
$.getJSON('/info/getdisk/', function(data) {
};
dashboard.getDisk = function () {
$.getJSON('/info/getdisk/', function (data) {
destroy_dataTable("get_disk");
$("#filter-ps").val("").off("keyup");
var $filterPs = $("#filter-ps");
$filterPs.val("").off("keyup");
var psTable = $("#get_disk").dataTable({
aaData: data,
aoColumns: [
@ -138,15 +144,17 @@ dashboard.getDisk = function() {
bAutoWidth: false,
bInfo: false
}).fadeIn();
$("#filter-ps").on("keyup", function() {
$filterPs.on("keyup", function () {
psTable.fnFilter(this.value);
});
});
}
dashboard.getUsers = function() {
$.getJSON('/info/getusers/', function(data) {
};
dashboard.getUsers = function () {
$.getJSON('/info/getusers/', function (data) {
destroy_dataTable("get_users");
$("#filter-ps").val("").off("keyup");
var $filterPs = $("#filter-ps");
$filterPs.val("").off("keyup");
var psTable = $("#get_users").dataTable({
aaData: data,
aoColumns: [
@ -164,15 +172,17 @@ dashboard.getUsers = function() {
bAutoWidth: false,
bInfo: false
}).fadeIn();
$("#filter-ps").on("keyup", function() {
$filterPs.on("keyup", function () {
psTable.fnFilter(this.value);
});
});
}
dashboard.getNetstat = function() {
$.getJSON('/info/getnetstat/', function(data) {
};
dashboard.getNetstat = function () {
$.getJSON('/info/getnetstat/', function (data) {
destroy_dataTable("get_netstat");
$("#filter-ps").val("").off("keyup");
var $filterPs = $("#filter-ps");
$filterPs.val("").off("keyup");
var psTable = $("#get_netstat").dataTable({
aaData: data,
aoColumns: [
@ -188,15 +198,17 @@ dashboard.getNetstat = function() {
bAutoWidth: false,
bInfo: false
}).fadeIn();
$("#filter-ps").on("keyup", function() {
$filterPs.on("keyup", function () {
psTable.fnFilter(this.value);
});
});
}
dashboard.getProc = function() {
$.getJSON('/info/proc/', function(data) {
};
dashboard.getProc = function () {
$.getJSON('/info/proc/', function (data) {
destroy_dataTable("get_proc");
$("#filter-ps").val("").off("keyup");
var $filterPs = $("#filter-ps");
$filterPs.val("").off("keyup");
var psTable = $("#get_proc").dataTable({
aaData: data,
aoColumns: [
@ -219,16 +231,17 @@ dashboard.getProc = function() {
bAutoWidth: false,
bInfo: false
}).fadeIn();
$("#filter-ps").on("keyup", function() {
$filterPs.on("keyup", function () {
psTable.fnFilter(this.value);
});
});
}
};
dashboard.getIps = function() {
$.getJSON('/info/getips/', function(data) {
dashboard.getIps = function () {
$.getJSON('/info/getips/', function (data) {
destroy_dataTable("get_ips");
$("#filter-ps").val("").off("keyup");
var $filterPs = $("#filter-ps");
$filterPs.val("").off("keyup");
var psTable = $("#get_ips").dataTable({
aaData: data,
aoColumns: [
@ -244,18 +257,17 @@ dashboard.getIps = function() {
bAutoWidth: false,
bInfo: false
}).fadeIn();
$("#filter-ps").on("keyup", function() {
$filterPs.on("keyup", function () {
psTable.fnFilter(this.value);
});
});
}
};
//Expand-Contract div/table
$(document).ready(function() {
// Expand-Contract div/table
$(document).ready(function () {
$(".widget-content").show();
$(".widget-header").click(function()
{
$(".widget-header").click(function () {
$(this).next(".widget-content").slideToggle(500);
$("i",this).toggleClass("icon-minus icon-plus");
$("i", this).toggleClass("icon-minus icon-plus");
});
});
Loading…
Cancel
Save