Permalink
Browse files

Stats now display in byte, KB or MB units.

Added template filter for converting byte values.
  • Loading branch information...
1 parent 65945fb commit e00400fde42bcfbff3b42517db13e08dc0910578 @andzdroid andzdroid committed May 8, 2012
Showing with 20 additions and 4 deletions.
  1. +16 −0 filters.js
  2. +4 −4 views/collection.html
View
@@ -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';
+ }
+};
View
@@ -204,15 +204,15 @@
</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>
@@ -221,7 +221,7 @@
</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>

0 comments on commit e00400f

Please sign in to comment.