devshort

private self-hosted shortlink service
git clone https://git.clttr.info/devshort.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 9c457e1a391e3e153ff2615985354ba9fa82d6cb
parent 1b4166276cdf731b471a72f7d0f915990a99150e
Author: Florian <flokX@users.noreply.github.com>
Date:   Sun, 19 Jan 2020 10:57:29 +0100

Fix chart reloading

Diffstat:
Massets/main.js | 52++++++++++++++++++++++++++++++----------------------
1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/assets/main.js b/assets/main.js @@ -30,29 +30,29 @@ Vue.component('chart', { } }, template: template, - mounted: function () { - let dataset = []; - for (let [unixTimestamp, count] of Object.entries(this.stats)) { - let timestamp = new Date(unixTimestamp * 1000); - if (((currentDate - timestamp) / (60 * 60 * 24 * 1000)) <= 7) { - this.accessCount.sevenDays += count; - } - this.accessCount.total += count; - dataset.push({ x: timestamp, y: count }); - } - new frappe.Chart('div#' + this.chartId, { - type: 'heatmap', - title: 'Access statistics for ' + this.name, - data: { - dataPoints: this.stats, - start: startDate, - end: currentDate - }, - countLabel: 'Accesses', - discreteDomains: 0 - }); - }, methods: { + render: function () { + let dataset = []; + for (let [unixTimestamp, count] of Object.entries(this.stats)) { + let timestamp = new Date(unixTimestamp * 1000); + if (((currentDate - timestamp) / (60 * 60 * 24 * 1000)) <= 7) { + this.accessCount.sevenDays += count; + } + this.accessCount.total += count; + dataset.push({ x: timestamp, y: count }); + } + new frappe.Chart('div#' + this.chartId, { + type: 'heatmap', + title: 'Access statistics for ' + this.name, + data: { + dataPoints: this.stats, + start: startDate, + end: currentDate + }, + countLabel: 'Accesses', + discreteDomains: 0 + }); + }, remove: function (event) { post('admin.php?delete', { name: this.name @@ -68,6 +68,14 @@ Vue.component('chart', { shortlinkUrl: function () { return this.$parent.dataObject.shortlinks[this.name]; } + }, + watch: { + stats: function () { + this.render(); + } + }, + mounted: function () { + this.render(); } });