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

120 lines
2.3 KiB
JavaScript
Raw Normal View History

import {
Chart,
LineController,
CategoryScale,
LinearScale,
LineElement,
PointElement,
Tooltip,
Filler,
} from 'chart.js';
import * as bootbox from 'bootbox';
import * as alerts from '../../modules/alerts';
2016-05-24 22:01:46 -04:00
Chart.register(
LineController,
CategoryScale,
LinearScale,
LineElement,
PointElement,
Tooltip,
Filler
);
2016-05-24 22:01:46 -04:00
2016-05-24 23:04:57 -04:00
export function init() {
setupCharts();
2016-05-24 23:04:57 -04:00
$('[data-action="clear"]').on('click', clear404);
}
2016-08-16 19:46:59 +02:00
function clear404() {
bootbox.confirm('[[admin/advanced/errors:clear404-confirm]]', function (ok) {
if (ok) {
socket.emit('admin.errors.clear', {}, function (err) {
if (err) {
return alerts.error(err);
}
2016-05-24 23:04:57 -04:00
ajaxify.refresh();
alerts.success('[[admin/advanced/errors:clear404-success]]');
});
}
});
}
2016-05-24 22:01:46 -04:00
function setupCharts() {
const notFoundCanvas = document.getElementById('not-found');
const tooBusyCanvas = document.getElementById('toobusy');
let dailyLabels = utils.getDaysArray();
2016-05-24 22:01:46 -04:00
dailyLabels = dailyLabels.slice(-7);
2016-05-24 22:01:46 -04:00
if (utils.isMobile()) {
Chart.defaults.plugins.tooltip.enabled = false;
}
2016-05-24 22:01:46 -04:00
const data = {
'not-found': {
labels: dailyLabels,
datasets: [
{
label: '',
fill: 'origin',
tension: 0.25,
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)',
data: ajaxify.data.analytics['not-found'],
2016-08-09 07:54:58 -07:00
},
],
},
toobusy: {
labels: dailyLabels,
datasets: [
{
label: '',
fill: 'origin',
tension: 0.25,
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
},
],
},
};
2023-11-10 16:29:33 -05:00
const chartOptions = {
responsive: true,
scales: {
y: {
beginAtZero: true,
},
},
plugins: {
legend: {
display: false,
},
},
};
2017-02-18 01:27:46 -07:00
new Chart(notFoundCanvas.getContext('2d'), {
type: 'line',
data: data['not-found'],
2023-11-10 16:29:33 -05:00
options: chartOptions,
});
2016-05-24 22:01:46 -04:00
new Chart(tooBusyCanvas.getContext('2d'), {
type: 'line',
data: data.toobusy,
2023-11-10 16:29:33 -05:00
options: chartOptions,
});
}