diff --git a/src/sunstone/public/app/templates/helpers/humanizeSize.js b/src/sunstone/public/app/templates/helpers/humanizeSize.js new file mode 100644 index 0000000000..56e0553d8e --- /dev/null +++ b/src/sunstone/public/app/templates/helpers/humanizeSize.js @@ -0,0 +1,30 @@ +define(function(require) { + var Handlebars = require('hbs/handlebars'); + var Humanize = require('utils/humanize'); + + /** + * Returns a human readable size in Kilo, Mega, Giga or Tera bytes + * @param {string} unit one of MB, KB, B + * @param {integer} value value + * @param {object} options + * @return {string} human readable size + */ + var humanizeSize = function(unit, value, options) { + switch(unit.toUpperCase()){ + case 'B': + return Humanize.sizeFromB(value); + case 'K': + case 'KB': + return Humanize.sizeFromKB(value); + case 'M': + case 'MB': + return Humanize.sizeFromMB(value); + default: + return value; + } + }; + + Handlebars.registerHelper('humanizeSize', humanizeSize); + + return humanizeSize; +}); \ No newline at end of file diff --git a/src/sunstone/public/app/utils/humanize.js b/src/sunstone/public/app/utils/humanize.js index 72bfc23d4e..4b21fefc0f 100644 --- a/src/sunstone/public/app/utils/humanize.js +++ b/src/sunstone/public/app/utils/humanize.js @@ -12,6 +12,8 @@ define(function(require) { return { 'size': _size, + 'sizeFromB': _sizeFromB, + 'sizeFromKB': _sizeFromKB, 'sizeFromMB': _sizeFromMB, 'prettyTime': _prettyTime, 'prettyTimeAxis': _prettyTimeAxis, @@ -52,6 +54,14 @@ define(function(require) { return st; } + function _sizeFromB(value) { + return _size(value, true); + } + + function _sizeFromKB(value) { + return _size(value); + } + function _sizeFromMB(value) { if (typeof(value) === "undefined") { value = 0;