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
This commit is contained in:
Matthias Schiffer 2016-02-24 22:20:18 +01:00
parent 5a2f130323
commit 6e452f207a
2 changed files with 25 additions and 4 deletions

View File

@ -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) {

View File

@ -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
}
})