"use strict"; import Chartist from "chartist"; import 'chartist-plugin-tooltips'; if(document.querySelector('#chart-сaptcha-activity')) { let chartCaptchaActivity = null; axios.get('/dashboard/chart-captcha-activity') .then(response => { chartCaptchaActivity = new Chartist.Line('#chart-сaptcha-activity', { labels: response.data.days, series: response.data.values, }, { low: 0, showArea: true, fullWidth: true, plugins: [ Chartist.plugins.tooltip() ], axisX: { // On the x-axis start means top and end means bottom position: 'end', showGrid: true, }, axisY: { // On the y-axis start means left and end means right showGrid: true, showLabel: true, } }); let currentDate = response.data.days[response.data.days.length - 1]; window.websocket.add(function (echo) { echo.private('chart-captcha-activity') .listen('CreatedCaptchaLog', (e) => { let options = chartCaptchaActivity.data; if (currentDate !== e.chartCaptchaActivity.date) { currentDate = e.chartCaptchaActivity.date; options['labels'].push(currentDate); options['series'].forEach(function(series, i) { series.push(response.data.types[i]); options['series'].push(series); }); } let values = options['series'][e.chartCaptchaActivity['type'] - 1]; options['series'][e.chartCaptchaActivity['type'] - 1][values.length - 1]['value']++; chartCaptchaActivity.update(options); let captchaLog = document.querySelector('#captcha-log'); if (captchaLog) { let tr = document.createElement("tr"); let link = ''; if (e.captchaLog.link !== '' && e.captchaLog.title !== '') { link = `${e.captchaLog.title}`; } tr.innerHTML = ` ${e.captchaLog.created_at} ${link}

${e.captchaLog.type}

IP: ${e.captchaLog.ip}

User Agent: ${e.captchaLog.user_agent}

referer: ${e.captchaLog.referer}

`; captchaLog.prepend(tr); } }); }); }) .catch(error => { }); }