From b2389c7d8454e41829bf583f627bcb7063579807 Mon Sep 17 00:00:00 2001 From: Karthik Ananthapadmanaban Date: Sat, 19 Jul 2014 01:34:24 -0400 Subject: [PATCH] added the ability to clear entire stats --- app.js | 1 + persist.js | 8 ++++++++ public/javascripts/core.js | 14 ++++++++++++++ public/stylesheets/usages.css | 4 ++++ routes/analytics.js | 6 ++++++ views/usages.jade | 4 +++- 6 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 324b8e8..382f7bf 100644 --- a/app.js +++ b/app.js @@ -38,6 +38,7 @@ app.post('/page-analytics/record', analytics.record); app.post('/page-analytics/getavgtime', analytics.getavgtime); app.get('/page-analytics/getrequestct', analytics.getrequestct); app.post('/page-analytics/getrequests', analytics.getrequests); +app.post('/page-analytics/remove-all', analytics.removeAll); /// catch 404 and forwarding to error handler app.use(function(req, res, next) { diff --git a/persist.js b/persist.js index 863d900..c8317ff 100644 --- a/persist.js +++ b/persist.js @@ -36,3 +36,11 @@ exports.getAnalytics = function(callback){ callback(items); }); }; + +exports.removeAll = function(callback){ + var collection = db.collection('time_spent'); + + collection.remove({}, function(){ + callback(); + }); +}; diff --git a/public/javascripts/core.js b/public/javascripts/core.js index 576c2ad..7edf31b 100644 --- a/public/javascripts/core.js +++ b/public/javascripts/core.js @@ -119,6 +119,20 @@ $(document).ready(function(){ var val = $(this).val(); loadChart(val, ['#avg_container']); }); + + $('#remove').on('click', function(){ + $.ajax({ + type: "POST", + url: '/page-analytics/remove-all', + success: function(data){ + $('#status').addClass('alert alert-success').html('Successfully deleted all the records').show(); + setTimeout(function(){ + $('#status').hide('slow').html('').removeClass('alert alert-success'); + }, 3000); + }, + dataType: 'json' + }); + }); }); $(function () { diff --git a/public/stylesheets/usages.css b/public/stylesheets/usages.css index 7148070..fc063e4 100644 --- a/public/stylesheets/usages.css +++ b/public/stylesheets/usages.css @@ -5,3 +5,7 @@ #requests tr { cursor: pointer } + +#status { + display: none +} diff --git a/routes/analytics.js b/routes/analytics.js index c17fcc0..3d710e4 100644 --- a/routes/analytics.js +++ b/routes/analytics.js @@ -129,6 +129,12 @@ exports.getrequests = function(req, res) { }); }; +exports.removeAll = function(req, res){ + db.removeAll(function(){ + res.json({ result: true }); + }); +}; + function getTimeSpent(sec) { if (sec < 60) { return sec + " seconds"; diff --git a/views/usages.jade b/views/usages.jade index 8de411a..96e7e94 100644 --- a/views/usages.jade +++ b/views/usages.jade @@ -9,6 +9,8 @@ block content script(type='text/javascript' src='/javascripts/highcharts.js') script(type='text/javascript' src='/javascripts/highcharts-3d.js') script(type='text/javascript' src='/javascripts/exporting.js') + br + div#status ul#tabs.nav.nav-tabs(role='tablist', data-tabs='tabs') li.active a(href='#home', role='tab', data-toggle='tab') Dashboard @@ -104,7 +106,7 @@ block content .panel.panel-default .panel-heading Purge Analytics Data .panel-body - a.btn.btn-danger + a.btn.btn-danger(id='remove') | Delete All Data br br