[Kimchi-devel] [PATCH] [Wok 1/3] Introduced converters in formatMeasurement
Aline Manera
alinefm at linux.vnet.ibm.com
Wed May 18 02:28:17 UTC 2016
On 05/13/2016 11:18 AM, pkulkark at linux.vnet.ibm.com wrote:
> From: Pooja Kulkarni <pkulkark at linux.vnet.ibm.com>
>
> 1)Added converters in formatMeasurement
> which enables formatting of data to be
> displayed.
> 2)Renamed datetimeLocaleConverters to
> localeConverters in order to make it
> generic and added number converter.
>
> Signed-off-by: Pooja Kulkarni <pkulkark at linux.vnet.ibm.com>
> ---
> ui/js/src/wok.utils.js | 33 +++++++++++++++++++++++++--------
> 1 file changed, 25 insertions(+), 8 deletions(-)
>
> diff --git a/ui/js/src/wok.utils.js b/ui/js/src/wok.utils.js
> index 74b623c..81e7c4f 100644
> --- a/ui/js/src/wok.utils.js
> +++ b/ui/js/src/wok.utils.js
> @@ -140,7 +140,13 @@ wok.changetoProperUnit = function(numOrg, digits, base) {
> return new Formatted(number, unit);
> }
>
> - var n_locale = settings['locale'] || null;
> + // Introduce converter to format data.
> + // Converter's to function will be used for formatting.
> + // if not passed then 'to' formatting will not be done.
> + // e.g. formatMeasurement( 2,
> + // { .. , converter: wok.localeConverters["number-locale-converter"]})
> + var converter = settings['converter'] || null;
> + var converter_to_fun = converter?converter['to']:''
I'd suggest to use spaces around ? and : to make it easier to read. But
I can do that before applying so you don't need to send a V2.
> var fixed = settings['fixed'];
>
> var unitMapping = unitBaseMapping[base];
> @@ -154,14 +160,14 @@ wok.changetoProperUnit = function(numOrg, digits, base) {
>
> var formatted = number / startingValue;
> formatted = fixed ? formatted.toFixed(fixed) : formatted;
> - formatted = n_locale ? Number(formatted).toLocaleString(n_locale) : Number(formatted).toLocaleString()
> + formatted = converter_to_fun ? converter_to_fun(Number(formatted)) : formatted;
> return new Formatted(formatted, suffix + unit);
> }
>
> formatted = fixed ? number.toFixed(fixed) : number;
> - /* format the formatted number as per settings's locale, if not present format it with default locale. */
> - formatted_locale = n_locale ? Number(formatted).toLocaleString(n_locale) : Number(formatted).toLocaleString()
> - return new Formatted(formatted_locale, unit);
> + /* format the formatted number as per settings's converter, if not present return as it is. */
> + formatted_val = converter_to_fun ? converter_to_fun(Number(formatted)) : formatted;
> + return new Formatted(formatted_val, unit);
> };
>
> wok.formatMeasurement = format;
> @@ -237,7 +243,13 @@ wok.timeLocaleConverter = function timeLocaleConverter(time_string, locale){
> }
>
>
> -wok.dateTimeLocaleConverters = {
> +wok.numberLocaleConverter = function numberConverter(number, locale){
> + number = (typeof(number)==='number')?number.toLocaleString(wok.lang.get_locale()):number;
Same I commented above.
> + return number;
> +}
> +
> +
> +wok.localeConverters = {
> "date-locale-converter": {
> to: function(date){
> return wok.dateLocaleConverter(date, wok.lang.get_locale());
> @@ -252,5 +264,10 @@ wok.dateTimeLocaleConverters = {
> to: function(datetime){
> return wok.datetimeLocaleConverter(datetime, wok.lang.get_locale());
> }
> - }
> - }
> + },
> + "number-locale-converter":{
> + to: function(number){
> + return wok.numberLocaleConverter(number, wok.lang.get_locale());
> + }
> + }
> +}
More information about the Kimchi-devel
mailing list