FIX getting fileSize shouldn't give a "NaN"

This commit is contained in:
Christopher Joe 2016-12-09 15:20:40 +13:00 committed by Damian Mooyman
parent 6ec7804932
commit fcf1eedee4
4 changed files with 32 additions and 17 deletions

View File

@ -840,14 +840,14 @@ n(this,e)}return i(e,null,[{key:"get",value:function t(e){return window.ss.confi
}}]),e}()
t["default"]=r},function(e,t,n){(function(t){e.exports=t.DataFormat=n(148)}).call(t,function(){return this}())},function(e,t,n){"use strict"
function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(null===t)return null
if(t){var n=a({},e.query,t),i=l["default"].stringify(n)
return i?"?"+i:""}return e.search}function o(e){return e<1024?e+" bytes":e<10240?Math.round(e/1024*10)/10+" KB":e<1048576?Math.round(e/1024)+" KB":e<10485760?Math.round(e/1024/1024*10)/10+" MB":e<1073741824?Math.round(e/1024/1024)+" MB":Math.round(e/1073741824*10)/10+" GB"
}Object.defineProperty(t,"__esModule",{value:!0})
if(t){var n=a({},e.query,t),i=c["default"].stringify(n)
return i?"?"+i:""}return e.search}function o(e){var t=null,n=""
return e<1024?(t=e,n="bytes"):e<10240?(t=Math.round(e/1024*10)/10,n="KB"):e<1048576?(t=Math.round(e/1024),n="KB"):e<10485760?(t=Math.round(e/1024*1024*10)/10,n="MB"):e<1073741824&&(t=Math.round(e/1024*1024),
n="MB"),t&&n||(t=Math.round(e/1073741824*10)/10,n="GB"),isNaN(t)?l["default"]._t("File.NO_SIZE","N/A"):t+" "+n}Object.defineProperty(t,"__esModule",{value:!0})
var a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]
for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}
t.urlQuery=r,t.fileSize=o
var s=n(149),l=i(s)},,,function(e,t,n){(function(t){e.exports=t.ReducerRegister=n(152)}).call(t,function(){return this}())},function(e,t){"use strict"
var s=n(115),l=i(s),u=n(149),c=i(u)},,,function(e,t,n){(function(t){e.exports=t.ReducerRegister=n(152)}).call(t,function(){return this}())},function(e,t){"use strict"
function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0})
var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n]
i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),r={},o=function(){function e(){

View File

@ -18,6 +18,7 @@ if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') {
"Campaigns.ITEM_SUMMARY_SINGULAR": "%s item",
"Campaigns.PUBLISHCAMPAIGN": "Publish campaign",
"Campaigns.REVERTCAMPAIGN": "Revert",
"File.NO_SIZE": "N/A",
"FormBuilderModal.CLOSE": "Close",
"LeftAndMain.CONFIRMUNSAVED": "Are you sure you want to navigate away from this page?\n\nWARNING: Your changes have not been saved.\n\nPress OK to continue, or Cancel to stay on the current page.",
"LeftAndMain.CONFIRMUNSAVEDSHORT": "WARNING: Your changes have not been saved.",

View File

@ -11,6 +11,7 @@
"Campaigns.ITEM_SUMMARY_SINGULAR": "%s item",
"Campaigns.PUBLISHCAMPAIGN": "Publish campaign",
"Campaigns.REVERTCAMPAIGN": "Revert",
"File.NO_SIZE": "N/A",
"FormBuilderModal.CLOSE": "Close",
"LeftAndMain.CONFIRMUNSAVED": "Are you sure you want to navigate away from this page?\n\nWARNING: Your changes have not been saved.\n\nPress OK to continue, or Cancel to stay on the current page.",
"LeftAndMain.CONFIRMUNSAVEDSHORT": "WARNING: Your changes have not been saved.",

View File

@ -1,3 +1,4 @@
import i18n from 'i18n';
import QueryString from 'query-string';
export function urlQuery(location, newQuery) {
@ -17,20 +18,32 @@ export function urlQuery(location, newQuery) {
}
export function fileSize(size) {
let number = null;
let metric = '';
if (size < 1024) {
return `${size} bytes`;
number = size;
metric = 'bytes';
} else if (size < 1024 * 10) {
number = Math.round(size / 1024 * 10) / 10;
metric = 'KB';
} else if (size < 1024 * 1024) {
number = Math.round(size / 1024);
metric = 'KB';
} else if (size < 1024 * 1024 * 10) {
number = Math.round(size / 1024 * 1024 * 10) / 10;
metric = 'MB';
} else if (size < 1024 * 1024 * 1024) {
number = Math.round(size / 1024 * 1024);
metric = 'MB';
}
if (size < 1024 * 10) {
return `${Math.round(size / 1024 * 10) / 10} KB`;
if (!number || !metric) {
number = Math.round(size / (1024 * 1024 * 1024) * 10) / 10;
metric = 'GB';
}
if (size < 1024 * 1024) {
return `${Math.round(size / 1024)} KB`;
if (isNaN(number)) {
return i18n._t('File.NO_SIZE', 'N/A');
}
if (size < 1024 * 1024 * 10) {
return `${Math.round((size / 1024) / 1024 * 10) / 10} MB`;
}
if (size < 1024 * 1024 * 1024) {
return `${Math.round((size / 1024) / 1024)} MB`;
}
return `${Math.round(size / (1024 * 1024 * 1024) * 10) / 10} GB`;
return `${number} ${metric}`;
}