From 22ca339fb9f3f13b5199394aebc9a7a3cbc1bf8f Mon Sep 17 00:00:00 2001 From: Jamie V Date: Wed, 1 Jul 2020 09:50:18 -0700 Subject: [PATCH] [LADTable] Lad bounds listener FIX (#3114) * added bounds listener, moved history request to function, checking for race conditions Co-authored-by: Andrew Henry --- .../generator/GeneratorMetadataProvider.js | 19 ++++++++ src/plugins/LADTable/components/LADRow.vue | 43 +++++++++++++++---- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/example/generator/GeneratorMetadataProvider.js b/example/generator/GeneratorMetadataProvider.js index 9ca9a08f4c..e3969600c3 100644 --- a/example/generator/GeneratorMetadataProvider.js +++ b/example/generator/GeneratorMetadataProvider.js @@ -28,6 +28,16 @@ define([ domain: 2 } }, + // Need to enable "LocalTimeSystem" plugin to make use of this + // { + // key: "local", + // name: "Time", + // format: "local-format", + // source: "utc", + // hints: { + // domain: 3 + // } + // }, { key: "sin", name: "Sine", @@ -61,6 +71,15 @@ define([ domain: 1 } }, + { + key: "local", + name: "Time", + format: "utc", + source: "utc", + hints: { + domain: 2 + } + }, { key: "state", source: "value", diff --git a/src/plugins/LADTable/components/LADRow.vue b/src/plugins/LADTable/components/LADRow.vue index 6df10a9aad..39e8092ebb 100644 --- a/src/plugins/LADTable/components/LADRow.vue +++ b/src/plugins/LADTable/components/LADRow.vue @@ -64,7 +64,7 @@ export default { }, computed: { formattedTimestamp() { - return this.timestamp !== undefined ? this.formats[this.timestampKey].format(this.timestamp) : '---'; + return this.timestamp !== undefined ? this.getFormattedTimestamp(this.timestamp) : '---'; } }, mounted() { @@ -110,11 +110,11 @@ export default { }, methods: { updateValues(datum) { - let newTimestamp = this.formats[this.timestampKey].parse(datum), + let newTimestamp = this.getParsedTimestamp(datum), limit; if(this.shouldUpdate(newTimestamp)) { - this.timestamp = this.formats[this.timestampKey].parse(datum); + this.timestamp = newTimestamp; this.value = this.formats[this.valueKey].format(datum); limit = this.limitEvaluator.evaluate(datum, this.valueMetadata); if (limit) { @@ -125,9 +125,12 @@ export default { } }, shouldUpdate(newTimestamp) { - return (this.timestamp === undefined) || - (this.inBounds(newTimestamp) && - newTimestamp > this.timestamp); + let newTimestampInBounds = this.inBounds(newTimestamp), + noExistingTimestamp = this.timestamp === undefined, + newTimestampIsLatest = newTimestamp > this.timestamp; + + return newTimestampInBounds && + (noExistingTimestamp || newTimestampIsLatest); }, requestHistory() { this.openmct @@ -146,6 +149,7 @@ export default { updateBounds(bounds, isTick) { this.bounds = bounds; if(!isTick) { + this.resetValues(); this.requestHistory(); } }, @@ -153,13 +157,34 @@ export default { return timestamp >= this.bounds.start && timestamp <= this.bounds.end; }, updateTimeSystem(timeSystem) { - this.value = '---'; - this.timestamp = '---'; - this.valueClass = ''; + this.resetValues(); this.timestampKey = timeSystem.key; }, showContextMenu(event) { this.openmct.contextMenu._showContextMenuForObjectPath(this.currentObjectPath, event.x, event.y, CONTEXT_MENU_ACTIONS); + }, + resetValues() { + this.value = '---'; + this.timestamp = undefined; + this.valueClass = ''; + }, + getParsedTimestamp(timestamp) { + if(this.timeSystemFormat()) { + return this.formats[this.timestampKey].parse(timestamp); + } + }, + getFormattedTimestamp(timestamp) { + if(this.timeSystemFormat()) { + return this.formats[this.timestampKey].format(timestamp); + } + }, + timeSystemFormat() { + if(this.formats[this.timestampKey]) { + return true; + } else { + console.warn(`No formatter for ${this.timestampKey} time system for ${this.domainObject.name}.`); + return false; + } } } }