diff --git a/src/plugins/condition/ConditionManager.js b/src/plugins/condition/ConditionManager.js index dc51d1194e..5acb67d1df 100644 --- a/src/plugins/condition/ConditionManager.js +++ b/src/plugins/condition/ConditionManager.js @@ -37,11 +37,13 @@ export default class ConditionManager extends EventEmitter { this.compositionLoad = this.composition.load(); this.subscriptions = {}; this.telemetryObjects = {}; + this.testData = {conditionTestData: [], applied: false}; this.initialize(); this.stopObservingForChanges = this.openmct.objects.observe(this.conditionSetDomainObject, '*', (newDomainObject) => { this.conditionSetDomainObject = newDomainObject; }); + } subscribeToTelemetry(endpoint) { @@ -265,14 +267,31 @@ export default class ConditionManager extends EventEmitter { this.emit(`broadcastTelemetry`, Object.assign({}, this.createNormalizedDatum(datum, id), {id: id})); } + getTestData(metadatum) { + let data = undefined; + if (this.testData.applied) { + const found = this.testData.conditionTestInputs.find((testInput) => (testInput.metadata === metadatum.source)); + if (found) { + data = found.value; + } + } + return data; + } + createNormalizedDatum(telemetryDatum, id) { return Object.values(this.telemetryObjects[id].telemetryMetaData).reduce((normalizedDatum, metadatum) => { + const testValue = this.getTestData(metadatum); const formatter = this.openmct.telemetry.getValueFormatter(metadatum); - normalizedDatum[metadatum.key] = formatter.parse(telemetryDatum[metadatum.source]); + normalizedDatum[metadatum.key] = testValue !== undefined ? formatter.parse(testValue) : formatter.parse(telemetryDatum[metadatum.source]); return normalizedDatum; }, {}); } + updateTestData(testData) { + this.testData = testData; + this.openmct.objects.mutate(this.conditionSetDomainObject, 'configuration.conditionTestData', this.testData.conditionTestInputs); + } + persistConditions() { this.openmct.objects.mutate(this.conditionSetDomainObject, 'configuration.conditionCollection', this.conditionSetDomainObject.configuration.conditionCollection); } diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index 9b2ae28eb0..5db1e702cb 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -90,7 +90,17 @@ export default { Condition }, props: { - isEditing: Boolean + isEditing: Boolean, + testData: { + type: Object, + required: true, + default: () => { + return { + applied: false, + conditionTestInputs: [] + } + } + } }, data() { return { @@ -103,6 +113,14 @@ export default { isDragging: false }; }, + watch: { + testData: { + handler() { + this.updateTestData(); + }, + deep: true + } + }, destroyed() { this.composition.off('add', this.addTelemetryObject); this.composition.off('remove', this.removeTelemetryObject); @@ -181,6 +199,7 @@ export default { }, addTelemetryObject(domainObject) { this.telemetryObjs.push(domainObject); + this.$emit('telemetryUpdated', this.telemetryObjs); }, removeTelemetryObject(identifier) { let index = _.findIndex(this.telemetryObjs, (obj) => { @@ -206,6 +225,9 @@ export default { }, cloneCondition(data) { this.conditionManager.cloneCondition(data.condition, data.index); + }, + updateTestData() { + this.conditionManager.updateTestData(this.testData); } } } diff --git a/src/plugins/condition/components/ConditionSet.vue b/src/plugins/condition/components/ConditionSet.vue index 7cc20f18da..d955ad2679 100644 --- a/src/plugins/condition/components/ConditionSet.vue +++ b/src/plugins/condition/components/ConditionSet.vue @@ -33,10 +33,16 @@ - + @@ -56,15 +62,27 @@ export default { }, data() { return { - currentConditionOutput: '' + currentConditionOutput: '', + telemetryObjs: [], + testData: {} } }, mounted() { this.conditionSetIdentifier = this.openmct.objects.makeKeyString(this.domainObject.identifier); + this.testData = { + applied: false, + conditionTestInputs: this.domainObject.configuration.conditionTestData || [] + }; }, methods: { updateCurrentOutput(currentConditionResult) { this.currentConditionOutput = currentConditionResult.output; + }, + updateTelemetry(telemetryObjs) { + this.telemetryObjs = telemetryObjs; + }, + updateTestData(testData) { + this.testData = testData; } } }; diff --git a/src/plugins/condition/components/TestData.vue b/src/plugins/condition/components/TestData.vue index daedc68ff8..24ac3ceb93 100644 --- a/src/plugins/condition/components/TestData.vue +++ b/src/plugins/condition/components/TestData.vue @@ -37,36 +37,85 @@
-
+
+ - - Apply Test Data - -
-
- Set -
- -
+ Set + + + + + + + + + + +
-
+
+
@@ -75,17 +124,113 @@ export default { inject: ['openmct'], props: { - isEditing: Boolean + isEditing: Boolean, + telemetry: { + type: Array, + required: true, + default: () => [] + }, + testData: { + type: Object, + required: true, + default: () => { + return { + applied: false, + conditionTestInputs: [] + } + } + } }, data() { return { expanded: true, - isApplied: true + isApplied: false, + testInputs: [], + telemetryMetadataOptions: {} }; }, + watch: { + isEditing(editing) { + if (!editing) { + this.resetApplied(); + } + }, + telemetry: { + handler() { + this.initializeMetadata(); + }, + deep: true + }, + testData: { + handler() { + this.initialize(); + }, + deep: true + } + }, + beforeDestroy() { + this.resetApplied(); + }, + mounted() { + this.initialize(); + this.initializeMetadata(); + }, methods: { - applyTestData(ev) { - this.$emit('change', ev.target.checked); + applyTestData() { + this.isApplied = !this.isApplied; + this.updateTestData(); + }, + initialize() { + if (this.testData && this.testData.conditionTestInputs) { + this.testInputs = this.testData.conditionTestInputs; + } + if (!this.testInputs.length) { + this.addTestInput(); + } + }, + initializeMetadata() { + this.telemetry.forEach((telemetryObject) => { + const id = this.openmct.objects.makeKeyString(telemetryObject.identifier); + let telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject); + this.telemetryMetadataOptions[id] = telemetryMetadata.values().slice(); + }); + }, + addTestInput(testInput) { + this.testInputs.push(Object.assign({ + telemetry: '', + metadata: '', + input: '' + }, testInput)); + }, + removeTestInput(index) { + this.testInputs.splice(index, 1); + this.updateTestData(); + }, + getId(identifier) { + if (identifier) { + return this.openmct.objects.makeKeyString(identifier); + } + return []; + }, + updateMetadata(testInput) { + if (testInput.telemetry) { + const id = this.openmct.objects.makeKeyString(testInput.telemetry); + if(this.telemetryMetadataOptions[id]) { + return; + } + let telemetryMetadata = this.openmct.telemetry.getMetadata(testInput); + this.telemetryMetadataOptions[id] = telemetryMetadata.values().slice(); + } + }, + resetApplied() { + this.isApplied = false; + this.updateTestData(); + }, + updateTestData() { + this.$emit('updateTestData', { + applied: this.isApplied, + conditionTestInputs: this.testInputs + }); } } } diff --git a/src/plugins/condition/components/condition-set.scss b/src/plugins/condition/components/condition-set.scss index 7449d457d7..45db953c8d 100644 --- a/src/plugins/condition/components/condition-set.scss +++ b/src/plugins/condition/components/condition-set.scss @@ -64,7 +64,7 @@ } /***************************** TEST DATA */ -.c-cs-test-h { +.c-cs-tests { flex: 1 1 auto; overflow: auto; padding-right: $interiorMarginSm; @@ -74,16 +74,21 @@ } } -.c-test-datum { +.c-cs-test { > * { flex: 0 0 auto; + * { margin-left: $interiorMargin; } } - &__controls { - flex: 1 1 auto; - } + &__controls { + display: flex; + flex: 1 1 auto; + + > * + * { + margin-left: $interiorMargin; + } + } } diff --git a/src/plugins/condition/plugin.js b/src/plugins/condition/plugin.js index b8b08385f5..1d4855a8f5 100644 --- a/src/plugins/condition/plugin.js +++ b/src/plugins/condition/plugin.js @@ -38,6 +38,7 @@ export default function ConditionPlugin() { cssClass: 'icon-conditional', initialize: function (domainObject) { domainObject.configuration = { + conditionTestData: [], conditionCollection: [{ isDefault: true, id: uuid(), diff --git a/src/styles/_controls.scss b/src/styles/_controls.scss index e6f9c3f12a..f6ea5b475b 100644 --- a/src/styles/_controls.scss +++ b/src/styles/_controls.scss @@ -225,6 +225,10 @@ section { overflow: hidden; + section { margin-top: $interiorMargin; + + &.is-expanded { + margin-bottom: $interiorMargin * 3; + } } &.is-expanded {