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 fs = require('fs');
var path = require('path'); var path = require('path');
@ -14,16 +16,30 @@ Missions.prototype.missionPath = function (name) {
} }
Missions.prototype.list = function (cb){ Missions.prototype.list = function (cb){
var self = this;
fs.readdir(this.missionsPath(), function (err, files) { fs.readdir(this.missionsPath(), function (err, files) {
if (err) { if (err) {
cb(err); cb(err);
} else { } else {
var missions = files.map(function (filename) { async.map(files, function (filename, cb) {
return { fs.stat(self.missionPath(filename), function (err, stat) {
name: filename, 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 { #footer .container .text-muted {
margin: 20px 0; margin: 20px 0;
} }
.text-nowrap {
white-space: nowrap;
}

View File

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

View File

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