mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
chore: add prettier
(2/3): apply formatting, re-enable lint ci step (#6682)
* style: apply prettier formatting * fix: re-enable lint ci check
This commit is contained in:
@ -20,139 +20,135 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'lodash'
|
||||
], function (
|
||||
_
|
||||
) {
|
||||
define(['lodash'], function (_) {
|
||||
function applyReasonableDefaults(valueMetadata, index) {
|
||||
valueMetadata.source = valueMetadata.source || valueMetadata.key;
|
||||
valueMetadata.hints = valueMetadata.hints || {};
|
||||
|
||||
function applyReasonableDefaults(valueMetadata, index) {
|
||||
valueMetadata.source = valueMetadata.source || valueMetadata.key;
|
||||
valueMetadata.hints = valueMetadata.hints || {};
|
||||
if (Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'x')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'domain')) {
|
||||
valueMetadata.hints.domain = valueMetadata.hints.x;
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'x')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'domain')) {
|
||||
valueMetadata.hints.domain = valueMetadata.hints.x;
|
||||
}
|
||||
|
||||
delete valueMetadata.hints.x;
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'y')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'range')) {
|
||||
valueMetadata.hints.range = valueMetadata.hints.y;
|
||||
}
|
||||
|
||||
delete valueMetadata.hints.y;
|
||||
}
|
||||
|
||||
if (valueMetadata.format === 'enum') {
|
||||
if (!valueMetadata.values) {
|
||||
valueMetadata.values = valueMetadata.enumerations.map(e => e.value);
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata, 'max')) {
|
||||
valueMetadata.max = Math.max(valueMetadata.values) + 1;
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata, 'min')) {
|
||||
valueMetadata.min = Math.min(valueMetadata.values) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'priority')) {
|
||||
valueMetadata.hints.priority = index;
|
||||
}
|
||||
|
||||
return valueMetadata;
|
||||
delete valueMetadata.hints.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility class for handling and inspecting telemetry metadata. Applies
|
||||
* reasonable defaults to simplify the task of providing metadata, while
|
||||
* also providing methods for interrogating telemetry metadata.
|
||||
*/
|
||||
function TelemetryMetadataManager(metadata) {
|
||||
this.metadata = metadata;
|
||||
if (Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'y')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'range')) {
|
||||
valueMetadata.hints.range = valueMetadata.hints.y;
|
||||
}
|
||||
|
||||
this.valueMetadatas = this.metadata.values ? this.metadata.values.map(applyReasonableDefaults) : [];
|
||||
delete valueMetadata.hints.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value metadata for a single key.
|
||||
*/
|
||||
TelemetryMetadataManager.prototype.value = function (key) {
|
||||
return this.valueMetadatas.filter(function (metadata) {
|
||||
return metadata.key === key;
|
||||
})[0];
|
||||
};
|
||||
if (valueMetadata.format === 'enum') {
|
||||
if (!valueMetadata.values) {
|
||||
valueMetadata.values = valueMetadata.enumerations.map((e) => e.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all value metadatas, sorted by priority.
|
||||
*/
|
||||
TelemetryMetadataManager.prototype.values = function () {
|
||||
return this.valuesForHints(['priority']);
|
||||
};
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata, 'max')) {
|
||||
valueMetadata.max = Math.max(valueMetadata.values) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of valueMetadatas that posess all hints requested.
|
||||
* Array is sorted based on hint priority.
|
||||
*
|
||||
*/
|
||||
TelemetryMetadataManager.prototype.valuesForHints = function (
|
||||
hints
|
||||
) {
|
||||
function hasHint(hint) {
|
||||
// eslint-disable-next-line no-invalid-this
|
||||
return Object.prototype.hasOwnProperty.call(this.hints, hint);
|
||||
}
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata, 'min')) {
|
||||
valueMetadata.min = Math.min(valueMetadata.values) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
function hasHints(metadata) {
|
||||
return hints.every(hasHint, metadata);
|
||||
}
|
||||
if (!Object.prototype.hasOwnProperty.call(valueMetadata.hints, 'priority')) {
|
||||
valueMetadata.hints.priority = index;
|
||||
}
|
||||
|
||||
const matchingMetadata = this.valueMetadatas.filter(hasHints);
|
||||
let iteratees = hints.map(hint => {
|
||||
return (metadata) => {
|
||||
return metadata.hints[hint];
|
||||
};
|
||||
});
|
||||
return valueMetadata;
|
||||
}
|
||||
|
||||
return _.sortBy(matchingMetadata, ...iteratees);
|
||||
};
|
||||
/**
|
||||
* Utility class for handling and inspecting telemetry metadata. Applies
|
||||
* reasonable defaults to simplify the task of providing metadata, while
|
||||
* also providing methods for interrogating telemetry metadata.
|
||||
*/
|
||||
function TelemetryMetadataManager(metadata) {
|
||||
this.metadata = metadata;
|
||||
|
||||
/**
|
||||
* check out of a given metadata has array values
|
||||
*/
|
||||
TelemetryMetadataManager.prototype.isArrayValue = function (metadata) {
|
||||
const regex = /\[\]$/g;
|
||||
if (!metadata.format && !metadata.formatString) {
|
||||
return false;
|
||||
}
|
||||
this.valueMetadatas = this.metadata.values
|
||||
? this.metadata.values.map(applyReasonableDefaults)
|
||||
: [];
|
||||
}
|
||||
|
||||
return (metadata.format || metadata.formatString).match(regex) !== null;
|
||||
};
|
||||
/**
|
||||
* Get value metadata for a single key.
|
||||
*/
|
||||
TelemetryMetadataManager.prototype.value = function (key) {
|
||||
return this.valueMetadatas.filter(function (metadata) {
|
||||
return metadata.key === key;
|
||||
})[0];
|
||||
};
|
||||
|
||||
TelemetryMetadataManager.prototype.getFilterableValues = function () {
|
||||
return this.valueMetadatas.filter(metadatum => metadatum.filters && metadatum.filters.length > 0);
|
||||
};
|
||||
/**
|
||||
* Returns all value metadatas, sorted by priority.
|
||||
*/
|
||||
TelemetryMetadataManager.prototype.values = function () {
|
||||
return this.valuesForHints(['priority']);
|
||||
};
|
||||
|
||||
TelemetryMetadataManager.prototype.getDefaultDisplayValue = function () {
|
||||
let valueMetadata = this.valuesForHints(['range'])[0];
|
||||
/**
|
||||
* Get an array of valueMetadatas that posess all hints requested.
|
||||
* Array is sorted based on hint priority.
|
||||
*
|
||||
*/
|
||||
TelemetryMetadataManager.prototype.valuesForHints = function (hints) {
|
||||
function hasHint(hint) {
|
||||
// eslint-disable-next-line no-invalid-this
|
||||
return Object.prototype.hasOwnProperty.call(this.hints, hint);
|
||||
}
|
||||
|
||||
if (valueMetadata === undefined) {
|
||||
valueMetadata = this.values().filter(values => {
|
||||
return !(values.hints.domain);
|
||||
})[0];
|
||||
}
|
||||
function hasHints(metadata) {
|
||||
return hints.every(hasHint, metadata);
|
||||
}
|
||||
|
||||
if (valueMetadata === undefined) {
|
||||
valueMetadata = this.values()[0];
|
||||
}
|
||||
const matchingMetadata = this.valueMetadatas.filter(hasHints);
|
||||
let iteratees = hints.map((hint) => {
|
||||
return (metadata) => {
|
||||
return metadata.hints[hint];
|
||||
};
|
||||
});
|
||||
|
||||
return valueMetadata;
|
||||
};
|
||||
return _.sortBy(matchingMetadata, ...iteratees);
|
||||
};
|
||||
|
||||
return TelemetryMetadataManager;
|
||||
/**
|
||||
* check out of a given metadata has array values
|
||||
*/
|
||||
TelemetryMetadataManager.prototype.isArrayValue = function (metadata) {
|
||||
const regex = /\[\]$/g;
|
||||
if (!metadata.format && !metadata.formatString) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (metadata.format || metadata.formatString).match(regex) !== null;
|
||||
};
|
||||
|
||||
TelemetryMetadataManager.prototype.getFilterableValues = function () {
|
||||
return this.valueMetadatas.filter(
|
||||
(metadatum) => metadatum.filters && metadatum.filters.length > 0
|
||||
);
|
||||
};
|
||||
|
||||
TelemetryMetadataManager.prototype.getDefaultDisplayValue = function () {
|
||||
let valueMetadata = this.valuesForHints(['range'])[0];
|
||||
|
||||
if (valueMetadata === undefined) {
|
||||
valueMetadata = this.values().filter((values) => {
|
||||
return !values.hints.domain;
|
||||
})[0];
|
||||
}
|
||||
|
||||
if (valueMetadata === undefined) {
|
||||
valueMetadata = this.values()[0];
|
||||
}
|
||||
|
||||
return valueMetadata;
|
||||
};
|
||||
|
||||
return TelemetryMetadataManager;
|
||||
});
|
||||
|
Reference in New Issue
Block a user