Sort logs by creation date in descending order

This commit is contained in:
Björn Dahlgren 2021-02-28 14:30:16 +01:00 committed by Björn Dahlgren
parent a33c866644
commit 0d9b6134b7
2 changed files with 6 additions and 2 deletions

View File

@ -97,13 +97,15 @@ Logs.prototype.logFiles = function (callback) {
async.filter(files, function (file, cb) {
fs.stat(file.path, function (err, stat) {
file.created = stat.birthtime.toISOString()
file.modified = stat.mtime.toISOString()
file.formattedSize = filesize(stat.size)
file.size = stat.size
cb(!err && stat.isFile())
})
}, function (files) {
files.sort(function (a, b) {
return a.name.toLowerCase().localeCompare(b.name.toLowerCase())
return b.created.localeCompare(a.created) // Descending order
})
callback(null, files)

View File

@ -3,7 +3,9 @@ var Backbone = require('backbone')
var Log = require('app/models/log')
module.exports = Backbone.Collection.extend({
comparator: 'name',
comparator: function (a, b) {
return b.get('created').localeCompare(a.get('created')) // Descending order
},
model: Log,
url: '/api/logs/'
})