Merge pull request #86 from Dahlgren/feature/delete-log-file

Add delete button to log files list
This commit is contained in:
Björn Dahlgren 2017-10-05 21:47:15 +02:00 committed by GitHub
commit 841b9385b7
6 changed files with 58 additions and 1 deletions

View File

@ -28,6 +28,24 @@ Logs.generateLogFileName = function () {
return 'arma3server_' + dateStr + '.log'
}
Logs.prototype.delete = function (filename, callback) {
this.getLogFile(filename, function (err, logFile) {
if (err) {
if (callback) {
return callback(err)
}
} else {
if (logFile && logFile.path) {
fs.unlink(logFile.path, callback)
} else {
if (callback) {
return callback(new Error('File not found'))
}
}
}
})
}
Logs.prototype.generateLogFilePath = function () {
return path.join(this.logsPath(), Logs.generateLogFileName())
}

View File

@ -11,7 +11,8 @@ define(function (require) {
name: '',
formattedSize: '0 B',
size: 0,
}
},
idAttribute: 'name',
});
});

View File

@ -6,6 +6,7 @@ define(function (require) {
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
swal = require('sweet-alert'),
tpl = require('text!tpl/logs/list_item.html'),
template = _.template(tpl);
@ -13,5 +14,24 @@ define(function (require) {
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
"click .destroy": "destroy",
},
destroy: function (event) {
var self = this;
sweetAlert({
title: "Are you sure?",
text: "The log will be deleted from the server!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
},
function(){
self.model.destroy();
});
},
});
});

View File

@ -4,6 +4,7 @@
<th width="100%">Filename</th>
<th>Size</th>
<th></th>
<th></th>
</tr>
</thead>

View File

@ -15,3 +15,9 @@
Download
</a>
</td>
<td>
<a class="btn btn-danger btn-xs destroy ladda-button pull-right" data-style="expand-left">
<span class="glyphicon glyphicon-trash"></span>
Delete
</a>
</td>

View File

@ -13,6 +13,17 @@ module.exports = function (logsManager) {
})
})
router.delete('/:log', function (req, res) {
var filename = req.params.log
logsManager.delete(filename, function (err) {
if (err) {
res.status(500).send(err)
} else {
res.status(204).send()
}
})
})
router.get('/:log/:mode', function (req, res) {
var requestedFilename = req.params.log
var mode = req.params.mode === 'view' ? 'view' : 'download'