From ed9a57fdd94adb12718a73e531def8cb2feb3507 Mon Sep 17 00:00:00 2001 From: Abdullah Diab Date: Tue, 5 May 2015 19:39:37 +0200 Subject: [PATCH 1/2] Added clear history button to history page --- src/routes/bins.js | 16 ++++++++++++++++ src/static/main.css | 4 ++++ src/views/bin/log.jade | 14 +++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/routes/bins.js b/src/routes/bins.js index 621431bf..83b4e980 100644 --- a/src/routes/bins.js +++ b/src/routes/bins.js @@ -39,6 +39,8 @@ var Bins = function (dsn_str) { router.get('/:uuid/log', mw.errorHandler, mw.bodyParser, this.routes.log.bind(this), mw.cors, mw.negotiateContent) + router.post('/:uuid/log/clear', mw.errorHandler, mw.bodyParser, this.routes.clear_log.bind(this), mw.cors, mw.negotiateContent) + router.all('/:uuid*', mw.errorHandler, mw.bodyParser, this.routes.send.bind(this), mw.cors, mw.negotiateContent) return router @@ -243,6 +245,20 @@ Bins.prototype.routes = { next() }) + }, + + clear_log: function (req, res, next) { + this.client.del('log:' + req.params.uuid, function (err, history) { + if (err) { + debug(err) + + throw err + } + + res.view = 'redirect'; + res.status(200).location(util.format('/bin/%s', req.params.uuid)); + next(); + }); } } diff --git a/src/static/main.css b/src/static/main.css index 826e8e8b..ef0477bc 100644 --- a/src/static/main.css +++ b/src/static/main.css @@ -176,6 +176,10 @@ div[data-page="bin/log"] h3 { margin-top: 0; } +div[data-page="bin/log"] h3 label { + margin-left: 1em; +} + div[data-page="bin/log"] pre { height: 500px; diff --git a/src/views/bin/log.jade b/src/views/bin/log.jade index a6eb5743..41b1188b 100644 --- a/src/views/bin/log.jade +++ b/src/views/bin/log.jade @@ -11,7 +11,13 @@ block content div.btn-group.pull-right.hidden-xs a(href= '/bin/' + req.params.uuid + '/view').btn.btn-primary View Details - h3 Bin History: #[code= req.params.uuid] + h3 + | Bin History: #[code= req.params.uuid] + label(for='clear_log').btn.btn-xs.btn-default + span.glyphicon.glyphicon-trash + | Clear History + form(method="POST", action='/bin/' + req.params.uuid + '/log/clear').hidden + button(type='submit', id='clear_log').btn.btn-xs div.visible-xs a(href= '/bin/' + req.params.uuid + '/view').btn.btn-block.btn-primary View Details @@ -68,6 +74,12 @@ block content block scripts script. $(function() { + $('#clear_log').click(function (e) { + if (!confirm('Are you sure you want to clear the log?')) { + e.preventDefault(); + } + }); + $('tr[data-id] td, button[data-id]').on('click', function (e) { var id = $(this).data('id') From fb043a642373d385a5eca646c75c55e02daef61d Mon Sep 17 00:00:00 2001 From: Abdullah Diab Date: Thu, 7 May 2015 21:53:39 +0200 Subject: [PATCH 2/2] Fixed the failing tests, removed the extra semicolons --- src/routes/bins.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/bins.js b/src/routes/bins.js index 83b4e980..2541afb1 100644 --- a/src/routes/bins.js +++ b/src/routes/bins.js @@ -255,10 +255,10 @@ Bins.prototype.routes = { throw err } - res.view = 'redirect'; - res.status(200).location(util.format('/bin/%s', req.params.uuid)); - next(); - }); + res.view = 'redirect' + res.status(200).location(util.format('/bin/%s', req.params.uuid)) + next() + }) } }