From 0a54f0cf2d332c010d8819f1883fb6007c856bf8 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 19 May 2017 16:21:26 +0200 Subject: [PATCH 1/4] better alignment of preview and code entry --- www/code/inner.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/code/inner.html b/www/code/inner.html index 36d5911ee..0ef693f1c 100644 --- a/www/code/inner.html +++ b/www/code/inner.html @@ -78,7 +78,7 @@ overflow: auto; display: inline-block; height: 100%; - border: 1px solid black; + border-left: 1px solid black; box-sizing: border-box; font-family: Calibri,Ubuntu,sans-serif; } From 1378a0c1f62f678e115168a94d13db5fdec3568e Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 19 May 2017 16:56:45 +0200 Subject: [PATCH 2/4] serve blobs from configured location --- server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index d7f5b90fc..037a8adeb 100644 --- a/server.js +++ b/server.js @@ -8,6 +8,7 @@ var Fs = require('fs'); var WebSocketServer = require('ws').Server; var NetfluxSrv = require('./node_modules/chainpad-server/NetfluxWebsocketSrv'); var Package = require('./package.json'); +var Path = require("path"); var config = require('./config'); var websocketPort = config.websocketPort || config.httpPort; @@ -82,7 +83,7 @@ var mainPages = config.mainPages || ['index', 'privacy', 'terms', 'about', 'cont var mainPagePattern = new RegExp('^\/(' + mainPages.join('|') + ').html$'); app.get(mainPagePattern, Express.static(__dirname + '/customize.dist')); -app.use("/blob", Express.static(__dirname + '/blob')); +app.use("/blob", Express.static(Path.join(__dirname, (config.blobPath || './blob')))); app.use("/customize", Express.static(__dirname + '/customize')); app.use("/customize", Express.static(__dirname + '/customize.dist')); From ba5ef5157e93c85d92f02fc4a5cb4527b46b5c51 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 19 May 2017 18:37:31 +0200 Subject: [PATCH 3/4] show pretty representations of storage usage --- customize.dist/translations/messages.es.js | 4 +++ customize.dist/translations/messages.fr.js | 3 ++ customize.dist/translations/messages.js | 4 +++ www/common/common-util.js | 17 ++++++++++-- www/common/cryptpad-common.js | 32 ++++++++++++++++------ 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/customize.dist/translations/messages.es.js b/customize.dist/translations/messages.es.js index 2346579fb..d2359c44b 100644 --- a/customize.dist/translations/messages.es.js +++ b/customize.dist/translations/messages.es.js @@ -410,6 +410,10 @@ define(function () { out.upgrade = "Mejorar"; out.upgradeTitle = "Mejora tu cuenta para obtener más espacio"; out.MB = "MB"; + out.GB = "GB"; + out.formattedMB = "{0} MB"; + out.formattedGB = "{0} GB"; + out.pinLimitReached = "Has llegado al limite de espacio"; out.pinLimitReachedAlert = "Has llegado al limite de espacio. Nuevos pads no serán movidos a tu CryptDrive.
Para resolver este problema, puedes quitar pads de tu CryptDrive (incluso en la papelera) o mejorar tu cuenta para obtener más espacio."; out.pinLimitNotPinned = "Has llegado al limite de espacio.
Este pad no estará presente en tu CryptDrive."; diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index e8cc86ce2..5dfd383b0 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -61,6 +61,9 @@ define(function () { out.upgrade = "Améliorer"; out.upgradeTitle = "Améliorer votre compte pour augmenter la limite de stockage"; out.MB = "Mo"; + out.GB = "Go"; + out.formattedMB = "{0} Mo"; + out.formattedGB = "{0} Go"; out.greenLight = "Tout fonctionne bien"; out.orangeLight = "Votre connexion est lente, ce qui réduit la qualité de l'éditeur"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index f0ce247fc..6cbff3d7f 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -63,6 +63,10 @@ define(function () { out.upgrade = "Upgrade"; out.upgradeTitle = "Upgrade your account to increase the storage limit"; out.MB = "MB"; + out.GB = "GB"; + + out.formattedMB = "{0} MB"; + out.formattedGB = "{0} GB"; out.greenLight = "Everything is working fine"; out.orangeLight = "Your slow connection may impact your experience"; diff --git a/www/common/common-util.js b/www/common/common-util.js index a5822c743..f04b85199 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -81,12 +81,25 @@ define([], function () { .replace(/_+/g, '_'); }; + var oneKilobyte = 1024; + var oneMegabyte = 1024 * oneKilobyte; + var oneGigabyte = 1024 * oneMegabyte; + + Util.bytesToGigabytes = function (bytes) { + return Math.ceil(bytes / oneGigabyte * 100) / 100; + }; + Util.bytesToMegabytes = function (bytes) { - return Math.floor((bytes / (1024 * 1024) * 100)) / 100; + return Math.ceil(bytes / oneMegabyte * 100) / 100; }; Util.bytesToKilobytes = function (bytes) { - return Math.floor(bytes / 1024 * 100) / 100; + return Math.ceil(bytes / oneKilobyte * 100) / 100; + }; + + Util.magnitudeOfBytes = function (bytes) { + if (bytes >= oneGigabyte) { return 'GB'; } + else if (bytes >= oneMegabyte) { return 'MB'; } }; Util.fetch = function (src, cb) { diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 6f0a5e256..9bbebbed3 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -745,8 +745,7 @@ define([ if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); } rpc.updatePinLimits(function (e, limit, plan) { if (e) { return cb(e); } - var MB = common.bytesToMegabytes(limit); - cb(e, MB, plan); + cb(e, limit, plan); }); }; @@ -754,8 +753,7 @@ define([ if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); } rpc.getLimit(function (e, limit, plan) { if (e) { return cb(e); } - var MB = common.bytesToMegabytes(limit); - cb(void 0, MB, plan); + cb(void 0, limit, plan); }); }; @@ -771,7 +769,7 @@ define([ return void cb (null, false, data); }; var todo = function (e, used) { - usage = common.bytesToMegabytes(used); + usage = used; //common.bytesToMegabytes(used); if (e) { return void cb(e); } common.getPinLimit(andThen); }; @@ -802,9 +800,14 @@ define([ common.isOverPinLimit(todo); }, LIMIT_REFRESH_RATE); } - var usage = data.usage; - var limit = data.limit; - var unit = Messages.MB; + + var unit = Util.magnitudeOfBytes(data.limit); + + var usage = unit === 'GB'? Util.bytesToGigabytes(data.usage): + Util.bytesToMegabytes(data.usage); + var limit = unit === 'GB'? Util.bytesToGigabytes(data.limit): + Util.bytesToMegabytes(data.limit); + var $limit = $('', {'class': 'cryptpad-limit-bar'}).appendTo($container); var quota = usage/limit; var width = Math.floor(Math.min(quota, 1)*200); // the bar is 200px width @@ -823,11 +826,22 @@ define([ }).text(Messages.upgrade).appendTo($upgradeLink); } + var prettyUsage; + var prettyLimit; + + if (unit === 'GB') { + prettyUsage = usage; //Messages._getKey('formattedGB', [usage]); + prettyLimit = Messages._getKey('formattedGB', [limit]); + } else { + prettyUsage = usage; //Messages._getKey('formattedMB', [usage]); + prettyLimit = Messages._getKey('formattedMB', [limit]); + } + if (quota < 0.8) { $usage.addClass('normal'); } else if (quota < 1) { $usage.addClass('warning'); } else { $usage.addClass('above'); } var $text = $('', {'class': 'usageText'}); - $text.text(usage + ' / ' + limit + ' ' + unit); + $text.text(prettyUsage + ' / ' + prettyLimit); $limit.append($usage).append($text); window.setTimeout(function () { common.isOverPinLimit(todo); From 03da870a7a4a3188496aa12f9ec7f6ec0e31496b Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 19 May 2017 19:38:57 +0200 Subject: [PATCH 4/4] jshint compliance --- www/file/main.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/www/file/main.js b/www/file/main.js index eb53cca47..ada0b50d2 100644 --- a/www/file/main.js +++ b/www/file/main.js @@ -73,13 +73,9 @@ define([ if (box) { actual += box.length; var progressValue = (actual / estimate * 100); - var progress = progressValue + '%'; return void sendChunk(box, function (e) { if (e) { return console.error(e); } - /*$progress.css({ - width: progress, - });*/ var $pv = $table.find('tr[id="'+id+'"]').find('.progressValue'); $pv.text(Math.round(progressValue*100)/100 + '%'); var $pb = $table.find('tr[id="'+id+'"]').find('.progressContainer'); @@ -179,17 +175,17 @@ define([ var $tr = $('', {id: id}).appendTo($table); var $cancel = $('', {'class': 'cancel fa fa-times'}).click(function () { - queue.queue = queue.queue.filter(function (el) { return el.id !== id }); + queue.queue = queue.queue.filter(function (el) { return el.id !== id; }); $cancel.remove(); $tr.find('.upCancel').text('-'); $tr.find('.progressValue').text(Messages.upload_cancelled); }); - var $tr = $('', {id: id}).appendTo($table); - $('').text(obj.metadata.name).appendTo($tr); - $('').text(prettySize(estimate)).appendTo($tr); - $('', {'class': 'upProgress'}).append($progressBar).append($progressValue).appendTo($tr); - $('', {'class': 'upCancel'}).append($cancel).appendTo($tr); + var $tr2 = $('', {id: id}).appendTo($table); + $('').text(obj.metadata.name).appendTo($tr2); + $('').text(prettySize(estimate)).appendTo($tr2); + $('', {'class': 'upProgress'}).append($progressBar).append($progressValue).appendTo($tr2); + $('', {'class': 'upCancel'}).append($cancel).appendTo($tr2); queue.next(); };