devshort

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

commit 7ec6012852d15bd6ea4cdb5b3fd1f276a2e65681
parent 935022e3dcdbdcc5a7ec70738447dec5b38b4bce
Author: Florian <flokX@users.noreply.github.com>
Date:   Sat,  2 Feb 2019 11:39:40 +0100

Rewrite main.js
Diffstat:
Madmin/main.js | 68+++++++++++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 47 insertions(+), 21 deletions(-)

diff --git a/admin/main.js b/admin/main.js @@ -1,28 +1,54 @@ var currentDate = new Date(); var startDate = new Date(new Date().setFullYear(currentDate.getFullYear() - 1)); -$.getJSON('stats.json', function (json) { +$('button#add-shortlink').click(function (event) { + event.preventDefault(); + $('div#spinner').show(); + $.post('index.php?add', { + name: $('input#name').val(), + link: $('input#link').val() + }, function () { + $('input#name').val(''); + $('input#link').val(''); + getCharts(); + }); +}); +$('a#refresh').click(function (event) { + event.preventDefault(); + getCharts(); +}); + +function getCharts() { 'use strict'; - $.each(json, function (name, data) { - $('div#charts').append('<div class="card mb-3"><div class="card-body"><div id="heatmap-' + name + '" class="heatmap"></div></div><div class="card-footer text-center text-muted"><a id="export-' + name + '" href="#download" class="card-link">Download chart</a><a id="delete-' + name + '" href="#delete" class="card-link">Delete shortlink and dataset</a></div></div>'); - let heatmap = new frappe.Chart('div#heatmap-' + name, { - type: 'heatmap', - title: 'Access statistics for ' + name, - data: { - dataPoints: data, - start: startDate, - end: currentDate - }, - countLabel: 'Access(es)' - }); - $('a#export-' + name).click(function () { - heatmap.export(); - }); - $('a#delete-' + name).click(function () { - $.post('index.php', { - delete: name + $('div#spinner').show(); + $('div#charts').empty(); + $.getJSON('stats.json', function (json) { + $.each(json, function (name, data) { + $('div#charts').append('<div id="card-' + name + '" class="card mb-3"><div class="card-body"><div id="heatmap-' + name + '" class="heatmap"></div></div><div class="card-footer text-center text-muted"><a id="export-' + name + '" href="#download" class="card-link">Download chart</a><a id="delete-' + name + '" href="#delete" class="card-link">Delete shortlink and dataset</a></div></div>'); + let heatmap = new frappe.Chart('div#heatmap-' + name, { + type: 'heatmap', + title: 'Access statistics for ' + name, + data: { + dataPoints: data, + start: startDate, + end: currentDate + }, + countLabel: 'Access(es)' + }); + $('a#export-' + name).click(function (event) { + event.preventDefault(); + heatmap.export(); + }); + $('a#delete-' + name).click(function (event) { + event.preventDefault(); + $.post('index.php?delete', { + name: name + }); + $('div#card-' + name).remove(); }); - location.reload(); }); + $('div#spinner').hide(); }); -}); +} + +getCharts();