Merge pull request #2685 from nasa/conditionals-refactor

Conditionals refactor
This commit is contained in:
Joel McKinnon 2020-02-28 11:35:09 -08:00 committed by GitHub
commit cfafecdd64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 412 additions and 172 deletions

View File

@ -22,9 +22,9 @@
import * as EventEmitter from 'eventemitter3'; import * as EventEmitter from 'eventemitter3';
import uuid from 'uuid'; import uuid from 'uuid';
import TelemetryCriterion from "@/plugins/condition/criterion/TelemetryCriterion"; import TelemetryCriterion from "./criterion/TelemetryCriterion";
import { TRIGGER } from "@/plugins/condition/utils/constants"; import { TRIGGER } from "./utils/constants";
import {computeCondition} from "@/plugins/condition/utils/evaluator"; import {computeCondition} from "./utils/evaluator";
/* /*
* conditionConfiguration = { * conditionConfiguration = {
@ -58,11 +58,11 @@ export default class ConditionClass extends EventEmitter {
this.id = this.openmct.objects.makeKeyString(conditionConfiguration.identifier); this.id = this.openmct.objects.makeKeyString(conditionConfiguration.identifier);
this.criteria = []; this.criteria = [];
this.criteriaResults = {}; this.criteriaResults = {};
this.result = null;
if (conditionConfiguration.configuration.criteria) { if (conditionConfiguration.configuration.criteria) {
this.createCriteria(conditionConfiguration.configuration.criteria); this.createCriteria(conditionConfiguration.configuration.criteria);
} }
this.trigger = conditionConfiguration.configuration.trigger; this.trigger = conditionConfiguration.configuration.trigger;
this.result = null;
this.openmct.objects.get(this.id).then(obj => this.observeForChanges(obj)); this.openmct.objects.get(this.id).then(obj => this.observeForChanges(obj));
} }
@ -199,9 +199,7 @@ export default class ConditionClass extends EventEmitter {
subscribe() { subscribe() {
this.criteria.forEach((criterion) => { this.criteria.forEach((criterion) => {
if (criterion.isValid()) { criterion.subscribe();
criterion.subscribe();
}
}) })
} }

View File

@ -0,0 +1,250 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
import Condition from "./Condition";
import uuid from "uuid";
import * as EventEmitter from 'eventemitter3';
export default class ConditionManager extends EventEmitter {
constructor(domainObject, openmct) {
super();
this.domainObject = domainObject;
this.openmct = openmct;
this.instantiate = this.openmct.$injector.get('instantiate');
this.initialize();
}
initialize() {
this.conditionResults = {};
this.openmct.objects.get(this.domainObject.identifier).then((obj) => {
this.observeForChanges(obj);
this.conditionCollection = [];
if (this.domainObject.configuration.conditionCollection.length) {
this.domainObject.configuration.conditionCollection.forEach((conditionConfigurationId, index) => {
this.openmct.objects.get(conditionConfigurationId).then((conditionConfiguration) => {
this.initCondition(conditionConfiguration, index)
});
});
} else {
this.addCondition(true);
}
});
}
observeForChanges(domainObject) {
//TODO: Observe only the conditionCollection property instead of the whole domainObject
this.stopObservingForChanges = this.openmct.objects.observe(domainObject, '*', this.handleConditionCollectionUpdated.bind(this));
}
handleConditionCollectionUpdated(newDomainObject) {
let oldConditionIdentifiers = this.domainObject.configuration.conditionCollection.map((conditionConfigurationId) => {
return this.openmct.objects.makeKeyString(conditionConfigurationId);
});
let newConditionIdentifiers = newDomainObject.configuration.conditionCollection.map((conditionConfigurationId) => {
return this.openmct.objects.makeKeyString(conditionConfigurationId);
});
this.domainObject = newDomainObject;
//check for removed conditions
oldConditionIdentifiers.forEach((identifier, index) => {
if (newConditionIdentifiers.indexOf(identifier) < 0) {
this.removeCondition(identifier);
}
});
let newConditionCount = this.domainObject.configuration.conditionCollection.length - this.conditionCollection.length;
for (let i = 0; i < newConditionCount; i++) {
let conditionConfigurationId = this.domainObject.configuration.conditionCollection[i];
this.openmct.objects.get(conditionConfigurationId).then((conditionConfiguration) => {
this.initCondition(conditionConfiguration, i);
});
}
}
initCondition(conditionConfiguration, index) {
let condition = new Condition(conditionConfiguration, this.openmct);
condition.on('conditionResultUpdated', this.handleConditionResult.bind(this));
if (index !== undefined) {
this.conditionCollection.splice(index + 1, 0, condition);
} else {
this.conditionCollection.unshift(condition);
}
//There are no criteria for a default condition and hence no subscriptions.
//Hence the conditionResult must be manually triggered for it.
if (conditionConfiguration.isDefault) {
this.handleConditionResult();
}
}
createConditionDomainObject(isDefault, conditionConfiguration) {
let conditionObj;
if (conditionConfiguration) {
conditionObj = {
...conditionConfiguration,
name: `Copy of ${conditionConfiguration.name}`,
identifier: {
...this.domainObject.identifier,
key: uuid()
}
};
} else {
conditionObj = {
isDefault: isDefault,
type: 'condition',
identifier: {
...this.domainObject.identifier,
key: uuid()
},
configuration: {
name: isDefault ? 'Default' : 'Unnamed Condition',
output: 'false',
trigger: 'all',
criteria: isDefault ? [] : [{
telemetry: '',
operation: '',
input: [],
metadata: ''
}]
},
summary: ''
};
}
let conditionDomainObjectKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
let newDomainObject = this.instantiate(conditionObj, conditionDomainObjectKeyString);
return newDomainObject.useCapability('adapter');
}
addCondition(isDefault, index) {
this.createAndSaveConditionDomainObject(!!isDefault, index);
}
cloneCondition(conditionConfigurationId, index) {
this.openmct.objects.get(conditionConfigurationId).then((conditionConfiguration) => {
this.createAndSaveConditionDomainObject(false, index, conditionConfiguration);
});
}
createAndSaveConditionDomainObject(isDefault, index, conditionConfiguration) {
let newConditionDomainObject = this.createConditionDomainObject(isDefault, conditionConfiguration);
//persist the condition domain object so that we can do an openmct.objects.get on it and only persist the identifier in the conditionCollection of conditionSet
this.openmct.objects.mutate(newConditionDomainObject, 'created', new Date());
if (index !== undefined) {
this.domainObject.configuration.conditionCollection.splice(index + 1, 0, newConditionDomainObject.identifier);
} else {
this.domainObject.configuration.conditionCollection.unshift(newConditionDomainObject.identifier);
}
this.persist();
}
removeCondition(identifier) {
let found = this.findConditionById(identifier);
if (found) {
let index = found.index;
let condition = this.conditionCollection[index];
let conditionIdAsString = condition.id;
condition.destroyCriteria();
condition.off('conditionResultUpdated', this.handleConditionResult.bind(this));
this.conditionCollection.splice(index, 1);
this.domainObject.configuration.conditionCollection.splice(index, 1);
if (this.conditionResults[conditionIdAsString] !== undefined) {
delete this.conditionResults[conditionIdAsString];
}
this.persist();
this.handleConditionResult();
}
}
findConditionById(identifier) {
let found;
for (let i=0, ii=this.conditionCollection.length; i < ii; i++) {
if (this.conditionCollection[i].id === this.openmct.objects.makeKeyString(identifier)) {
found = {
item: this.conditionCollection[i],
index: i
};
break;
}
}
return found;
}
//this.$set(this.conditionCollection, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]);
reorderConditions(reorderPlan) {
let oldConditions = Array.from(this.domainObject.configuration.conditionCollection);
let newCollection = [];
reorderPlan.forEach((reorderEvent) => {
let item = oldConditions[reorderEvent.oldIndex];
newCollection.push(item);
this.domainObject.configuration.conditionCollection = newCollection;
});
this.persist();
}
handleConditionResult(resultObj) {
let conditionCollection = this.domainObject.configuration.conditionCollection;
let currentConditionIdentifier = conditionCollection[conditionCollection.length-1];
if (resultObj) {
let idAsString = this.openmct.objects.makeKeyString(resultObj.id);
let found = this.findConditionById(idAsString);
if (found) {
this.conditionResults[idAsString] = resultObj.data.result;
}
}
for (let i = 0, ii = conditionCollection.length - 1; i < ii; i++) {
let conditionIdAsString = this.openmct.objects.makeKeyString(conditionCollection[i]);
if (this.conditionResults[conditionIdAsString]) {
//first condition to be true wins
currentConditionIdentifier = conditionCollection[i];
break;
}
}
this.openmct.objects.get(currentConditionIdentifier).then((obj) => {
this.emit('conditionSetResultUpdated', {
id: this.domainObject.identifier,
output: obj.configuration.output,
conditionId: currentConditionIdentifier
})
});
}
persist() {
this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.domainObject.configuration.conditionCollection);
}
destroy() {
if (typeof this.stopObservingForChanges === 'function') {
this.stopObservingForChanges();
}
this.conditionCollection.forEach((condition) => {
condition.off('conditionResultUpdated', this.handleConditionResult);
condition.destroy();
})
}
}

View File

@ -0,0 +1,98 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
import ConditionManager from './ConditionManager';
describe('ConditionManager', () => {
let conditionMgr;
let mockListener;
let openmct = {};
let conditionSetDomainObject = {
identifier: {
namespace: "",
key: "600a7372-8d48-4dc4-98b6-548611b1ff7e"
},
type: "conditionSet",
location: "mine",
configuration: {
conditionCollection: []
}
};
let mockConditionDomainObject = {
isDefault: true,
type: 'condition',
identifier: {
namespace: '',
key: '1234-5678'
}
};
function mockAngularComponents() {
let mockInjector = jasmine.createSpyObj('$injector', ['get']);
let mockInstantiate = jasmine.createSpy('mockInstantiate');
mockInstantiate.and.returnValue(mockInstantiate);
let mockDomainObject = {
useCapability: function () {
return mockConditionDomainObject;
}
};
mockInstantiate.and.callFake(function () {
return mockDomainObject;
});
mockInjector.get.and.callFake(function (service) {
return {
'instantiate': mockInstantiate
}[service];
});
openmct.$injector = mockInjector;
}
beforeAll(function () {
mockAngularComponents();
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString', 'observe', 'mutate']);
openmct.objects.get.and.returnValues(new Promise(function (resolve, reject) {
resolve(conditionSetDomainObject);
}), new Promise(function (resolve, reject) {
resolve(mockConditionDomainObject);
}));
openmct.objects.makeKeyString.and.returnValue(conditionSetDomainObject.identifier.key);
openmct.objects.observe.and.returnValue(function () {});
openmct.objects.mutate.and.returnValue(function () {});
conditionMgr = new ConditionManager(conditionSetDomainObject, openmct);
mockListener = jasmine.createSpy('mockListener');
conditionMgr.on('conditionSetResultUpdated', mockListener);
});
it('creates a conditionCollection with a default condition', function () {
expect(conditionMgr.domainObject.configuration.conditionCollection.length).toEqual(1);
let defaultConditionIdentifier = conditionMgr.domainObject.configuration.conditionCollection[0];
expect(defaultConditionIdentifier).toEqual(mockConditionDomainObject.identifier);
});
});

View File

@ -177,8 +177,7 @@
</template> </template>
<script> <script>
import ConditionClass from "@/plugins/condition/Condition"; import Criterion from './Criterion.vue';
import Criterion from '../../condition/components/Criterion.vue';
export default { export default {
inject: ['openmct'], inject: ['openmct'],
@ -236,10 +235,6 @@ export default {
methods: { methods: {
initialize() { initialize() {
this.setOutput(); this.setOutput();
if (!this.domainObject.isDefault) {
this.conditionClass = new ConditionClass(this.domainObject, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
}
}, },
addCriteria() { addCriteria() {
const criteriaObject = { const criteriaObject = {
@ -256,19 +251,6 @@ export default {
this.$emit('setMoveIndex', this.conditionIndex); this.$emit('setMoveIndex', this.conditionIndex);
}, },
destroy() { destroy() {
if (this.conditionClass) {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (typeof this.conditionClass.destroy === 'function') {
this.conditionClass.destroy();
}
delete this.conditionClass;
}
},
handleConditionResult(args) {
this.$emit('conditionResultUpdated', {
id: this.conditionIdentifier,
result: args.data.result
})
}, },
removeCondition(ev) { removeCondition(ev) {
this.$emit('removeCondition', this.conditionIdentifier); this.$emit('removeCondition', this.conditionIdentifier);
@ -309,9 +291,6 @@ export default {
this.domainObject.configuration.output = this.selectedOutputKey; this.domainObject.configuration.output = this.selectedOutputKey;
} }
}, },
updateCurrentCondition() {
this.$emit('updateCurrentCondition', this.currentConditionIdentifier);
},
hasTelemetry(identifier) { hasTelemetry(identifier) {
// TODO: check parent domainObject.composition.hasTelemetry // TODO: check parent domainObject.composition.hasTelemetry
return this.currentCriteria && identifier; return this.currentCriteria && identifier;

View File

@ -70,10 +70,8 @@
:condition-index="index" :condition-index="index"
:telemetry="telemetryObjs" :telemetry="telemetryObjs"
:is-editing="isEditing" :is-editing="isEditing"
@updateCurrentCondition="updateCurrentCondition"
@removeCondition="removeCondition" @removeCondition="removeCondition"
@cloneCondition="cloneCondition" @cloneCondition="cloneCondition"
@conditionResultUpdated="handleConditionResult"
@setMoveIndex="setMoveIndex" @setMoveIndex="setMoveIndex"
/> />
</li> </li>
@ -84,8 +82,8 @@
</template> </template>
<script> <script>
import Condition from '../../condition/components/Condition.vue'; import Condition from './Condition.vue';
import uuid from 'uuid'; import ConditionManager from '../ConditionManager';
export default { export default {
inject: ['openmct', 'domainObject'], inject: ['openmct', 'domainObject'],
@ -111,21 +109,30 @@ export default {
destroyed() { destroyed() {
this.composition.off('add', this.addTelemetryObject); this.composition.off('add', this.addTelemetryObject);
this.composition.off('remove', this.removeTelemetryObject); this.composition.off('remove', this.removeTelemetryObject);
if(this.conditionManager) {
this.conditionManager.off('conditionSetResultUpdated', this.handleOutputUpdated);
this.conditionManager.destroy();
}
if (typeof this.stopObservingForChanges === 'function') {
this.stopObservingForChanges();
}
}, },
mounted() { mounted() {
this.instantiate = this.openmct.$injector.get('instantiate');
this.composition = this.openmct.composition.get(this.domainObject); this.composition = this.openmct.composition.get(this.domainObject);
this.composition.on('add', this.addTelemetryObject); this.composition.on('add', this.addTelemetryObject);
this.composition.on('remove', this.removeTelemetryObject); this.composition.on('remove', this.removeTelemetryObject);
this.composition.load(); this.composition.load();
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : []; this.conditionCollection = this.domainObject.configuration.conditionCollection;
if (!this.conditionCollection.length) { this.conditionManager = new ConditionManager(this.domainObject, this.openmct);
this.addCondition(null, true); this.conditionManager.on('conditionSetResultUpdated', this.handleOutputUpdated.bind(this));
} else { this.observeForChanges();
this.updateCurrentCondition(this.conditionCollection[0]);
}
}, },
methods: { methods: {
observeForChanges() {
this.stopObservingForChanges = this.openmct.objects.observe(this.domainObject, '*', (newDomainObject) => {
this.conditionCollection = newDomainObject.configuration.conditionCollection;
});
},
setMoveIndex(index) { setMoveIndex(index) {
this.moveIndex = index; this.moveIndex = index;
this.isDragging = true; this.isDragging = true;
@ -172,22 +179,8 @@ export default {
dragLeave(e) { dragLeave(e) {
e.target.classList.remove("dragging"); e.target.classList.remove("dragging");
}, },
handleConditionResult(args) { handleOutputUpdated(args) {
let idAsString = this.openmct.objects.makeKeyString(args.id); this.$emit('currentConditionSetOutputUpdated', args);
this.conditionResults[idAsString] = args.result;
this.updateCurrentConditionId();
},
updateCurrentConditionId() {
let currentConditionIdentifier = this.conditionCollection[this.conditionCollection.length-1];
for (let i = 0; i < this.conditionCollection.length - 1; i++) {
let conditionIdAsString = this.openmct.objects.makeKeyString(this.conditionCollection[i]);
if (this.conditionResults[conditionIdAsString]) {
//first condition to be true wins
currentConditionIdentifier = this.conditionCollection[i];
break;
}
}
this.$emit('currentConditionUpdated', currentConditionIdentifier);
}, },
addTelemetryObject(domainObject) { addTelemetryObject(domainObject) {
this.telemetryObjs.push(domainObject); this.telemetryObjs.push(domainObject);
@ -202,98 +195,20 @@ export default {
this.telemetryObjs.splice(index, 1); this.telemetryObjs.splice(index, 1);
} }
}, },
removeTelemetry(telemetryDomainObjectIdentifier) { addCondition(event, isDefault, index) {
let index = _.findIndex(this.telemetryObjs, (obj) => { this.conditionManager.addCondition(!!isDefault, index);
let objId = this.openmct.objects.makeKeyString(obj.identifier);
let id = this.openmct.objects.makeKeyString(telemetryDomainObjectIdentifier);
return objId === id;
});
if (index > -1) {
this.telemetryObjs.splice(index, 1);
}
},
/*
Adds a condition to list via programatic creation of default for initial list, manual
creation via Add Condition button, or duplication via button in title bar of condition.
Params:
event: always null,
isDefault (boolean): true if conditionList is empty
isClone (boolean): true if duplicating a condition
definition (string): definition property of condition being duplicated with new name
index (number): index of condition being duplicated
*/
addCondition(event, isDefault, isClone, configuration, index) {
let conditionDomainObject = this.createConditionDomainObject(!!isDefault, isClone, configuration);
//persist the condition domain object so that we can do an openmct.objects.get on it and only persist the identifier in the conditionCollection of conditionSet
this.openmct.objects.mutate(conditionDomainObject, 'created', new Date());
if (!isClone) {
this.conditionCollection.unshift(conditionDomainObject.identifier);
} else {
this.conditionCollection.splice(index + 1, 0, conditionDomainObject.identifier);
}
this.persist();
}, },
updateCurrentCondition(identifier) { updateCurrentCondition(identifier) {
this.currentConditionIdentifier = identifier; this.currentConditionIdentifier = identifier;
}, },
createConditionDomainObject(isDefault, isClone, configuration) {
const configurationTemplate = {
name: isDefault ? 'Default' : (isClone ? 'Copy of ' : '') + 'Unnamed Condition',
output: 'false',
trigger: 'all',
criteria: isDefault ? [] : [{
telemetry: '',
operation: '',
input: '',
metadata: '',
key: ''
}]
};
let conditionObj = {
isDefault: isDefault,
type: 'condition',
identifier: {
namespace: this.domainObject.identifier.namespace,
key: uuid()
},
configuration: isClone ? configuration: configurationTemplate,
summary: 'summary description',
created: new Date()
};
let conditionDomainObjectKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
let newDomainObject = this.instantiate(conditionObj, conditionDomainObjectKeyString);
return newDomainObject.useCapability('adapter');
},
updateCondition(updatedCondition) {
let index = _.findIndex(this.conditions, (condition) => condition.id === updatedCondition.id);
this.conditions[index] = updatedCondition;
},
removeCondition(identifier) { removeCondition(identifier) {
let index = _.findIndex(this.conditionCollection, (condition) => { this.conditionManager.removeCondition(identifier);
let conditionId = this.openmct.objects.makeKeyString(condition);
let id = this.openmct.objects.makeKeyString(identifier);
return conditionId === id;
});
this.conditionCollection.splice(index, 1);
this.persist();
this.updateCurrentConditionId();
}, },
reorder(reorderPlan) { reorder(reorderPlan) {
let oldConditions = Array.from(this.conditionCollection); this.conditionManager.reorderConditions(reorderPlan);
reorderPlan.forEach((reorderEvent) => {
this.$set(this.conditionCollection, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]);
});
this.persist();
}, },
cloneCondition(condition) { cloneCondition(condition) {
this.openmct.objects.get(condition.identifier).then((obj) => { this.conditionManager.cloneCondition(condition.identifier, condition.index);
obj.configuration.name = 'Copy of ' + obj.configuration.name;
this.addCondition(null, false, true, obj.configuration, condition.index);
});
},
persist() {
this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.conditionCollection);
} }
} }
} }

View File

@ -23,10 +23,10 @@
<template> <template>
<div class="c-cs-edit w-condition-set"> <div class="c-cs-edit w-condition-set">
<div class="c-sw-edit__ui holder"> <div class="c-sw-edit__ui holder">
<CurrentOutput :condition="currentCondition" /> <CurrentOutput :output="currentConditionOutput" />
<TestData :is-editing="isEditing" /> <TestData :is-editing="isEditing" />
<ConditionCollection :is-editing="isEditing" <ConditionCollection :is-editing="isEditing"
@currentConditionUpdated="updateCurrentCondition" @currentConditionSetOutputUpdated="updateCurrentOutput"
/> />
</div> </div>
</div> </div>
@ -49,24 +49,17 @@ export default {
}, },
data() { data() {
return { return {
currentCondition: this.currentCondition currentConditionOutput: ''
} }
}, },
mounted() { mounted() {
let conditionCollection = this.domainObject.configuration.conditionCollection; this.conditionSetIdentifier = this.openmct.objects.makeKeyString(this.domainObject.identifier);
this.currentConditionIdentifier = conditionCollection.length ? this.updateCurrentCondition(conditionCollection[0]) : null;
}, },
methods: { methods: {
setCurrentCondition() { updateCurrentOutput(currentConditionResult) {
if (this.currentConditionIdentifier) { if (this.openmct.objects.makeKeyString(currentConditionResult.id) === this.conditionSetIdentifier) {
this.openmct.objects.get(this.currentConditionIdentifier).then((obj) => { this.currentConditionOutput = currentConditionResult.output;
this.currentCondition = obj;
});
} }
},
updateCurrentCondition(conditionIdentifier) {
this.currentConditionIdentifier = conditionIdentifier;
this.setCurrentCondition();
} }
} }
}; };

View File

@ -22,7 +22,7 @@
<template> <template>
<section id="current-output"> <section id="current-output">
<div v-if="condition" <div v-if="output"
class="c-cs__ui__header" class="c-cs__ui__header"
> >
<span class="c-cs__ui__header-label">Current Output</span> <span class="c-cs__ui__header-label">Current Output</span>
@ -32,11 +32,11 @@
@click="expanded = !expanded" @click="expanded = !expanded"
></span> ></span>
</div> </div>
<div v-if="expanded && condition" <div v-if="expanded && output"
class="c-cs__ui_content" class="c-cs__ui_content"
> >
<div> <div>
<span class="current-output">{{ condition.configuration.output }}</span> <span class="current-output">{{ output }}</span>
</div> </div>
</div> </div>
</section> </section>
@ -47,9 +47,9 @@ export default {
inject: ['openmct', 'domainObject'], inject: ['openmct', 'domainObject'],
props: { props: {
isEditing: Boolean, isEditing: Boolean,
condition: { output: {
default: () => {return null;}, default: () => {return null;},
type: Object type: String
} }
}, },
data() { data() {

View File

@ -72,17 +72,19 @@ export default class TelemetryCriterion extends EventEmitter {
} }
computeResult(data) { computeResult(data) {
let comparator = this.findOperation(this.operation);
let params = [];
let result = false; let result = false;
params.push(data[this.metadata]); if (data) {
if (this.input instanceof Array && this.input.length) { let comparator = this.findOperation(this.operation);
params.push(this.input[0]); let params = [];
} else if (this.input) { params.push(data[this.metadata]);
params.push(this.input); if (this.input instanceof Array && this.input.length) {
} params.push(this.input[0]);
if (typeof comparator === 'function') { } else {
result = comparator(params); params.push(this.input);
}
if (typeof comparator === 'function') {
result = comparator(params);
}
} }
return result; return result;
} }
@ -100,12 +102,17 @@ export default class TelemetryCriterion extends EventEmitter {
/** /**
* Subscribes to the telemetry object and returns an unsubscribe function * Subscribes to the telemetry object and returns an unsubscribe function
* If the telemetry is not valid, returns nothing
*/ */
subscribe() { subscribe() {
this.unsubscribe(); if (this.isValid()) {
this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => { this.unsubscribe();
this.handleSubscription(datum); this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => {
}); this.handleSubscription(datum);
});
} else {
this.handleSubscription();
}
} }
/** /**