From: Alan Knowles Date: Wed, 9 Jun 2021 03:03:25 +0000 (+0800) Subject: fix size formating X-Git-Url: http://git.roojs.org/?p=roojs1;a=commitdiff_plain;h=9da53a68d13d5f73e41052aa33a3b3b44d56e887 fix size formating --- diff --git a/Roo/util/Format.js b/Roo/util/Format.js index 03fbabe9ff..3c0715c367 100644 --- a/Roo/util/Format.js +++ b/Roo/util/Format.js @@ -246,6 +246,7 @@ Roo.util.Format = function(){ stripTags : function(v){ return !v ? v : String(v).replace(this.stripTagsRE, ""); }, + /** * Size in Mb,Gb etc. * @param {Number} value The number to be formated @@ -255,11 +256,11 @@ Roo.util.Format = function(){ size : function(value, decimals) { var sizes = ['b', 'k', 'M', 'G', 'T']; - if (v == 0) { + if (value == 0) { return 0; } - var i = parseInt(Math.floor(Math.log(v) / Math.log(1024))); - return this.number(v / Math.pow(1024, i) ,decimals) + ' ' + sizes[i]; + var i = parseInt(Math.floor(Math.log(value) / Math.log(1024))); + return this.number(value/ Math.pow(1024, i) ,decimals) + ' ' + sizes[i]; } diff --git a/docs/json/roodata.json b/docs/json/roodata.json index 3002d8493d..b9513b8bae 100644 --- a/docs/json/roodata.json +++ b/docs/json/roodata.json @@ -107645,6 +107645,14 @@ "static" : false, "memberOf" : "" }, + { + "name" : "size", + "type" : "function", + "desc" : "Size in Mb,Gb etc.", + "sig" : "(value, decimals)", + "static" : false, + "memberOf" : "" + }, { "name" : "stripTags", "type" : "function", diff --git a/docs/src/Roo_util_Format.js.html b/docs/src/Roo_util_Format.js.html index 26e8e5bcd2..a6e4997d8d 100644 --- a/docs/src/Roo_util_Format.js.html +++ b/docs/src/Roo_util_Format.js.html @@ -245,7 +245,25 @@ */ stripTags : function(v){ return !v ? v : String(v).replace(this.stripTagsRE, ""); + }, + /** + * Size in Mb,Gb etc. + * @param {Number} value The number to be formated + * @param {number} decimals how many decimal places + * @return {String} the formated string + */ + size : function(value, decimals) + { + var sizes = ['b', 'k', 'M', 'G', 'T']; + if (v == 0) { + return 0; + } + var i = parseInt(Math.floor(Math.log(v) / Math.log(1024))); + return this.number(v / Math.pow(1024, i) ,decimals) + ' ' + sizes[i]; } + + + }; }(); Roo.util.Format.defaults = { diff --git a/docs/symbols/Roo.util.Format.json b/docs/symbols/Roo.util.Format.json index b22a27b7b5..2e053ffd65 100644 --- a/docs/symbols/Roo.util.Format.json +++ b/docs/symbols/Roo.util.Format.json @@ -242,6 +242,39 @@ } ] }, + { + "name" : "size", + "desc" : "Size in Mb,Gb etc.", + "isStatic" : false, + "isConstructor" : false, + "isPrivate" : false, + "memberOf" : "Roo.util.Format", + "example" : "", + "deprecated" : "", + "since" : "", + "see" : "", + "params" : [ + { + "name" : "value", + "type" : "Number", + "desc" : "The number to be formated", + "isOptional" : false + }, + { + "name" : "decimals", + "type" : "number", + "desc" : "how many decimal places", + "isOptional" : false + } + ], + "returns" : [ + { + "name" : "", + "type" : "String", + "desc" : "the formated string" + } + ] + }, { "name" : "toFixed", "desc" : "safer version of Math.toFixed..??/", diff --git a/roojs-all.js b/roojs-all.js index e5313d0bc4..b33beb3226 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -574,7 +574,7 @@ return eval(fn).apply(window,B);}else{return eval(fn).call(window,value);}},toFi var fd=(ps[1]+z);var r=fd.substring(0,n);var rm=fd.substring(n);if(rm<5){return ps[0]+'.'+r;}r*=1;r++;if(String(r).length!=n){ps[0]*=1;ps[0]++;r=String(r).substring(1);}return ps[0]+'.'+r;},usMoney:function(v){return '$'+Roo.util.Format.number(v);},number:function(v,B,C){B=typeof(B)=='undefined'?2:B; C=typeof(C)=='undefined'?',':C;var D=Math.pow(10,B);var E=String(D).substring(1);v=(Math.round((v-0)*D))/D;v=String(v);var ps=v.split('.');var F=ps[0];var r=/(\d+)(\d{3})/;if(C.length!=0){F=F.replace(/\B(?=(\d{3})+(?!\d))/g,C);}var G=ps[1]?(B?('.'+ps[1]+E.substring(ps[1].length)):''):(B?('.'+E):''); return F+G;},date:function(v,B){if(!v){return "";}if(!(v instanceof Date)){v=new Date(Date.parse(v));}return v.dateFormat(B||Roo.util.Format.defaults.date);},dateRenderer:function(B){return function(v){return Roo.util.Format.date(v,B);};},stripTagsRE:/<\/?[^>]+>/gi,stripTags:function(v){return !v?v:String(v).replace(this.stripTagsRE,""); -}};}();Roo.util.Format.defaults={date:'d/M/Y'}; +},size:function(B,C){var D=['b','k','M','G','T'];if(v==0){return 0;}var i=parseInt(Math.floor(Math.log(v)/Math.log(1024)));return this.number(v/Math.pow(1024,i),C)+' '+D[i];}};}();Roo.util.Format.defaults={date:'d/M/Y'}; // Roo/MasterTemplate.js Roo.MasterTemplate=function(){Roo.MasterTemplate.superclass.constructor.apply(this,arguments);this.originalHtml=this.html;var st={};var m,re=this.subTemplateRe;re.lastIndex=0;var A=0;while(m=re.exec(this.html)){var B=m[1],C=m[2];st[A]={name:B,index:A,buffer:[],tpl:new Roo.Template(C)} ;if(B){st[B]=st[A];}st[A].tpl.compile();st[A].tpl.call=this.call.createDelegate(this);A++;}this.subCount=A;this.subs=st;};Roo.extend(Roo.MasterTemplate,Roo.Template,{subTemplateRe:/((?:.|\n)*?)<\/tpl>/gi,add:function(A,B){if(arguments.length==1){B=arguments[0]; diff --git a/roojs-core-debug.js b/roojs-core-debug.js index 02931daa5c..02fc5b290f 100644 --- a/roojs-core-debug.js +++ b/roojs-core-debug.js @@ -13990,7 +13990,25 @@ Roo.util.Format = function(){ */ stripTags : function(v){ return !v ? v : String(v).replace(this.stripTagsRE, ""); + }, + /** + * Size in Mb,Gb etc. + * @param {Number} value The number to be formated + * @param {number} decimals how many decimal places + * @return {String} the formated string + */ + size : function(value, decimals) + { + var sizes = ['b', 'k', 'M', 'G', 'T']; + if (v == 0) { + return 0; + } + var i = parseInt(Math.floor(Math.log(v) / Math.log(1024))); + return this.number(v / Math.pow(1024, i) ,decimals) + ' ' + sizes[i]; } + + + }; }(); Roo.util.Format.defaults = { diff --git a/roojs-core.js b/roojs-core.js index 0d25211989..d5c015de8b 100644 --- a/roojs-core.js +++ b/roojs-core.js @@ -574,7 +574,7 @@ return eval(fn).apply(window,B);}else{return eval(fn).call(window,value);}},toFi var fd=(ps[1]+z);var r=fd.substring(0,n);var rm=fd.substring(n);if(rm<5){return ps[0]+'.'+r;}r*=1;r++;if(String(r).length!=n){ps[0]*=1;ps[0]++;r=String(r).substring(1);}return ps[0]+'.'+r;},usMoney:function(v){return '$'+Roo.util.Format.number(v);},number:function(v,B,C){B=typeof(B)=='undefined'?2:B; C=typeof(C)=='undefined'?',':C;var D=Math.pow(10,B);var E=String(D).substring(1);v=(Math.round((v-0)*D))/D;v=String(v);var ps=v.split('.');var F=ps[0];var r=/(\d+)(\d{3})/;if(C.length!=0){F=F.replace(/\B(?=(\d{3})+(?!\d))/g,C);}var G=ps[1]?(B?('.'+ps[1]+E.substring(ps[1].length)):''):(B?('.'+E):''); return F+G;},date:function(v,B){if(!v){return "";}if(!(v instanceof Date)){v=new Date(Date.parse(v));}return v.dateFormat(B||Roo.util.Format.defaults.date);},dateRenderer:function(B){return function(v){return Roo.util.Format.date(v,B);};},stripTagsRE:/<\/?[^>]+>/gi,stripTags:function(v){return !v?v:String(v).replace(this.stripTagsRE,""); -}};}();Roo.util.Format.defaults={date:'d/M/Y'}; +},size:function(B,C){var D=['b','k','M','G','T'];if(v==0){return 0;}var i=parseInt(Math.floor(Math.log(v)/Math.log(1024)));return this.number(v/Math.pow(1024,i),C)+' '+D[i];}};}();Roo.util.Format.defaults={date:'d/M/Y'}; // Roo/MasterTemplate.js Roo.MasterTemplate=function(){Roo.MasterTemplate.superclass.constructor.apply(this,arguments);this.originalHtml=this.html;var st={};var m,re=this.subTemplateRe;re.lastIndex=0;var A=0;while(m=re.exec(this.html)){var B=m[1],C=m[2];st[A]={name:B,index:A,buffer:[],tpl:new Roo.Template(C)} ;if(B){st[B]=st[A];}st[A].tpl.compile();st[A].tpl.call=this.call.createDelegate(this);A++;}this.subCount=A;this.subs=st;};Roo.extend(Roo.MasterTemplate,Roo.Template,{subTemplateRe:/((?:.|\n)*?)<\/tpl>/gi,add:function(A,B){if(arguments.length==1){B=arguments[0]; diff --git a/roojs-debug.js b/roojs-debug.js index ba91ad09ee..4c9a82c533 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -13990,7 +13990,25 @@ Roo.util.Format = function(){ */ stripTags : function(v){ return !v ? v : String(v).replace(this.stripTagsRE, ""); + }, + /** + * Size in Mb,Gb etc. + * @param {Number} value The number to be formated + * @param {number} decimals how many decimal places + * @return {String} the formated string + */ + size : function(value, decimals) + { + var sizes = ['b', 'k', 'M', 'G', 'T']; + if (v == 0) { + return 0; + } + var i = parseInt(Math.floor(Math.log(v) / Math.log(1024))); + return this.number(v / Math.pow(1024, i) ,decimals) + ' ' + sizes[i]; } + + + }; }(); Roo.util.Format.defaults = {