diff --git a/src/plugins/condition/Condition.js b/src/plugins/condition/Condition.js
index e99ac0e384..dfd21f0636 100644
--- a/src/plugins/condition/Condition.js
+++ b/src/plugins/condition/Condition.js
@@ -26,6 +26,7 @@ import TelemetryCriterion from "./criterion/TelemetryCriterion";
import { evaluateResults } from './utils/evaluator';
import { getLatestTimestamp } from './utils/time';
import AllTelemetryCriterion from "./criterion/AllTelemetryCriterion";
+import {TRIGGER_CONJUNCTION, TRIGGER_LABEL} from "./utils/constants";
/*
* conditionConfiguration = {
@@ -41,13 +42,14 @@ import AllTelemetryCriterion from "./criterion/AllTelemetryCriterion";
* ]
* }
*/
-export default class ConditionClass extends EventEmitter {
+export default class Condition extends EventEmitter {
/**
* Manages criteria and emits the result of - true or false - based on criteria evaluated.
* @constructor
* @param conditionConfiguration: {id: uuid,trigger: enum, criteria: Array of {id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier} }
* @param openmct
+ * @param conditionManager
*/
constructor(conditionConfiguration, openmct, conditionManager) {
super();
@@ -62,6 +64,7 @@ export default class ConditionClass extends EventEmitter {
this.createCriteria(conditionConfiguration.configuration.criteria);
}
this.trigger = conditionConfiguration.configuration.trigger;
+ this.description = '';
}
getResult(datum) {
@@ -109,7 +112,7 @@ export default class ConditionClass extends EventEmitter {
return {
id: criterionConfiguration.id || uuid(),
telemetry: criterionConfiguration.telemetry || '',
- telemetryObject: this.conditionManager.telemetryObjects[this.openmct.objects.makeKeyString(criterionConfiguration.telemetry)],
+ telemetryObjects: this.conditionManager.telemetryObjects,
operation: criterionConfiguration.operation || '',
input: criterionConfiguration.input === undefined ? [] : criterionConfiguration.input,
metadata: criterionConfiguration.metadata || ''
@@ -120,6 +123,7 @@ export default class ConditionClass extends EventEmitter {
criterionConfigurations.forEach((criterionConfiguration) => {
this.addCriterion(criterionConfiguration);
});
+ this.updateDescription();
}
updateCriteria(criterionConfigurations) {
@@ -127,10 +131,11 @@ export default class ConditionClass extends EventEmitter {
this.createCriteria(criterionConfigurations);
}
- updateTelemetry() {
+ updateTelemetryObjects() {
this.criteria.forEach((criterion) => {
- criterion.updateTelemetry(this.conditionManager.telemetryObjects);
+ criterion.updateTelemetryObjects(this.conditionManager.telemetryObjects);
});
+ this.updateDescription();
}
/**
@@ -178,6 +183,7 @@ export default class ConditionClass extends EventEmitter {
criterion.unsubscribe();
criterion.off('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
this.criteria.splice(found.index, 1, newCriterion);
+ this.updateDescription();
}
}
@@ -190,6 +196,7 @@ export default class ConditionClass extends EventEmitter {
});
criterion.destroy();
this.criteria.splice(found.index, 1);
+ this.updateDescription();
return true;
}
@@ -200,9 +207,30 @@ export default class ConditionClass extends EventEmitter {
let found = this.findCriterion(criterion.id);
if (found) {
this.criteria[found.index] = criterion.data;
+ this.updateDescription();
}
}
+ updateDescription() {
+ const triggerDescription = this.getTriggerDescription();
+ let description = '';
+ this.criteria.forEach((criterion, index) => {
+ if (!index) {
+ description = `Match if ${triggerDescription.prefix}`;
+ }
+ description = `${description} ${criterion.getDescription()} ${(index < this.criteria.length - 1) ? triggerDescription.conjunction : ''}`;
+ });
+ this.description = description;
+ this.conditionManager.updateConditionDescription(this);
+ }
+
+ getTriggerDescription() {
+ return {
+ conjunction: TRIGGER_CONJUNCTION[this.trigger],
+ prefix: `${TRIGGER_LABEL[this.trigger]}: `
+ };
+ }
+
requestLADConditionResult() {
let latestTimestamp;
let criteriaResults = {};
diff --git a/src/plugins/condition/ConditionManager.js b/src/plugins/condition/ConditionManager.js
index 7c0bbb7a69..a29f338be7 100644
--- a/src/plugins/condition/ConditionManager.js
+++ b/src/plugins/condition/ConditionManager.js
@@ -57,7 +57,7 @@ export default class ConditionManager extends EventEmitter {
endpoint,
this.telemetryReceived.bind(this, endpoint)
);
- this.updateConditionTelemetry();
+ this.updateConditionTelemetryObjects();
}
unsubscribeFromTelemetry(endpointIdentifier) {
@@ -70,11 +70,11 @@ export default class ConditionManager extends EventEmitter {
this.subscriptions[id]();
delete this.subscriptions[id];
delete this.telemetryObjects[id];
- this.removeConditionTelemetry();
+ this.removeConditionTelemetryObjects();
}
initialize() {
- this.conditionClassCollection = [];
+ this.conditions = [];
if (this.conditionSetDomainObject.configuration.conditionCollection.length) {
this.conditionSetDomainObject.configuration.conditionCollection.forEach((conditionConfiguration, index) => {
this.initCondition(conditionConfiguration, index);
@@ -82,13 +82,14 @@ export default class ConditionManager extends EventEmitter {
}
}
- updateConditionTelemetry() {
- this.conditionClassCollection.forEach((condition) => condition.updateTelemetry());
+ updateConditionTelemetryObjects() {
+ this.conditions.forEach((condition) => condition.updateTelemetryObjects());
}
- removeConditionTelemetry() {
+ removeConditionTelemetryObjects() {
let conditionsChanged = false;
- this.conditionSetDomainObject.configuration.conditionCollection.forEach((conditionConfiguration) => {
+ this.conditionSetDomainObject.configuration.conditionCollection.forEach((conditionConfiguration, conditionIndex) => {
+ let conditionChanged = false;
conditionConfiguration.configuration.criteria.forEach((criterion, index) => {
const isAnyAllTelemetry = criterion.telemetry && (criterion.telemetry === 'any' || criterion.telemetry === 'all');
if (!isAnyAllTelemetry) {
@@ -100,10 +101,14 @@ export default class ConditionManager extends EventEmitter {
criterion.metadata = '';
criterion.input = [];
criterion.operation = '';
- conditionsChanged = true;
+ conditionChanged = true;
}
}
});
+ if (conditionChanged) {
+ this.updateCondition(conditionConfiguration, conditionIndex);
+ conditionsChanged = true;
+ }
});
if (conditionsChanged) {
this.persistConditions();
@@ -111,18 +116,24 @@ export default class ConditionManager extends EventEmitter {
}
updateCondition(conditionConfiguration, index) {
- let condition = this.conditionClassCollection[index];
- condition.update(conditionConfiguration);
+ let condition = this.conditions[index];
this.conditionSetDomainObject.configuration.conditionCollection[index] = conditionConfiguration;
+ condition.update(conditionConfiguration);
+ this.persistConditions();
+ }
+
+ updateConditionDescription(condition) {
+ const found = this.conditionSetDomainObject.configuration.conditionCollection.find(conditionConfiguration => (conditionConfiguration.id === condition.id));
+ found.summary = condition.description;
this.persistConditions();
}
initCondition(conditionConfiguration, index) {
let condition = new Condition(conditionConfiguration, this.openmct, this);
if (index !== undefined) {
- this.conditionClassCollection.splice(index + 1, 0, condition);
+ this.conditions.splice(index + 1, 0, condition);
} else {
- this.conditionClassCollection.unshift(condition);
+ this.conditions.unshift(condition);
}
}
@@ -181,15 +192,15 @@ export default class ConditionManager extends EventEmitter {
}
removeCondition(index) {
- let condition = this.conditionClassCollection[index];
+ let condition = this.conditions[index];
condition.destroy();
- this.conditionClassCollection.splice(index, 1);
+ this.conditions.splice(index, 1);
this.conditionSetDomainObject.configuration.conditionCollection.splice(index, 1);
this.persistConditions();
}
findConditionById(id) {
- return this.conditionClassCollection.find(conditionClass => conditionClass.id === id);
+ return this.conditions.find(condition => condition.id === id);
}
reorderConditions(reorderPlan) {
@@ -234,14 +245,14 @@ export default class ConditionManager extends EventEmitter {
}
requestLADConditionSetOutput() {
- if (!this.conditionClassCollection.length) {
+ if (!this.conditions.length) {
return Promise.resolve([]);
}
return this.compositionLoad.then(() => {
let latestTimestamp;
let conditionResults = {};
- const conditionRequests = this.conditionClassCollection
+ const conditionRequests = this.conditions
.map(condition => condition.requestLADConditionResult());
return Promise.all(conditionRequests)
@@ -281,7 +292,7 @@ export default class ConditionManager extends EventEmitter {
isTelemetryUsed(endpoint) {
const id = this.openmct.objects.makeKeyString(endpoint.identifier);
- for(const condition of this.conditionClassCollection) {
+ for(const condition of this.conditions) {
if (condition.isTelemetryUsed(id)) {
return true;
}
@@ -300,7 +311,7 @@ export default class ConditionManager extends EventEmitter {
let timestamp = {};
timestamp[timeSystemKey] = normalizedDatum[timeSystemKey];
- this.conditionClassCollection.forEach(condition => {
+ this.conditions.forEach(condition => {
condition.getResult(normalizedDatum);
});
@@ -364,7 +375,7 @@ export default class ConditionManager extends EventEmitter {
this.stopObservingForChanges();
}
- this.conditionClassCollection.forEach((condition) => {
+ this.conditions.forEach((condition) => {
condition.destroy();
})
}
diff --git a/src/plugins/condition/ConditionManagerSpec.js b/src/plugins/condition/ConditionManagerSpec.js
index 2f9a6c3499..483053ba4e 100644
--- a/src/plugins/condition/ConditionManagerSpec.js
+++ b/src/plugins/condition/ConditionManagerSpec.js
@@ -126,7 +126,7 @@ describe('ConditionManager', () => {
it('creates a conditionCollection with a default condition', function () {
expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection.length).toEqual(1);
- let defaultConditionId = conditionMgr.conditionClassCollection[0].id;
+ let defaultConditionId = conditionMgr.conditions[0].id;
expect(defaultConditionId).toEqual(mockCondition.id);
});
diff --git a/src/plugins/condition/ConditionSpec.js b/src/plugins/condition/ConditionSpec.js
index 5cd0c33558..d887771647 100644
--- a/src/plugins/condition/ConditionSpec.js
+++ b/src/plugins/condition/ConditionSpec.js
@@ -36,19 +36,20 @@ describe("The condition", function () {
beforeEach (() => {
conditionManager = jasmine.createSpyObj('conditionManager',
- ['on']
+ ['on', 'updateConditionDescription']
);
mockTelemetryReceived = jasmine.createSpy('listener');
conditionManager.on('telemetryReceived', mockTelemetryReceived);
+ conditionManager.updateConditionDescription.and.returnValue(function () {});
testTelemetryObject = {
identifier:{ namespace: "", key: "test-object"},
type: "test-object",
name: "Test Object",
telemetry: {
- values: [{
- key: "value",
- name: "Value",
+ valueMetadatas: [{
+ key: "some-key",
+ name: "Some attribute",
hints: {
range: 2
}
@@ -78,7 +79,7 @@ describe("The condition", function () {
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', 'subscribe', 'getMetadata']);
openmct.telemetry.isTelemetryObject.and.returnValue(true);
openmct.telemetry.subscribe.and.returnValue(function () {});
- openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values);
+ openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry);
mockTimeSystems = {
key: 'utc'
diff --git a/src/plugins/condition/components/Condition.vue b/src/plugins/condition/components/Condition.vue
index 6f1deb7d3c..51c58b6da3 100644
--- a/src/plugins/condition/components/Condition.vue
+++ b/src/plugins/condition/components/Condition.vue
@@ -50,7 +50,7 @@
{{ condition.configuration.name }}
-
+
Define criteria
@@ -250,7 +250,7 @@ export default {
keys.forEach((trigger) => {
triggerOptions.push({
value: TRIGGER[trigger],
- label: TRIGGER_LABEL[TRIGGER[trigger]]
+ label: `when ${TRIGGER_LABEL[TRIGGER[trigger]]}`
});
});
return triggerOptions;
diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue
index 54c797d966..3f7ba73c30 100644
--- a/src/plugins/condition/components/ConditionCollection.vue
+++ b/src/plugins/condition/components/ConditionCollection.vue
@@ -152,7 +152,8 @@ export default {
},
observeForChanges() {
this.stopObservingForChanges = this.openmct.objects.observe(this.domainObject, 'configuration.conditionCollection', (newConditionCollection) => {
- this.conditionCollection = newConditionCollection;
+ //this forces children to re-render
+ this.conditionCollection = newConditionCollection.map(condition => condition);
this.updateDefaultCondition();
});
},
diff --git a/src/plugins/condition/components/ConditionDescription.vue b/src/plugins/condition/components/ConditionDescription.vue
index 3bfd121e6b..c7cc42ae0e 100644
--- a/src/plugins/condition/components/ConditionDescription.vue
+++ b/src/plugins/condition/components/ConditionDescription.vue
@@ -27,20 +27,20 @@
>
{{ condition.configuration.name }}
-
- When
- {{ criterionDescription }}
- {{ triggerDescription }}
+ {{ description }}
+
+
+ Match if no other condition is matched