Commit d2b90430 authored by Leo Iannacone's avatar Leo Iannacone

code refactoried and structured

parent 480fdb12
...@@ -10,6 +10,7 @@ function Page_History() { ...@@ -10,6 +10,7 @@ function Page_History() {
var distributions_counter = {}; var distributions_counter = {};
var days_counter = {}; var days_counter = {};
var all_distributions = [];
var all_days = {}; var all_days = {};
function _get_short_day(timestamp) { function _get_short_day(timestamp) {
...@@ -22,24 +23,8 @@ function Page_History() { ...@@ -22,24 +23,8 @@ function Page_History() {
return date.toLocaleDateString(locale, options); return date.toLocaleDateString(locale, options);
} }
// init table and some objects function _add_row(package_status) {
for (var i = 0; i < dom_history.length; i++) { var p = package_status;
var p = dom_history[i];
var day = _get_short_day(p.start);
// count total packages by distributions
if (distributions_counter.hasOwnProperty(p.distribution))
distributions_counter[p.distribution]++;
else distributions_counter[p.distribution] = 1;
if (days_counter.hasOwnProperty(p.distribution)) {
if (days_counter[p.distribution].hasOwnProperty(day))
days_counter[p.distribution][day]++;
else
days_counter[p.distribution][day] = 1;
} else {
days_counter[p.distribution] = {};
days_counter[p.distribution][day] = 1;
}
all_days[day] = 0;
var info = Utils.get_status_icon_and_class(p); var info = Utils.get_status_icon_and_class(p);
var label = info.label || 'building'; var label = info.label || 'building';
var distribution_url = Utils.get_url_to_package({ var distribution_url = Utils.get_url_to_package({
...@@ -57,71 +42,113 @@ function Page_History() { ...@@ -57,71 +42,113 @@ function Page_History() {
$('table tbody').append(row); $('table tbody').append(row);
} }
// create the theme for tablesorter function _count_distributions(package_status) {
$.extend($.tablesorter.themes.bootstrap, { var p = package_status;
table: 'table table-condensed table-bordered table-striped', if (distributions_counter.hasOwnProperty(p.distribution))
caption: 'caption', distributions_counter[p.distribution]++;
header: 'bootstrap-header', else distributions_counter[p.distribution] = 1;
sortNone: 'bootstrap-icon-unsorted', }
sortAsc: 'glyphicon glyphicon-chevron-up',
sortDesc: 'glyphicon glyphicon-chevron-down', function _count_days(package_status) {
}); var p = package_status;
var day = _get_short_day(p.start);
// call the tablesorter plugin and apply the uitheme widget if (days_counter.hasOwnProperty(p.distribution)) {
$("table").tablesorter({ if (days_counter[p.distribution].hasOwnProperty(day))
theme: "bootstrap", days_counter[p.distribution][day]++;
widthFixed: true, else
headerTemplate: '{content} {icon}', days_counter[p.distribution][day] = 1;
widgets: ["uitheme", "filter"], } else {
sortList: [ days_counter[p.distribution] = {};
[3, 1] days_counter[p.distribution][day] = 1;
]
});
// add some fancy class to input fields
$("table input").addClass('form-control');
$("table select").addClass('form-control');
// build the distribution Pie graph
var distributions_data = {
series: [],
labels: []
};
var all_distibutions = [];
for (var distro in distributions_counter) {
if (distributions_counter.hasOwnProperty(distro)) {
distributions_data.series.push(distributions_counter[distro]);
distributions_data.labels.push(distro + " (" + distributions_counter[distro] + ")");
all_distibutions.push(distro);
} }
all_days[day] = 0;
} }
Chartist.Pie('#distributions-chart', distributions_data, { function _sort_table() {
donut: true, // create the theme for tablesorter
donutWidth: 15, $.extend($.tablesorter.themes.bootstrap, {
}); table: 'table table-condensed table-bordered table-striped',
caption: 'caption',
// build the days Line graph header: 'bootstrap-header',
var days_data = { sortNone: 'bootstrap-icon-unsorted',
series: [], sortAsc: 'glyphicon glyphicon-chevron-up',
labels: [] sortDesc: 'glyphicon glyphicon-chevron-down',
}; });
for (var day in all_days) {
if (all_days.hasOwnProperty(day)) // call the tablesorter plugin and apply the uitheme widget
days_data.labels.push(day); $("table").tablesorter({
theme: "bootstrap",
widthFixed: true,
headerTemplate: '{content} {icon}',
widgets: ["uitheme", "filter"],
sortList: [
[3, 1]
]
});
// add some fancy class to input fields
$("table input").addClass('form-control');
$("table select").addClass('form-control');
} }
for (var i = 0; i < all_distibutions.length; i++) {
var info = []; function _create_graph_distributions() {
var distro = all_distibutions[i]; // build the distribution Pie graph
var distributions_data = {
series: [],
labels: []
};
for (var distro in distributions_counter) {
if (distributions_counter.hasOwnProperty(distro)) {
distributions_data.series.push(distributions_counter[distro]);
distributions_data.labels.push(distro + " (" + distributions_counter[distro] + ")");
all_distributions.push(distro);
}
}
Chartist.Pie('#distributions-chart', distributions_data, {
donut: true,
donutWidth: 15,
});
}
function _create_graph_days() {
// build the days Line graph
var days_data = {
series: [],
labels: []
};
for (var day in all_days) { for (var day in all_days) {
if (!all_days.hasOwnProperty(day)) if (all_days.hasOwnProperty(day))
continue; days_data.labels.push(day);
if (days_counter[distro].hasOwnProperty(day)) }
info.push(days_counter[distro][day]); for (var i = 0; i < all_distributions.length; i++) {
else var info = [];
info.push(0); var distro = all_distributions[i];
for (var day in all_days) {
if (!all_days.hasOwnProperty(day))
continue;
if (days_counter[distro].hasOwnProperty(day))
info.push(days_counter[distro][day]);
else
info.push(0);
}
days_data.series.push(info);
} }
days_data.series.push(info); Chartist.Line('#days-chart', days_data);
}
// init table and some objects
for (var i = 0; i < dom_history.length; i++) {
var p = dom_history[i];
_add_row(p);
// count stats
_count_distributions(p);
_count_days(p);
} }
Chartist.Line('#days-chart', days_data); _sort_table();
_create_graph_distributions();
_create_graph_days();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment