Merge pull request #2656 from nasa/condition-ui-redo

Condition ui redo
This commit is contained in:
Shefali Joshi 2020-02-04 15:11:02 -08:00 committed by GitHub
commit 67919ece16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 1342 additions and 160 deletions

View File

@ -64,6 +64,7 @@
"request": "^2.69.0",
"split": "^1.0.0",
"style-loader": "^1.0.1",
"uuid": "^3.3.3",
"v8-compile-cache": "^1.1.0",
"vue": "2.5.6",
"vue-loader": "^15.2.6",

View File

@ -0,0 +1,247 @@
/*****************************************************************************
* 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 * as EventEmitter from 'eventemitter3';
import uuid from 'uuid';
import TelemetryCriterion from "@/plugins/condition/criterion/TelemetryCriterion";
import { TRIGGER } from "@/plugins/condition/utils/constants";
import {computeCondition} from "@/plugins/condition/utils/evaluator";
/*
* conditionDefinition = {
* identifier: {
* key: '',
* namespace: ''
* },
* trigger: 'any'/'all',
* criteria: [
* {
* operation: '',
* input: '',
* metaDataKey: '',
* key: 'someTelemetryObjectKey'
* }
* ]
* }
*/
export default class ConditionClass extends EventEmitter {
/**
* Manages criteria and emits the result of - true or false - based on criteria evaluated.
* @constructor
* @param conditionDefinition: {identifier: {domainObject.identifier},trigger: enum, criteria: Array of {id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier} }
* @param openmct
*/
constructor(conditionDefinition, openmct) {
super();
this.openmct = openmct;
this.id = this.openmct.objects.makeKeyString(conditionDefinition.identifier);
this.criteria = [];
this.criteriaResults = {};
if (conditionDefinition.definition.criteria) {
this.createCriteria(conditionDefinition.definition.criteria);
}
this.trigger = conditionDefinition.definition.trigger;
this.result = null;
this.openmct.objects.get(this.id).then(obj => this.observeForChanges(obj));
}
observeForChanges(conditionDO) {
this.stopObservingForChanges = this.openmct.objects.observe(conditionDO, '*', this.update.bind(this));
}
update(newDomainObject) {
this.updateTrigger(newDomainObject.definition.trigger);
this.updateCriteria(newDomainObject.definition.criteria);
}
updateTrigger(trigger) {
if (this.trigger !== trigger) {
this.trigger = trigger;
this.handleConditionUpdated();
}
}
generateCriterion(criterionDefinition) {
return {
id: uuid(),
operation: criterionDefinition.operation || '',
input: criterionDefinition.input === undefined ? [] : criterionDefinition.input,
metaDataKey: criterionDefinition.metaDataKey || '',
key: criterionDefinition.key || ''
};
}
createCriteria(criterionDefinitions) {
criterionDefinitions.forEach((criterionDefinition) => {
this.addCriterion(criterionDefinition);
});
}
updateCriteria(criterionDefinitions) {
this.destroyCriteria();
this.createCriteria(criterionDefinitions);
}
/**
* adds criterion to the condition.
*/
addCriterion(criterionDefinition) {
let criterionDefinitionWithId = this.generateCriterion(criterionDefinition || null);
let criterion = new TelemetryCriterion(criterionDefinitionWithId, this.openmct);
criterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
criterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj));
if (!this.criteria) {
this.criteria = [];
}
this.criteria.push(criterion);
//Do we need this here?
this.handleConditionUpdated();
return criterionDefinitionWithId.id;
}
findCriterion(id) {
let criterion;
for (let i=0, ii=this.criteria.length; i < ii; i ++) {
if (this.criteria[i].id === id) {
criterion = {
item: this.criteria[i],
index: i
}
}
}
return criterion;
}
updateCriterion(id, criterionDefinition) {
let found = this.findCriterion(id);
if (found) {
const newCriterionDefinition = this.generateCriterion(criterionDefinition);
let newCriterion = new TelemetryCriterion(newCriterionDefinition, this.openmct);
newCriterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
newCriterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj));
let criterion = found.item;
criterion.unsubscribe();
criterion.off('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
criterion.off('criterionResultUpdated', (obj) => this.handleCriterionResult(obj));
this.criteria.splice(found.index, 1, newCriterion);
if (this.criteriaResults[criterion.id] !== undefined) {
delete this.criteriaResults[criterion.id];
}
this.handleConditionUpdated();
}
}
removeCriterion(id) {
if (this.destroyCriterion(id)) {
this.handleConditionUpdated();
}
}
destroyCriterion(id) {
let found = this.findCriterion(id);
if (found) {
let criterion = found.item;
criterion.destroy();
criterion.off('criterionUpdated', (result) => {
this.handleCriterionUpdated(id, result);
});
this.criteria.splice(found.index, 1);
if (this.criteriaResults[criterion.id] !== undefined) {
delete this.criteriaResults[criterion.id];
}
return true;
}
return false;
}
handleCriterionUpdated(criterion) {
let found = this.findCriterion(criterion.id);
if (found) {
this.criteria[found.index] = criterion.data;
//Most likely don't need this.
this.subscribe();
this.emitEvent('conditionUpdated', {
trigger: this.trigger,
criteria: this.criteria
});
}
}
handleCriterionResult(eventData) {
let id = eventData.id;
let result = eventData.data.result;
let found = this.findCriterion(id);
if (found) {
this.criteriaResults[id] = result;
}
this.handleConditionUpdated();
}
subscribe() {
this.criteria.forEach((criterion) => {
criterion.subscribe();
})
}
handleConditionUpdated() {
// trigger an updated event so that consumers can react accordingly
this.evaluate();
this.emitEvent('conditionResultUpdated', {result: this.result});
}
getCriteria() {
return this.criteria;
}
destroyCriteria() {
let success = true;
//looping through the array backwards since destroyCriterion modifies the criteria array
for (let i=this.criteria.length-1; i >= 0; i--) {
success = success && this.destroyCriterion(this.criteria[i].id);
}
return success;
}
//TODO: implement as part of the evaluator class task.
evaluate() {
this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
}
emitEvent(eventName, data) {
this.emit(eventName, {
id: this.id,
data: data
});
}
destroy() {
if (typeof this.stopObservingForChanges === 'function') {
this.stopObservingForChanges();
}
this.destroyCriteria();
}
}

View File

@ -0,0 +1,121 @@
/*****************************************************************************
* 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 {TRIGGER} from "./utils/constants";
import TelemetryCriterion from "./criterion/TelemetryCriterion";
let openmct = {},
mockListener,
testConditionDefinition,
testTelemetryObject,
conditionObj;
describe("The condition", function () {
beforeEach (() => {
mockListener = jasmine.createSpy('listener');
testTelemetryObject = {
identifier:{ namespace: "", key: "test-object"},
type: "test-object",
name: "Test Object",
telemetry: {
values: [{
key: "some-key",
name: "Some attribute",
hints: {
domain: 1
}
}, {
key: "some-other-key",
name: "Another attribute",
hints: {
range: 1
}
}]
}
};
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
openmct.objects.get.and.returnValue(new Promise(function (resolve, reject) {
resolve(testTelemetryObject);
})); openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
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);
testConditionDefinition = {
definition: {
trigger: TRIGGER.ANY,
criteria: [
{
operation: 'equalTo',
input: false,
metaDataKey: 'value',
key: testTelemetryObject.identifier
}
]
}
};
conditionObj = new Condition(
testConditionDefinition,
openmct
);
conditionObj.on('conditionUpdated', mockListener);
});
it("generates criteria with an id", function () {
const testCriterion = testConditionDefinition.definition.criteria[0];
let criterion = conditionObj.generateCriterion(testCriterion);
expect(criterion.id).toBeDefined();
expect(criterion.operation).toEqual(testCriterion.operation);
expect(criterion.input).toEqual(testCriterion.input);
expect(criterion.metaDataKey).toEqual(testCriterion.metaDataKey);
expect(criterion.key).toEqual(testCriterion.key);
});
it("initializes with an id", function () {
expect(conditionObj.id).toBeDefined();
});
it("initializes with criteria from the condition definition", function () {
expect(conditionObj.criteria.length).toEqual(1);
let criterion = conditionObj.criteria[0];
expect(criterion instanceof TelemetryCriterion).toBeTrue();
expect(criterion.operator).toEqual(testConditionDefinition.definition.criteria[0].operator);
expect(criterion.input).toEqual(testConditionDefinition.definition.criteria[0].input);
expect(criterion.metaDataKey).toEqual(testConditionDefinition.definition.criteria[0].metaDataKey);
});
it("initializes with the trigger from the condition definition", function () {
expect(conditionObj.trigger).toEqual(testConditionDefinition.definition.trigger);
});
it("destroys all criteria for a condition", function () {
const result = conditionObj.destroyCriteria();
expect(result).toBeTrue();
expect(conditionObj.criteria.length).toEqual(0);
});
});

View File

@ -1,53 +1,66 @@
<template>
<div id="conditionArea"
<!-- TODO: current condition class should be set using openmct.objects.makeKeyString(<identifier>) -->
<div v-if="condition"
id="conditionArea"
class="c-cs-ui__conditions"
:class="['widget-condition', { 'widget-condition--current': isCurrent }]"
:class="['widget-condition', { 'widget-condition--current': currentConditionIdentifier && (currentConditionIdentifier.key === conditionIdentifier.key) }]"
>
<div class="title-bar">
<span v-if="isDefault"
class="condition-name"
>Default
<span class="condition-name">
{{ condition.definition.name }}
</span>
<span v-else
class="condition-name"
>[condition name]
</span>
<span v-if="isDefault"
class="condition-output"
>Output: false
</span>
<span v-else
class="condition-output"
>Output: [condition output]
<span class="condition-output">
Output: {{ condition.definition.output }}
</span>
</div>
<div class="condition-config">
<span v-if="isDefault"
class="condition-description"
>When all else fails
</span>
<span v-else
class="condition-description"
>[condition description]
<span class="condition-description">
{{ condition.definition.description }}
</span>
</div>
</div>
</template>
<script>
import ConditionClass from "@/plugins/condition/Condition";
export default {
inject: ['openmct'],
props: {
isEditing: Boolean,
isCurrent: Boolean,
isDefault: Boolean
conditionIdentifier: {
type: Object,
required: true
},
currentConditionIdentifier: {
type: Object,
required: true
}
},
data() {
return {
conditionData: {}
condition: this.condition
};
},
destroyed() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
this.conditionClass.destroy();
}
},
mounted() {
this.openmct.objects.get(this.conditionIdentifier).then((obj => {
this.condition = obj;
this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
}));
},
methods: {
handleConditionResult(args) {
this.$emit('conditionResultUpdated', {
id: this.conditionIdentifier,
result: args.data.result
})
}
}
}
</script>

View File

@ -1,3 +1,25 @@
/*****************************************************************************
* 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.
*****************************************************************************/
<template>
<section id="conditionCollection"
class="c-cs__ui_section"
@ -28,19 +50,36 @@
<span class="c-cs-button__label">Add Condition</span>
</button>
</div>
<div v-for="condition in conditions"
:key="condition.key"
>
<div v-if="isEditing">
<ConditionEdit :domain-object="condition.domainObject"
:is-default="condition.isDefault"
/>
</div>
<div v-else>
<Condition :domain-object="condition.domainObject"
:is-default="condition.isDefault"
/>
</div>
<div class="c-c condition-collection">
<ul class="c-c__container-holder">
<li v-for="(conditionIdentifier, index) in conditionCollection"
:key="conditionIdentifier.key"
>
<div v-if="isEditing">
<div class="c-c__drag-ghost"
@drop.prevent="dropCondition"
@dragenter="dragEnter"
@dragleave="dragLeave"
@dragover.prevent
></div>
<ConditionEdit :condition-identifier="conditionIdentifier"
:telemetry="telemetryObjs"
:current-condition-identifier="currentConditionIdentifier"
:condition-index="index"
@updateCurrentCondition="updateCurrentCondition"
@removeCondition="removeCondition"
@conditionResultUpdated="handleConditionResult"
@setMoveIndex="setMoveIndex"
/>
</div>
<div v-else>
<Condition :condition-identifier="conditionIdentifier"
:current-condition-identifier="currentConditionIdentifier"
@conditionResultUpdated="handleConditionResult"
/>
</div>
</li>
</ul>
</div>
</div>
</section>
@ -49,6 +88,7 @@
<script>
import Condition from '../../condition/components/Condition.vue';
import ConditionEdit from '../../condition/components/ConditionEdit.vue';
import uuid from 'uuid';
export default {
inject: ['openmct', 'domainObject'],
@ -62,49 +102,169 @@ export default {
data() {
return {
expanded: true,
conditions: [
{
identifier: {
key: 'testConditionKey',
namespace: ''
},
type: 'condition',
isDefault: true
}
]
parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier),
conditionCollection: [],
conditions: [],
currentConditionIdentifier: this.currentConditionIdentifier || {},
telemetryObjs: this.telemetryObjs,
moveIndex: Number,
isDragging: false
};
},
destroyed() {
this.composition.off('add', this.addCondition);
this.composition.off('remove', this.removeCondition);
this.composition.off('reorder', this.reorder);
this.composition.off('add', this.addTelemetry);
},
mounted() {
this.telemetryObjs = [];
this.conditionResults = {};
this.instantiate = this.openmct.$injector.get('instantiate');
this.composition = this.openmct.composition.get(this.domainObject);
this.composition.on('add', this.addCondition);
this.composition.on('remove', this.removeCondition);
this.composition.on('reorder', this.reorder);
this.composition.on('add', this.addTelemetry);
this.composition.on('remove', this.removeTelemetry);
this.composition.load();
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : [];
if (!this.conditionCollection.length) {
this.addCondition(null, true);
} else {
this.updateCurrentCondition(this.conditionCollection[0]);
}
},
methods: {
addCondition() {
let condition = {};
condition.domainObject = this.domainObject;
condition.key = this.openmct.objects.makeKeyString(this.domainObject.identifier);
setMoveIndex(index) {
this.moveIndex = index;
this.isDragging = true;
},
dropCondition(e) {
let targetIndex = Array.from(document.querySelectorAll('.c-c__drag-ghost')).indexOf(e.target);
if (targetIndex > this.moveIndex) { targetIndex-- } // for 'downward' move
const oldIndexArr = Object.keys(this.conditionCollection);
const move = function (arr, old_index, new_index) {
while (old_index < 0) {
old_index += arr.length;
}
while (new_index < 0) {
new_index += arr.length;
}
if (new_index >= arr.length) {
var k = new_index - arr.length;
while ((k--) + 1) {
arr.push(undefined);
}
}
arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
return arr;
}
const newIndexArr = move(oldIndexArr, this.moveIndex, targetIndex);
const reorderPlan = [];
this.conditions.unshift(condition);
for (let i = 0; i < oldIndexArr.length; i++) {
reorderPlan.push({oldIndex: Number(newIndexArr[i]), newIndex: i});
}
this.reorder(reorderPlan);
e.target.classList.remove("dragging");
this.isDragging = false;
},
dragEnter(e) {
if (!this.isDragging) { return }
let targetIndex = Array.from(document.querySelectorAll('.c-c__drag-ghost')).indexOf(e.target);
if (targetIndex > this.moveIndex) { targetIndex-- } // for 'downward' move
if (this.moveIndex === targetIndex) { return }
e.target.classList.add("dragging");
},
dragLeave(e) {
e.target.classList.remove("dragging");
},
handleConditionResult(args) {
let idAsString = this.openmct.objects.makeKeyString(args.id);
this.conditionResults[idAsString] = args.result;
this.updateCurrentConditionId();
},
updateCurrentConditionId() {
let currentConditionIdentifier = this.conditionCollection[this.conditionCollection.length-1];
for (let i=0, ii = this.conditionCollection.length-1; i< ii; 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);
},
addTelemetry(telemetryDomainObject) {
this.telemetryObjs.push(telemetryDomainObject);
},
removeTelemetry(telemetryDomainObjectIdentifier) {
let index = _.findIndex(this.telemetryObjs, (obj) => {
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);
}
},
addCondition(event, isDefault) {
let conditionDomainObject = this.getConditionDomainObject(!!isDefault);
//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());
this.conditionCollection.unshift(conditionDomainObject.identifier);
this.persist();
},
updateCurrentCondition(identifier) {
this.currentConditionIdentifier = identifier;
},
getConditionDomainObject(isDefault) {
let conditionObj = {
isDefault: isDefault,
identifier: {
namespace: this.domainObject.identifier.namespace,
key: uuid()
},
definition: {
name: isDefault ? 'Default' : 'Unnamed Condition',
output: 'false',
trigger: 'any',
criteria: isDefault ? [] : [{
operation: '',
input: '',
metaDataKey: '',
key: ''
}]
},
summary: 'summary description'
};
let conditionDomainObjectKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
let newDomainObject = this.instantiate(conditionObj, conditionDomainObjectKeyString);
return newDomainObject.useCapability('adapter');
},
updateCondition(updatedCondition) {
//TODO: this should only happen for reordering
let index = _.findIndex(this.conditions, (condition) => condition.id === updatedCondition.id);
this.conditions[index] = updatedCondition;
},
removeCondition(identifier) {
console.log(`remove condition`);
// let index = _.findIndex(this.conditions, (condition) => this.openmct.objects.makeKeyString(identifier) === item.key);
// this.conditions.splice(index, 1);
let index = _.findIndex(this.conditionCollection, (condition) => {
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) {
let oldConditions = this.conditions.slice();
let oldConditions = this.conditionCollection.slice();
reorderPlan.forEach((reorderEvent) => {
this.$set(this.conditions, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]);
this.$set(this.conditionCollection, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]);
});
this.persist();
},
persist() {
this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.conditionCollection);
}
}
}

View File

@ -1,13 +1,37 @@
/*****************************************************************************
* 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.
*****************************************************************************/
<template>
<div id="conditionArea"
class="c-cs-editui__conditions"
:class="['widget-condition', { 'widget-condition--current': isCurrent }]"
<!-- TODO: current condition class should be set using openmct.objects.makeKeyString(<identifier>) -->
<div v-if="condition"
class="c-c-editui__conditions c-c-container__container c-c__drag-wrapper"
:class="['widget-condition', { 'widget-condition--current': currentConditionIdentifier && (currentConditionIdentifier.key === conditionIdentifier.key) }]"
>
<div class="title-bar">
<span
class="c-c__menu-hamburger"
:class="{ 'is-enabled': !isDefault }"
@click="expanded = !expanded"
<span class="c-c__menu-hamburger"
:class="{ 'is-enabled': !condition.isDefault }"
:draggable="!condition.isDefault"
@dragstart="dragStart"
@dragover.stop
></span>
<span
class="is-enabled flex-elem"
@ -15,45 +39,33 @@
@click="expanded = !expanded"
></span>
<div class="condition-summary">
<span v-if="isDefault"
class="condition-name"
>Default
</span>
<span v-else
class="condition-name"
>[condition name]
</span>
<span v-if="isDefault"
class="condition-description"
>When all else fails
</span>
<span v-else
class="condition-description"
>[condition description]
</span>
<span class="condition-name">{{ condition.definition.name }}</span>
<!-- TODO: description should be derived from criteria -->
<span class="condition-description">{{ condition.definition.name }}</span>
</div>
<span v-if="!isDefault"
<span v-if="!condition.isDefault"
class="is-enabled c-c__duplicate"
></span>
<span v-if="!isDefault"
<span v-if="!condition.isDefault"
class="is-enabled c-c__trash"
@click="removeCondition"
></span>
</div>
<div v-if="expanded"
class="condition-config-edit widget-rule-content c-sw-editui__rules-wrapper holder widget-rules-wrapper flex-elem expanded"
class="condition-config-edit widget-condition-content c-sw-editui__conditions-wrapper holder widget-conditions-wrapper flex-elem expanded"
>
<div id="ruleArea"
class="c-sw-editui__rules widget-rules"
<div id="conditionArea"
class="c-c-editui__condition widget-conditions"
>
<div class="c-sw-rule">
<div class="c-sw-rule__ui l-compact-form l-widget-rule has-local-controls">
<div class="c-c-condition">
<div class="c-c-condition__ui l-compact-form l-widget-condition has-local-controls">
<div>
<ul>
<ul class="t-widget-condition-config">
<li>
<label>Condition Name</label>
<span class="controls">
<input class="t-rule-name-input"
<input v-model="condition.definition.name"
class="t-condition-name-input"
type="text"
>
</span>
@ -61,12 +73,91 @@
<li>
<label>Output</label>
<span class="controls">
<select class="">
<option value="false">false</option>
<select v-model="selectedOutputKey"
@change="checkInputValue"
>
<option value="">- Select Output -</option>
<option v-for="option in outputOptions"
:key="option.key"
:value="option.key"
>
{{ option.text }}
</option>
</select>
<input v-if="selectedOutputKey === outputOptions[2].key"
v-model="condition.definition.output"
class="t-condition-name-input"
type="text"
>
</span>
</li>
</ul>
<div v-if="!condition.isDefault"
class="widget-condition-content expanded"
>
<ul class="t-widget-condition-config">
<li class="has-local-controls t-condition">
<label>Match when</label>
<span class="controls">
<select>
<option value="all">all criteria are met</option>
<option value="any">any criteria are met</option>
</select>
</span>
</li>
</ul>
<ul class="t-widget-condition-config">
<li v-if="telemetry.length"
class="has-local-controls t-condition"
>
<label>when</label>
<span class="t-configuration">
<span class="controls">
<select v-model="selectedTelemetryKey"
@change="updateTelemetryMetaData"
>
<option value="">- Select Telemetry -</option>
<option v-for="telemetryOption in telemetry"
:key="telemetryOption.identifier.key"
:value="telemetryOption.identifier"
>
{{ telemetryOption.name }}
</option>
</select>
</span>
<span class="controls">
<select v-model="selectedMetaDataKey">
<option value="">- Select Field -</option>
<option v-for="option in telemetryMetadata"
:key="option.key"
:value="option.key"
>
{{ option.name }}
</option>
</select>
</span>
<span class="controls">
<select v-model="selectOperationName"
@change="setInputValueVisibility"
>
<option value="">- Select Comparison -</option>
<option v-for="option in operations"
:key="option.name"
:value="option.name"
>
{{ option.text }}
</option>
</select>
<input v-if="comparisonValueField"
class="t-condition-name-input"
type="text"
v-model="operationValue"
>
</span>
</span>
</li>
</ul>
</div>
</div>
</div>
</div>
@ -76,23 +167,215 @@
</template>
<script>
import { OPERATIONS } from '../utils/operations';
import ConditionClass from "@/plugins/condition/Condition";
export default {
inject: ['openmct'],
inject: ['openmct', 'domainObject'],
props: {
isEditing: Boolean,
isCurrent: Boolean,
isDefault: Boolean
conditionIdentifier: {
type: Object,
required: true
},
currentConditionIdentifier: {
type: Object,
required: true
},
telemetry: {
type: Array,
required: true,
default: () => []
},
conditionIndex: {
type: Number,
required: true
}
},
data() {
return {
conditions: {},
expanded: true
condition: this.condition,
expanded: true,
telemetryObject: this.telemetryObject,
telemetryMetadata: this.telemetryMetadata,
operations: OPERATIONS,
selectedMetaDataKey: '',
selectedTelemetryKey: '',
selectOperationName: '',
selectedOutputKey: '',
stringOutputField: false,
comparisonValueField: false,
operationValue: this.operationValue,
outputOptions: [
{
key: 'false',
text: 'False'
},
{
key: 'true',
text: 'True'
},
{
key: 'string',
text: 'String'
}
]
};
},
destroyed() {
this.destroy();
},
mounted() {
this.openmct.objects.get(this.conditionIdentifier).then((obj => {
this.condition = obj;
this.initialize();
}));
},
updated() {
//validate telemetry exists, update criteria as needed
this.validate();
this.persist();
},
methods: {
removeCondition() {
console.log(this);
// this.conditions.splice(index, 1);
dragStart(e) {
e.dataTransfer.effectAllowed = "copyMove";
e.dataTransfer.setDragImage(e.target.closest('.c-c-container__container'), 0, 0);
this.$emit('setMoveIndex', this.conditionIndex);
},
initialize() {
this.setOutput();
this.setOperation();
this.updateTelemetry();
this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
},
destroy() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
this.conditionClass.destroy();
delete this.conditionClass;
}
},
reset() {
this.selectedMetaDataKey = '';
this.selectedTelemetryKey = '';
this.selectOperationName = '';
this.operationValue = '';
},
validate() {
if (this.hasTelemetry() && !this.getTelemetryKey()) {
this.reset();
} else {
if (!this.conditionClass) {
this.initialize();
}
}
},
handleConditionResult(args) {
this.$emit('conditionResultUpdated', {
id: this.conditionIdentifier,
result: args.data.result
})
},
removeCondition(ev) {
this.$emit('removeCondition', this.conditionIdentifier);
},
setOutput() {
let conditionOutput = this.condition.definition.output;
if (conditionOutput !== 'false' && conditionOutput !== 'true') {
this.selectedOutputKey = this.outputOptions[2].key;
} else {
if (conditionOutput === 'true') {
this.selectedOutputKey = this.outputOptions[1].key;
} else {
this.selectedOutputKey = this.outputOptions[0].key;
}
}
},
setOperation() {
if (this.condition.definition.criteria.length && this.condition.definition.criteria[0].operation) {
for (let i=0, ii=this.operations.length; i < ii; i++) {
if (this.condition.definition.criteria[0].operation === this.operations[i].name) {
this.selectOperationName = this.operations[i].name;
this.comparisonValueField = this.operations[i].inputCount > 0;
if (this.comparisonValueField) {
this.operationValue = this.condition.definition.criteria[0].input[0];
}
}
}
}
},
updateTelemetry() {
if (this.hasTelemetry()) {
this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => {
this.telemetryObject = obj;
this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values();
this.selectedMetaDataKey = this.getTelemetryMetadataKey();
this.selectedTelemetryKey = this.getTelemetryKey();
});
} else {
this.telemetryObject = null;
}
},
getTelemetryMetadataKey() {
let index = -1;
if (this.condition.definition.criteria[0].metaDataKey) {
index = _.findIndex(this.telemetryMetadata, (metadata) => {
return metadata.key === this.condition.definition.criteria[0].metaDataKey;
});
}
return this.telemetryMetadata.length && index > -1 ? this.telemetryMetadata[index].key : '';
},
getTelemetryKey() {
let index = -1;
if (this.condition.definition.criteria[0].key) {
index = _.findIndex(this.telemetry, (obj) => {
let key = this.openmct.objects.makeKeyString(obj.identifier);
let conditionKey = this.openmct.objects.makeKeyString(this.condition.definition.criteria[0].key);
return key === conditionKey;
});
}
return this.telemetry.length && index > -1 ? this.telemetry[index].identifier : '';
},
hasTelemetry() {
return this.condition.definition.criteria.length && this.condition.definition.criteria[0].key;
},
updateConditionCriteria() {
if (this.condition.definition.criteria.length) {
let criterion = this.condition.definition.criteria[0];
criterion.key = this.selectedTelemetryKey;
criterion.metaDataKey = this.selectedMetaDataKey;
criterion.operation = this.selectOperationName;
criterion.input = [this.operationValue];
}
},
persist() {
this.updateConditionCriteria();
this.openmct.objects.mutate(this.condition, 'definition', this.condition.definition);
},
checkInputValue() {
if (this.selectedOutputKey === this.outputOptions[2].key) {
this.condition.definition.output = '';
} else {
this.condition.definition.output = this.selectedOutputKey;
}
},
setInputValueVisibility(ev) {
for (let i=0, ii=this.operations.length; i < ii; i++) {
if (this.selectOperationName === this.operations[i].name) {
this.comparisonValueField = this.operations[i].inputCount > 0;
break;
}
}
//find the criterion being updated and set the operation property
},
updateTelemetryMetaData() {
this.selectedMetaDataKey = '';
this.updateConditionCriteria();
this.updateTelemetry();
},
updateCurrentCondition() {
this.$emit('updateCurrentCondition', this.conditionIdentifier);
}
}
}

View File

@ -1,11 +1,33 @@
/*****************************************************************************
* 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.
*****************************************************************************/
<template>
<div class="c-object-view u-contents">
<div class="c-cs-edit w-condition-set">
<div class="c-sw-edit__ui holder">
<CurrentOutput :current-output="mockCurrentOutput" />
<TestData :is-editing="isEditing" />
<ConditionCollection :is-editing="isEditing" />
</div>
<div class="c-cs-edit w-condition-set">
<div class="c-sw-edit__ui holder">
<CurrentOutput :condition="currentCondition" />
<TestData :is-editing="isEditing" />
<ConditionCollection :is-editing="isEditing"
@currentConditionUpdated="updateCurrentCondition"
/>
</div>
</div>
</template>
@ -16,7 +38,7 @@ import TestData from './TestData.vue';
import ConditionCollection from './ConditionCollection.vue';
export default {
inject: ["openmct", "objectPath", "domainObject"],
inject: ["openmct", "domainObject"],
components: {
CurrentOutput,
TestData,
@ -27,7 +49,24 @@ export default {
},
data() {
return {
mockCurrentOutput: 'Data_Present'
currentCondition: this.currentCondition
}
},
mounted() {
let conditionCollection = this.domainObject.configuration.conditionCollection;
this.currentConditionIdentifier = conditionCollection.length ? this.updateCurrentCondition(conditionCollection[0]) : null;
},
methods: {
setCurrentCondition() {
if (this.currentConditionIdentifier) {
this.openmct.objects.get(this.currentConditionIdentifier).then((obj) => {
this.currentCondition = obj;
});
}
},
updateCurrentCondition(conditionIdentifier) {
this.currentConditionIdentifier = conditionIdentifier;
this.setCurrentCondition();
}
}
};

View File

@ -1,6 +1,30 @@
/*****************************************************************************
* 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.
*****************************************************************************/
<template>
<section id="current-output">
<div class="c-cs__ui__header">
<div v-if="condition"
class="c-cs__ui__header"
>
<span class="c-cs__ui__header-label">Current Output</span>
<span
class="is-enabled flex-elem"
@ -8,11 +32,11 @@
@click="expanded = !expanded"
></span>
</div>
<div v-if="expanded"
<div v-if="expanded && condition"
class="c-cs__ui_content"
>
<div>
<span class="current-output">{{ currentOutput }}</span>
<span class="current-output">{{ condition.definition.output }}</span>
</div>
</div>
</section>
@ -20,18 +44,23 @@
<script>
export default {
inject: ['openmct'],
inject: ['openmct', 'domainObject'],
props: {
currentOutput: {
type: String,
default: ''
},
isEditing: Boolean
isEditing: Boolean,
condition: {
default: () => {return null;},
type: Object
}
},
data() {
return {
expanded: true
};
}
},
mounted() {
},
updated() {
},
methods: {

View File

@ -1,3 +1,25 @@
/*****************************************************************************
* 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.
*****************************************************************************/
<template>
<section v-show="isEditing"
id="test-data"

View File

@ -1,8 +1,6 @@
.widget-condition {
background-color: #eee;
margin: 0 0 0.6em;
margin: 0 0 0.33em;
border-radius: 3px;
&--current {
@ -11,6 +9,10 @@
}
.c-c-editui__conditions.widget-condition {
margin: 0;
}
.title-bar {
display: flex;
align-items: center;
@ -53,31 +55,33 @@
margin-left: 0;
}
.l-widget-rule {
.l-widget-condition {
padding: 0;
}
.widget-rule-content.expanded {
.l-compact-form ul li {
padding: 0;
}
.widget-condition-content.expanded {
margin: 0 3px;
}
.widget-rule-content.expanded ul {
.widget-condition-content.expanded ul {
border-top: solid 1px #ccc;
padding: 5px;
}
.l-compact-form ul li {
padding: 1px 0;
padding: 2px;
}
.l-compact-form ul li .controls {
line-height: 20px;
min-height: 20px;
display: inline-flex;
flex-grow: inherit;
padding: 2px 0;
}
.l-compact-form ul li > label {
display: block;
width: 90px;
min-width: 90px;
text-align: right;
line-height: 20px;
}
@ -133,7 +137,14 @@
}
}
.c-c__menu-hamburger {
&:active {
cursor: grabbing;
cursor: -moz-grabbing;
cursor: -webkit-grabbing;
}
&:before {
content: $glyph-icon-menu-hamburger;
}
@ -150,3 +161,15 @@
content: $glyph-icon-trash;
}
}
.c-c__drag-ghost {
width: 100%;
min-height: 0.33em;
&.dragging {
min-height: 2em;
border: solid 1px blue;
background-color: lightblue;
border-radius: 2px;
}
}

View File

@ -21,6 +21,7 @@
*****************************************************************************/
import * as EventEmitter from 'eventemitter3';
import {OPERATIONS} from '../utils/operations';
export default class TelemetryCriterion extends EventEmitter {
@ -38,6 +39,9 @@ export default class TelemetryCriterion extends EventEmitter {
this.objectAPI = this.openmct.objects;
this.telemetryAPI = this.openmct.telemetry;
this.id = telemetryDomainObjectDefinition.id;
this.operation = telemetryDomainObjectDefinition.operation;
this.input = telemetryDomainObjectDefinition.input;
this.metaDataKey = telemetryDomainObjectDefinition.metaDataKey;
this.subscription = null;
this.telemetryMetadata = null;
this.telemetryObjectIdAsString = null;
@ -51,18 +55,35 @@ export default class TelemetryCriterion extends EventEmitter {
this.emitEvent('criterionUpdated', this);
}
handleSubscription(datum) {
let data = this.normalizeData(datum);
handleSubscription(data) {
let result = this.computeResult(data);
this.emitEvent('criterionResultUpdated', {
result: data,
result: result,
error: null
})
}
normalizeData(datum) {
return {
[datum.key]: datum[datum.source]
findOperation(operation) {
for (let i=0, ii=OPERATIONS.length; i < ii; i++) {
if (operation === OPERATIONS[i].name) {
return OPERATIONS[i].operation;
}
}
return null;
}
computeResult(data) {
let comparator = this.findOperation(this.operation);
let params = [];
let result = false;
params.push(data[this.metaDataKey]);
if (this.input instanceof Array && this.input.length) {
params.push(this.input[0]);
}
if (typeof comparator === 'function') {
result = comparator(params);
}
return result;
}
emitEvent(eventName, data) {
@ -76,6 +97,7 @@ export default class TelemetryCriterion extends EventEmitter {
* Subscribes to the telemetry object and returns an unsubscribe function
*/
subscribe() {
this.unsubscribe();
this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => {
this.handleSubscription(datum);
});
@ -90,6 +112,10 @@ export default class TelemetryCriterion extends EventEmitter {
this.subscription();
}
delete this.subscription;
}
destroy() {
this.unsubscribe();
this.emitEvent('criterionRemoved');
delete this.telemetryObjectIdAsString;
delete this.telemetryObject;

View File

@ -94,17 +94,6 @@ describe("The telemetry criterion", function () {
expect(telemetryCriterion.subscription).toBeDefined();
});
it("normalizes telemetry data", function () {
let result = telemetryCriterion.normalizeData({
key: 'some-key',
source: 'testSource',
testSource: 'Hello'
});
expect(result).toEqual({
'some-key': 'Hello'
})
});
it("emits update event on new data from telemetry providers", function () {
spyOn(telemetryCriterion, 'emitEvent').and.callThrough();
telemetryCriterion.handleSubscription({
@ -119,7 +108,7 @@ describe("The telemetry criterion", function () {
it("un-subscribes from telemetry providers", function () {
telemetryCriterion.subscribe();
expect(telemetryCriterion.subscription).toBeDefined();
telemetryCriterion.unsubscribe();
telemetryCriterion.destroy();
expect(telemetryCriterion.subscription).toBeUndefined();
expect(telemetryCriterion.telemetryObjectIdAsString).toBeUndefined();
expect(telemetryCriterion.telemetryObject).toBeUndefined();

View File

View File

@ -42,6 +42,9 @@ export default function ConditionPlugin() {
creatable: true,
cssClass: 'icon-summary-widget', // TODO: replace with class for new icon
initialize: function (domainObject) {
domainObject.configuration = {
conditionCollection: []
};
domainObject.composition = [];
}
});

View File

@ -0,0 +1,4 @@
export const TRIGGER = {
ANY: 'any',
ALL: 'all'
};

View File

@ -0,0 +1,16 @@
export const computeCondition = (resultMap, allMustBeTrue) => {
let result = false;
for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) {
result = resultMap[key];
if (allMustBeTrue && !result) {
//If we want all conditions to be true, then even one negative result should break.
break;
} else if (!allMustBeTrue && result) {
//If we want at least one condition to be true, then even one positive result should break.
break;
}
}
}
return result;
};

View File

@ -0,0 +1,206 @@
export const OPERATIONS = [
{
name: 'equalTo',
operation: function (input) {
return input[0] === input[1];
},
text: 'is equal to',
appliesTo: ['number'],
inputCount: 1,
getDescription: function (values) {
return ' == ' + values[0];
}
},
{
name: 'notEqualTo',
operation: function (input) {
return input[0] !== input[1];
},
text: 'is not equal to',
appliesTo: ['number'],
inputCount: 1,
getDescription: function (values) {
return ' != ' + values[0];
}
},
{
name: 'greaterThan',
operation: function (input) {
return input[0] > input[1];
},
text: 'is greater than',
appliesTo: ['number'],
inputCount: 1,
getDescription: function (values) {
return ' > ' + values[0];
}
},
{
name: 'lessThan',
operation: function (input) {
return input[0] < input[1];
},
text: 'is less than',
appliesTo: ['number'],
inputCount: 1,
getDescription: function (values) {
return ' < ' + values[0];
}
},
{
name: 'greaterThanOrEq',
operation: function (input) {
return input[0] >= input[1];
},
text: 'is greater than or equal to',
appliesTo: ['number'],
inputCount: 1,
getDescription: function (values) {
return ' >= ' + values[0];
}
},
{
name: 'lessThanOrEq',
operation: function (input) {
return input[0] <= input[1];
},
text: 'is less than or equal to',
appliesTo: ['number'],
inputCount: 1,
getDescription: function (values) {
return ' <= ' + values[0];
}
},
{
name: 'between',
operation: function (input) {
return input[0] > input[1] && input[0] < input[2];
},
text: 'is between',
appliesTo: ['number'],
inputCount: 2,
getDescription: function (values) {
return ' between ' + values[0] + ' and ' + values[1];
}
},
{
name: 'notBetween',
operation: function (input) {
return input[0] < input[1] || input[0] > input[2];
},
text: 'is not between',
appliesTo: ['number'],
inputCount: 2,
getDescription: function (values) {
return ' not between ' + values[0] + ' and ' + values[1];
}
},
{
name: 'textContains',
operation: function (input) {
return input[0] && input[1] && input[0].includes(input[1]);
},
text: 'text contains',
appliesTo: ['string'],
inputCount: 1,
getDescription: function (values) {
return ' contains ' + values[0];
}
},
{
name: 'textDoesNotContain',
operation: function (input) {
return input[0] && input[1] && !input[0].includes(input[1]);
},
text: 'text does not contain',
appliesTo: ['string'],
inputCount: 1,
getDescription: function (values) {
return ' does not contain ' + values[0];
}
},
{
name: 'textStartsWith',
operation: function (input) {
return input[0].startsWith(input[1]);
},
text: 'text starts with',
appliesTo: ['string'],
inputCount: 1,
getDescription: function (values) {
return ' starts with ' + values[0];
}
},
{
name: 'textEndsWith',
operation: function (input) {
return input[0].endsWith(input[1]);
},
text: 'text ends with',
appliesTo: ['string'],
inputCount: 1,
getDescription: function (values) {
return ' ends with ' + values[0];
}
},
{
name: 'textIsExactly',
operation: function (input) {
return input[0] === input[1];
},
text: 'text is exactly',
appliesTo: ['string'],
inputCount: 1,
getDescription: function (values) {
return ' is exactly ' + values[0];
}
},
{
name: 'isUndefined',
operation: function (input) {
return typeof input[0] === 'undefined';
},
text: 'is undefined',
appliesTo: ['string', 'number', 'enum'],
inputCount: 0,
getDescription: function () {
return ' is undefined';
}
},
{
name: 'isDefined',
operation: function (input) {
return typeof input[0] !== 'undefined';
},
text: 'is defined',
appliesTo: ['string', 'number', 'enum'],
inputCount: 0,
getDescription: function () {
return ' is defined';
}
},
{
name: 'enumValueIs',
operation: function (input) {
return input[0] === input[1];
},
text: 'is',
appliesTo: ['enum'],
inputCount: 1,
getDescription: function (values) {
return ' == ' + values[0];
}
},
{
name: 'enumValueIsNot',
operation: function (input) {
return input[0] !== input[1];
},
text: 'is not',
appliesTo: ['enum'],
inputCount: 1,
getDescription: function (values) {
return ' != ' + values[0];
}
}
];