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

117 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-02-18 01:56:23 -07:00
'use strict';
2016-05-24 22:01:46 -04:00
2023-09-29 21:50:11 -04:00
define('admin/advanced/errors', [
'bootbox', 'alerts', 'chart.js/auto',
], function (bootbox, alerts, { Chart }) {
const Errors = {};
2016-05-24 22:01:46 -04:00
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) {
2021-12-06 14:31:35 -05:00
return alerts.error(err);
2016-08-16 19:46:59 +02:00
}
2016-05-24 23:04:57 -04:00
ajaxify.refresh();
2021-12-06 14:31:35 -05:00
alerts.success('[[admin/advanced/errors:clear404-success]]');
2016-05-24 23:04:57 -04:00
});
}
});
};
Errors.setupCharts = function () {
const notFoundCanvas = document.getElementById('not-found');
const tooBusyCanvas = document.getElementById('toobusy');
let 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()) {
2023-09-29 21:50:11 -04:00
Chart.defaults.plugins.tooltip.enabled = false;
2016-05-24 22:01:46 -04:00
}
const data = {
2016-05-24 22:01:46 -04:00
'not-found': {
labels: dailyLabels,
datasets: [
{
2017-02-18 01:56:23 -07:00
label: '',
2023-09-29 21:50:11 -04:00
fill: 'origin',
tension: 0.25,
2017-02-18 01:56:23 -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
},
2017-02-18 01:19:20 -07:00
toobusy: {
2016-05-24 22:01:46 -04:00
labels: dailyLabels,
datasets: [
{
2017-02-18 01:56:23 -07:00
label: '',
2023-09-29 21:50:11 -04:00
fill: 'origin',
tension: 0.25,
2017-02-18 01:56:23 -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)',
data: ajaxify.data.analytics.toobusy,
2017-02-17 19:31:21 -07:00
},
],
},
2016-05-24 22:01:46 -04:00
};
2016-08-09 07:54:58 -07:00
new Chart(notFoundCanvas.getContext('2d'), {
type: 'line',
data: data['not-found'],
options: {
responsive: true,
2023-09-29 21:50:11 -04:00
plugins: {
legend: {
display: false,
},
2016-08-09 07:54:58 -07:00
},
scales: {
2023-09-29 21:50:11 -04:00
y: {
beginAtZero: true,
},
2017-02-17 19:31:21 -07:00
},
},
2016-05-24 22:01:46 -04:00
});
2017-02-18 01:27:46 -07:00
2016-08-09 07:54:58 -07:00
new Chart(tooBusyCanvas.getContext('2d'), {
type: 'line',
data: data.toobusy,
2016-08-09 07:54:58 -07:00
options: {
responsive: true,
2023-09-29 21:50:11 -04:00
plugins: {
legend: {
display: false,
},
2016-08-09 07:54:58 -07:00
},
scales: {
2023-09-29 21:50:11 -04:00
y: {
beginAtZero: true,
},
2017-02-17 19:31:21 -07:00
},
},
2016-05-24 22:01:46 -04:00
});
};
return Errors;
2017-02-18 02:30:48 -07:00
});