Skip to main content
Pentaho Documentation

Utils

cdf.dashboard.Utils

 
Static

A collection of utility functions.

AMD Module

require(["cdf/dashboard/Utils"], function(Utils) { /* code goes here */ });

Source: dashboard/Utils.js, line 23

Methods

Name Description
Utils.addArgs(url)
 
Deprecated

Adds the URL parameters to a local object.

Utils.clone(obj) : object
 
Deprecated

Deep clones an object.

Utils.configLanguage(langCode, config)

Configure a language.

Utils.dateFormat(date, mask, langCode) : string

Formats a date.

Utils.dateParse(date, mask) : Date

Parses a date with a given mask.

Utils.doCsvQuoting(value, separator, alwaysEscape) : string

Quote CSV values in a way that is compatible with CSVTokenizer.

Utils.eachValuesArray(values, opts, f, x) : boolean

Traverses each value, label, and id triple of a values array.

Utils.equalValues(a, b) : boolean

Determines if two values are considered equal.

Utils.escapeHtml(input) : string

Escapes a string as an HTML safe string.

Utils.ev(o) : object

Evaluates the argument.

Utils.getArgValue(key) : object | undefined
 
Deprecated

Gets an argument value that was previously set by calling addArgs.

Utils.getLocationSearchString() : string

Returns the query string part of the URL.

Utils.getPathParameter(url) : string | undefined

Gets the path from the URL.

Utils.getQueryParameter(parameterName) : string

Returns the value of a query string parameter.

Utils.getURLParameters(sURL) : Array.<Array.<String>>

Gets the parameters from a URL.

Utils.hsvToRgb(h, s, v) : string

Converts an HSV to an RGB color value.

Utils.isArray(value) : boolean

Determines if a value is considered an array.

Utils.normalizeValue(value) : object

Normalizes a value.

Utils.numberFormat(value, mask, langCode) : string

Formats a number.

Utils.objectToPropertiesArray(obj) : Array.<Array.<Object>> | undefined

Converts an object to an array.

Utils.parseMultipleValues(value) : array | object

Given a parameter value obtains an equivalent values array.

Utils.post(url, obj)

Performs a post to the server.

Utils.propertiesArrayToObject(pArray) : object | undefined

Converts an array to an object.

Methods Details

Utils.addArgs(url)
 
Deprecated

Adds the URL parameters to a local args object.

Source: dashboard/Utils.js, line 452

Parameters:
Name Default Value Summary
url : string

The URL from which to extract the parameters.

Utils.clone(obj) : object
 
Deprecated

Deep clones an object. This method is deprecated, use jQuery.extend.

Source: dashboard/Utils.js, line 414

Parameters:
Name Default Value Summary
obj : object

The object to clone.

Returns:
Name Description
object

The cloned object.

Utils.configLanguage(langCode, config)

Configure a new or existing language by specifying the language code and a configuration object.

Source: dashboard/Utils.js, line 162

Parameters:
Name Default Value Summary
langCode : string

Language code to be used.

config : object

Object with the language configuration.

Parameters:
Name Default Value Summary
number : object

Number format language configuration.

dateLocale : object

Date format language configuration.

Utils.dateFormat(date, mask, langCode) : string

Formats a date with a given mask using the dashboard language, the one that the user specified if it exists, or the default language 'en-US'.

Source: dashboard/Utils.js, line 184

Parameters:
Name Default Value Summary
date : Date

Date object to be formatted.

mask : string

Mask with format for the date.

langCode : string

Language to use in format.

Returns:
Name Description
string

The formatted date.

Utils.dateParse(date, mask) : Date

Parses a date with a given mask.

Source: dashboard/Utils.js, line 212

Parameters:
Name Default Value Summary
date : string

The date to be parsed.

mask : string

The mask with the format for the date.

Returns:
Name Description
Date

The parsed date as a Date object.

Utils.doCsvQuoting(value, separator, alwaysEscape) : string

Quote CSV values in a way that is compatible with CSVTokenizer.

Source: dashboard/Utils.js, line 346

Parameters:
Name Default Value Summary
value : string

Value quote.

separator : string

Separator to use when quoting.

alwaysEscape : boolean

Flag that indicates if the value should always be escaped or just when needed.

Returns:
Name Description
string | null

The escaped value or null.

Utils.eachValuesArray(values, opts, f, x) : boolean

Traverses each value, label and id triple of a values array.

Source: dashboard/Utils.js, line 518

Parameters:
Name Default Value Summary
values : Array.<Array.<string>>

The values array - an array of arrays.

Each second-level array is a value specification and contains a value and, optionally, a label and an id. It may have the following forms:

  • [valueAndLabel]: when having length one
  • [value, label,...]: when having length two or more and opts.valueAsId is falsy
  • [id, valueAndLabel,..]: when having length two or more and opts.valueAsId is truthy
opts : object

An object with options.

Parameters:
Name Default Value Summary
valueAsId : boolean
 
Optional
false

Indicates if the first element of the value specification array is the id, instead of the value.

f : function

The traversal function that is to be called with each value-label-id triple and with the JS context x. The function is called with arguments: value, label, id, and index.

When the function returns the value false, traversal is stopped, and false is returned.

x : object

The JS context object on which f is to be called.

Returns:
Name Description
boolean

true if the traversal was complete, false if explicitly stopped by the traversal function.

Utils.equalValues(a, b) : boolean

Determines if two values are considered equal.

Source: dashboard/Utils.js, line 615

Parameters:
Name Default Value Summary
a : object

The first value.

b : object

The second value.

Returns:
Name Description
boolean

true if equal, false otherwise.

Utils.escapeHtml(input) : string

Escapes a string as an HTML safe string. It assumes that, if there is an escaped char in the input, then the input is fully escaped.

Source: dashboard/Utils.js, line 61

Parameters:
Name Default Value Summary
input : string

The string to be escaped.

Returns:
Name Description
string

The escaped string or an empty string if it receives anything other than a string.

Utils.ev(o) : object

Evaluates the argument. If it is a function, calls the function, otherwise returns the argument.

Source: dashboard/Utils.js, line 374

Parameters:
Name Default Value Summary
o : object

The object to try and evaluate as a function.

Returns:
Name Description
object

The value of o if it isn't a function. Otherwise, the result of invoking o.

Utils.getArgValue(key) : object | undefined
 
Deprecated

Gets an argument value that was previously set by calling addArgs. This is deprecated, so use getQueryParameter or dashboard.context.params.

Source: dashboard/Utils.js, line 472

Parameters:
Name Default Value Summary
key : string

The argument name.

Returns:
Name Description
object | undefined

The argument value or undefined.

Utils.getLocationSearchString() : string

Returns the query string part of the URL.

Source: dashboard/Utils.js, line 104

Returns:
Name Description
string

The query string.

Utils.getPathParameter(url) : string | undefined

Given a URL containing an encoded Pentaho path, e.g. :home:admin:Test.wcdf, returns the encoded path.

Source: dashboard/Utils.js, line 85

Parameters:
Name Default Value Summary
url : string

The URL to encode.

Returns:
Name Description
string | undefined

The encoded URL or undefined if not available.

Utils.getQueryParameter(parameterName) : string

Returns the value of a query string parameter.

Source: dashboard/Utils.js, line 116

Parameters:
Name Default Value Summary
parameterName : string

The name of the parameter.

Returns:
Name Description
string

The value of the query parameter or an empty string.

Utils.getURLParameters(sURL) : Array.<Array.<String>>

Gets the parameters from a URL. CDF URL parameters are defined as those that are present in the query string with names starting with the string param. So, for a query string like ?paramfoo=bar, you would get a parameter foo with value bar.

Source: dashboard/Utils.js, line 293

Parameters:
Name Default Value Summary
sURL : string

URL with the query string to be parsed.

Returns:
Name Description
Array.<Array.<String>>

Array with the parsed parameters. Each element is an array with two positions, the first being the parameter name and the second the value. For example, .

Utils.hsvToRgb(h, s, v) : string

Converts an HSV to an RGB color value. Based on the algorithm described at http://en.wikipedia.org/wiki/HSL_and_HSV.

Source: dashboard/Utils.js, line 644

Parameters:
Name Default Value Summary
h : number

Hue as a value between 0 - 360 (degrees).

s : number

Saturation as a value between 0 - 100 (%).

v : number

Value as a value between 0 - 100 (%).

Returns:
Name Description
string

A RGB color string (e.g. "rgb(1,2,3)").

Utils.isArray(value) : boolean

Determines if a value is considered an array.

Returns true if value is an array, or an array-like object (object containing the methods join and length).

Source: dashboard/Utils.js, line 600

Parameters:
Name Default Value Summary
value : object

The value.

Returns:
Name Description
boolean

true if it is an array or an array-like object, false otherwise.

Utils.normalizeValue(value) : object

Normalizes a value so that undefined, empty string, and empty array are all translated to null.

Source: dashboard/Utils.js, line 584

Parameters:
Name Default Value Summary
value : object

The value to normalize.

Returns:
Name Description
object | null

The normalized value or null.

Utils.numberFormat(value, mask, langCode) : string

Formats a number with a given mask using the dashboard language, the one that the user specified if it exists, or the default language 'en-US'.

Source: dashboard/Utils.js, line 136

Parameters:
Name Default Value Summary
value : number

Number value to be formatted.

mask : string

Mask with format for the value.

langCode : string

Language to use in format.

Returns:
Name Description
string

The formatted number.

Utils.objectToPropertiesArray(obj) : Array.<Array.<Object>> | undefined

Converts an object to an array.

Source: dashboard/Utils.js, line 276

Parameters:
Name Default Value Summary
obj : object

The object to be converted into an array.

Returns:
Name Description
Array.<Array.<Object>> | undefined

An array of key-value pairs (array) or undefined if the argument is not an object, e. g., .

Utils.parseMultipleValues(value) : array | object

Given a parameter value obtains an equivalent values array.

The parameter value may encode multiple values in a string format.

A nully (i.e. null or undefined) input value or an empty string results in null, so the result of this method is normalized.

A string value may contain multiple values separated by the character |.

An array or array-like object is returned without modification.

Any other value type returns null.

Source: dashboard/Utils.js, line 564

Parameters:
Name Default Value Summary
value : object

A parameter value, as returned by getParameterValue.

Returns:
Name Description
array | object

An array, an array-like object, or null.

Utils.post(url, obj)

Performs a post to the server.

Source: dashboard/Utils.js, line 386

Parameters:
Name Default Value Summary
url : string

The URL where to post.

obj : object

Parameter object.

Utils.propertiesArrayToObject(pArray) : object | undefined

Converts an array to an object.

Source: dashboard/Utils.js, line 261

Parameters:
Name Default Value Summary
pArray : Array.<Array.<Object>>

An array of key-value pairs (array) to be converted, e.g.,.

Returns:
Name Description
object | undefined /p