Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stats now display in byte, KB or MB units.
Added template filter for converting byte values.
  • Loading branch information
andzdroid committed May 8, 2012
1 parent 65945fb commit e00400f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions filters.js
@@ -1,3 +1,19 @@
exports.json = function(input) {
return JSON.stringify(input, null, ' ');
};

exports.convertBytes= function(input) {
input = parseInt(input, 10);
if (input < 1024) {
return input.toString() + ' Bytes';
} else if (input < 1024 * 1024) {
//Convert to KB and keep 2 decimal values
input = Math.round((input / 1024) * 100) / 100;
return input.toString() + ' KB';
} else if (input < 1024 * 1024 * 1024) {
input = Math.round((input / (1024 * 1024)) * 100) / 100;
return input.toString() + ' MB';
} else {
return input.toString() + ' Bytes';
}
};
8 changes: 4 additions & 4 deletions views/collection.html
Expand Up @@ -204,15 +204,15 @@ <h2>Delete Collection</h2>
</li>
<li>
<strong>Total doc size</strong>
<span class="pull-right">{{ stats.size }} bytes</span>
<span class="pull-right">{{ stats.size|convertBytes }}</span>
</li>
<li>
<strong>Average doc size</strong>
<span class="pull-right">{{ stats.avgObjSize }} bytes</span>
<span class="pull-right">{{ stats.avgObjSize|convertBytes }}</span>
</li>
<li>
<strong>Pre-allocated size</strong>
<span class="pull-right">{{ stats.storageSize }} bytes</span>
<span class="pull-right">{{ stats.storageSize|convertBytes }}</span>
</li>
<li>&nbsp;</li>
<li>
Expand All @@ -221,7 +221,7 @@ <h2>Delete Collection</h2>
</li>
<li>
<strong>Total index size</strong>
<span class="pull-right">{{ stats.totalIndexSize }} bytes</span>
<span class="pull-right">{{ stats.totalIndexSize|convertBytes }}</span>
</li>
<li>&nbsp;</li>
<li>
Expand Down

0 comments on commit e00400f

Please sign in to comment.