Skip to content

Commit 7010943

Browse files
committed
Delete all log files button
1 parent c5d69ac commit 7010943

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-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

+27-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,31 @@ var template = _.template(tpl)
99
module.exports = Marionette.CompositeView.extend({
1010
childView: ListItemView,
1111
childViewContainer: 'tbody',
12-
template: template
12+
template: template,
13+
14+
events: {
15+
'click .delete-all': 'deleteAll'
16+
},
17+
18+
deleteAll: function (event) {
19+
var self = this
20+
21+
sweetAlert({
22+
title: 'Are you sure?',
23+
text: 'All logs will be deleted from the server!',
24+
type: 'warning',
25+
showCancelButton: true,
26+
confirmButtonClass: 'btn-danger',
27+
confirmButtonText: 'Yes, delete all!'
28+
},
29+
function () {
30+
$.ajax('/api/logs/all', {
31+
type: 'DELETE',
32+
success: function (data) {
33+
self.collection.fetch()
34+
},
35+
error: function () {}
36+
})
37+
})
38+
}
1339
})

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)