mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Merge pull request #86 from Dahlgren/feature/delete-log-file
Add delete button to log files list
This commit is contained in:
commit
841b9385b7
18
lib/logs.js
18
lib/logs.js
@ -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())
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ define(function (require) {
|
||||
name: '',
|
||||
formattedSize: '0 B',
|
||||
size: 0,
|
||||
}
|
||||
},
|
||||
idAttribute: 'name',
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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();
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
|
@ -4,6 +4,7 @@
|
||||
<th width="100%">Filename</th>
|
||||
<th>Size</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user