From 6e452f207a747adf64de2f1fa7250a6a7a663a30 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 24 Feb 2016 22:20:18 +0100 Subject: [PATCH] gluon-status-page: don't use internationalization API It is not supported by all browsers yet. Also change load display always to display 2 decimal digits (as it is read from the kernel with 2 decimal digits). Fixes #606 --- .../src/js/lib/gui/statistics.js | 8 +++---- .../gluon-status-page/src/js/lib/helper.js | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/package/gluon-status-page/src/js/lib/gui/statistics.js b/package/gluon-status-page/src/js/lib/gui/statistics.js index 7f09323c..3dcf5a52 100644 --- a/package/gluon-status-page/src/js/lib/gui/statistics.js +++ b/package/gluon-status-page/src/js/lib/gui/statistics.js @@ -171,7 +171,7 @@ define(["lib/helper"], function (Helper) { } function prettyPackets(d) { - var v = new Intl.NumberFormat("de-DE", {maximumFractionDigits: 0}).format(d) + var v = Helper.formatNumberFixed(d, 0) return v + " Pakete/s" } @@ -183,7 +183,7 @@ define(["lib/helper"], function (Helper) { prefix++ } - d = new Intl.NumberFormat("de-DE", {maximumSignificantDigits: 3}).format(d) + d = Helper.formatNumber(d, 3) return d + " " + prefixes[prefix] } @@ -220,11 +220,11 @@ define(["lib/helper"], function (Helper) { } function prettyNVRAM(usage) { - return new Intl.NumberFormat("de-DE", {maximumSignificantDigits: 3}).format(usage * 100) + "% belegt" + return Helper.formatNumber(usage * 100, 3) + "% belegt" } function prettyLoad(load) { - return new Intl.NumberFormat("de-DE", {maximumSignificantDigits: 3}).format(load) + return Helper.formatNumberFixed(load, 2) } function prettyRAM(memory) { diff --git a/package/gluon-status-page/src/js/lib/helper.js b/package/gluon-status-page/src/js/lib/helper.js index 6b39bc0a..c0c0ce2f 100644 --- a/package/gluon-status-page/src/js/lib/helper.js +++ b/package/gluon-status-page/src/js/lib/helper.js @@ -51,6 +51,25 @@ define([ "bacon" ], function (Bacon) { return dictGet(dict[k], key) } + function localizeNumber(d) { + var sep = ',' + return d.replace('.', sep) + } + + function formatNumberFixed(d, digits) { + return localizeNumber(d.toFixed(digits)) + } + + function formatNumber(d, digits) { + digits-- + + for (var v = d; v >= 10 && digits > 0; v /= 10) + digits-- + + // avoid toPrecision as it might produce strings in exponential notation + return formatNumberFixed(d, digits) + } + function haversine() { var radians = Array.prototype.map.call(arguments, function(deg) { return deg / 180.0 * Math.PI }) var lat1 = radians[0], lon1 = radians[1], lat2 = radians[2], lon2 = radians[3] @@ -66,6 +85,8 @@ define([ "bacon" ], function (Bacon) { , request: request , getJSON: getJSON , dictGet: dictGet + , formatNumber: formatNumber + , formatNumberFixed: formatNumberFixed , haversine: haversine } })