[VISTA] custom format tokens (#3469)

* [VISTA] custom format tokens #3468

Co-authored-by: Deep Tailor <deep.j.tailor@nasa.gov>
This commit is contained in:
Nikhil
2020-11-20 12:17:18 -08:00
committed by GitHub
parent 6375ecda34
commit 6fd8f6cd43
4 changed files with 169 additions and 12 deletions

View File

@ -21,12 +21,14 @@
*****************************************************************************/
define([
'../../plugins/displayLayout/CustomStringFormatter',
'./TelemetryMetadataManager',
'./TelemetryValueFormatter',
'./DefaultMetadataProvider',
'objectUtils',
'lodash'
], function (
CustomStringFormatter,
TelemetryMetadataManager,
TelemetryValueFormatter,
DefaultMetadataProvider,
@ -142,6 +144,17 @@ define([
this.valueFormatterCache = new WeakMap();
}
/**
* Return Custom String Formatter
*
* @param {Object} valueMetadata valueMetadata for given telemetry object
* @param {string} format custom formatter string (eg: %.4f, &lts etc.)
* @returns {CustomStringFormatter}
*/
TelemetryAPI.prototype.customStringFormatter = function (valueMetadata, format) {
return new CustomStringFormatter.default(this.openmct, valueMetadata, format);
};
/**
* Return true if the given domainObject is a telemetry object. A telemetry
* object is any object which has telemetry metadata-- regardless of whether
@ -400,6 +413,17 @@ define([
return _.sortBy(options, sortKeys);
};
/**
* @private
*/
TelemetryAPI.prototype.getFormatService = function () {
if (!this.formatService) {
this.formatService = this.openmct.$injector.get('formatService');
}
return this.formatService;
};
/**
* Get a value formatter for a given valueMetadata.
*
@ -407,19 +431,27 @@ define([
*/
TelemetryAPI.prototype.getValueFormatter = function (valueMetadata) {
if (!this.valueFormatterCache.has(valueMetadata)) {
if (!this.formatService) {
this.formatService = this.openmct.$injector.get('formatService');
}
this.valueFormatterCache.set(
valueMetadata,
new TelemetryValueFormatter(valueMetadata, this.formatService)
new TelemetryValueFormatter(valueMetadata, this.getFormatService())
);
}
return this.valueFormatterCache.get(valueMetadata);
};
/**
* Get a value formatter for a given key.
* @param {string} key
*
* @returns {Format}
*/
TelemetryAPI.prototype.getFormatter = function (key) {
const formatMap = this.getFormatService().formatMap;
return formatMap[key];
};
/**
* Get a format map of all value formatters for a given piece of telemetry
* metadata.