Show size and last updated in missions list

This commit is contained in:
Björn Dahlgren 2016-10-29 17:05:39 +02:00
parent a09651179c
commit 88c3a2067c
4 changed files with 29 additions and 5 deletions

View File

@ -1,3 +1,5 @@
var async = require('async');
var filesize = require('filesize');
var fs = require('fs');
var path = require('path');
@ -14,16 +16,30 @@ Missions.prototype.missionPath = function (name) {
}
Missions.prototype.list = function (cb){
var self = this;
fs.readdir(this.missionsPath(), function (err, files) {
if (err) {
cb(err);
} else {
var missions = files.map(function (filename) {
return {
name: filename,
};
async.map(files, function (filename, cb) {
fs.stat(self.missionPath(filename), function (err, stat) {
if (err) {
cb(err);
}
cb(null, {
dateCreated: new Date(stat.ctime),
dateModified: new Date(stat.mtime),
name: filename,
size: stat.size,
sizeFormatted: filesize(stat.size),
});
});
}, function (err, missions) {
if (cb) {
cb(err, missions);
}
});
cb(null, missions);
}
});
};

View File

@ -20,3 +20,7 @@ body {
#footer .container .text-muted {
margin: 20px 0;
}
.text-nowrap {
white-space: nowrap;
}

View File

@ -2,6 +2,8 @@
<thead>
<tr>
<th>Mission</th>
<th>Size</th>
<th>Updated</th>
<th></th>
</tr>
</thead>

View File

@ -1,6 +1,8 @@
<td style="width: 100%;">
<a href='/api/missions/<%-encodeURI(name)%>'><%-name%></a>
</td>
<td class="text-nowrap"><%-sizeFormatted%></td>
<td class="text-nowrap"><%-dateModified.substring(0, 10)%></td>
<td>
<button type="button" class="btn btn-danger btn-xs delete">
<span class="glyphicon glyphicon-trash"></span> Delete