Files
NodeBB/public/src/admin/advanced/errors.js

113 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-05-24 22:01:46 -04:00
"use strict";
2016-05-24 22:01:46 -04:00
2016-12-08 02:06:25 -07:00
define('admin/advanced/errors', ['Chart', 'translator'], function (Chart, translator) {
2016-05-24 22:01:46 -04:00
var Errors = {};
Errors.init = function () {
2016-05-24 23:04:57 -04:00
Errors.setupCharts();
$('[data-action="clear"]').on('click', Errors.clear404);
};
Errors.clear404 = function () {
2016-12-08 02:06:25 -07:00
bootbox.confirm('[[admin/advanced/errors:clear404-confirm]]', function (ok) {
2016-05-24 23:04:57 -04:00
if (ok) {
socket.emit('admin.errors.clear', {}, function (err) {
2016-08-16 19:46:59 +02:00
if (err) {
return app.alertError(err.message);
}
2016-05-24 23:04:57 -04:00
ajaxify.refresh();
2016-12-08 02:06:25 -07:00
app.alertSuccess('[[admin/advanced/errors:clear404-success]]');
2016-05-24 23:04:57 -04:00
});
}
});
};
Errors.setupCharts = function () {
2017-02-17 20:20:42 -07:00
var notFoundCanvas = document.getElementById('not-found');
var tooBusyCanvas = document.getElementById('toobusy');
var dailyLabels = utils.getDaysArray();
2016-05-24 22:01:46 -04:00
2016-05-25 15:28:37 -04:00
dailyLabels = dailyLabels.slice(-7);
2016-05-24 22:01:46 -04:00
if (utils.isMobile()) {
2016-08-09 07:54:58 -07:00
Chart.defaults.global.tooltips.enabled = false;
2016-05-24 22:01:46 -04:00
}
var data = {
'not-found': {
labels: dailyLabels,
datasets: [
{
label: "",
2016-08-09 07:54:58 -07:00
backgroundColor: "rgba(186,139,175,0.2)",
borderColor: "rgba(186,139,175,1)",
pointBackgroundColor: "rgba(186,139,175,1)",
pointHoverBackgroundColor: "#fff",
pointBorderColor: "#fff",
pointHoverBorderColor: "rgba(186,139,175,1)",
2017-02-17 19:31:21 -07:00
data: ajaxify.data.analytics['not-found'],
},
],
2016-05-24 22:01:46 -04:00
},
'toobusy': {
labels: dailyLabels,
datasets: [
{
label: "",
2016-08-09 07:54:58 -07:00
backgroundColor: "rgba(151,187,205,0.2)",
borderColor: "rgba(151,187,205,1)",
pointBackgroundColor: "rgba(151,187,205,1)",
pointHoverBackgroundColor: "#fff",
pointBorderColor: "#fff",
pointHoverBorderColor: "rgba(151,187,205,1)",
2017-02-17 19:31:21 -07:00
data: ajaxify.data.analytics['toobusy'],
},
],
},
2016-05-24 22:01:46 -04:00
};
notFoundCanvas.width = $(notFoundCanvas).parent().width();
tooBusyCanvas.width = $(tooBusyCanvas).parent().width();
2016-08-09 07:54:58 -07:00
new Chart(notFoundCanvas.getContext('2d'), {
type: 'line',
data: data['not-found'],
options: {
responsive: true,
legend: {
2017-02-17 19:31:21 -07:00
display: false,
2016-08-09 07:54:58 -07:00
},
scales: {
yAxes: [{
ticks: {
2017-02-17 19:31:21 -07:00
beginAtZero: true,
},
}],
},
},
2016-05-24 22:01:46 -04:00
});
2016-08-09 07:54:58 -07:00
new Chart(tooBusyCanvas.getContext('2d'), {
type: 'line',
data: data['toobusy'],
options: {
responsive: true,
legend: {
2017-02-17 19:31:21 -07:00
display: false,
2016-08-09 07:54:58 -07:00
},
scales: {
yAxes: [{
ticks: {
2017-02-17 19:31:21 -07:00
beginAtZero: true,
},
}],
},
},
2016-05-24 22:01:46 -04:00
});
};
return Errors;
});