Skip to content

Commit 203e8a7

Browse files
committed
Delete all log files button
1 parent c5d69ac commit 203e8a7

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

Diff for: lib/logs.js

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ Logs.prototype.delete = function (filename, callback) {
4646
})
4747
}
4848

49+
Logs.prototype.deleteAll = function (callback) {
50+
this.logFiles(function (err, files) {
51+
if (err) {
52+
return callback(err)
53+
}
54+
55+
async.map(files, function (logFile, cb) {
56+
fs.unlink(logFile.path, cb)
57+
}, callback)
58+
})
59+
}
60+
4961
Logs.prototype.generateLogFilePath = function (prefix, suffix) {
5062
return path.join(this.logsPath(), Logs.generateLogFileName(prefix, suffix))
5163
}

Diff for: public/js/app/views/logs/list.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
var $ = require('jquery')
12
var _ = require('underscore')
23
var Marionette = require('marionette')
4+
var sweetAlert = require('sweet-alert')
35

46
var ListItemView = require('app/views/logs/list_item')
57
var tpl = require('tpl/logs/list.html')
@@ -9,5 +11,31 @@ var template = _.template(tpl)
911
module.exports = Marionette.CompositeView.extend({
1012
childView: ListItemView,
1113
childViewContainer: 'tbody',
12-
template: template
14+
template: template,
15+
16+
events: {
17+
'click .delete-all': 'deleteAll'
18+
},
19+
20+
deleteAll: function (event) {
21+
var self = this
22+
23+
sweetAlert({
24+
title: 'Are you sure?',
25+
text: 'All logs will be deleted from the server!',
26+
type: 'warning',
27+
showCancelButton: true,
28+
confirmButtonClass: 'btn-danger',
29+
confirmButtonText: 'Yes, delete all!'
30+
},
31+
function () {
32+
$.ajax('/api/logs/all', {
33+
type: 'DELETE',
34+
success: function (data) {
35+
self.collection.fetch()
36+
},
37+
error: function () {}
38+
})
39+
})
40+
}
1341
})

Diff for: public/js/tpl/logs/list.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
<th class="hidden-xs hidden-sm">Created</th>
66
<th class="hidden-xs hidden-sm">Modified</th>
77
<th>Size</th>
8-
<th></th>
9-
<th></th>
8+
<th colspan="2">
9+
<a class="btn btn-danger btn-xs delete-all ladda-button pull-right" data-style="expand-left">
10+
<span class="glyphicon glyphicon-trash"></span>
11+
Delete all
12+
</a>
13+
</th>
1014
</tr>
1115
</thead>
1216

Diff for: routes/logs.js

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ module.exports = function (logsManager) {
1313
})
1414
})
1515

16+
router.delete('/all', function (req, res) {
17+
logsManager.deleteAll(function (err) {
18+
if (err) {
19+
res.status(500).send(err)
20+
} else {
21+
res.status(204).send()
22+
}
23+
})
24+
})
25+
1626
router.delete('/:log', function (req, res) {
1727
var filename = req.params.log
1828
logsManager.delete(filename, function (err) {

0 commit comments

Comments
 (0)