before Deep comments

This commit is contained in:
Joel McKinnon 2020-02-06 07:23:32 -08:00
parent fc03b3a79d
commit ec1d4abde9
3 changed files with 144 additions and 110 deletions

View File

@ -105,9 +105,10 @@ export default {
data() { data() {
return { return {
expanded: true, expanded: true,
telemetryObjs: this.telemetryObjs, telemetryObjs: [],
parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier), parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier),
conditionCollection: [], conditionCollection: [],
conditionResults: {},
conditions: [], conditions: [],
currentConditionIdentifier: this.currentConditionIdentifier || {}, currentConditionIdentifier: this.currentConditionIdentifier || {},
moveIndex: Number, moveIndex: Number,
@ -118,14 +119,12 @@ export default {
this.composition.off('add', this.addTelemetry); this.composition.off('add', this.addTelemetry);
}, },
mounted() { mounted() {
this.telemetryObjs = [];
this.conditionResults = {};
this.instantiate = this.openmct.$injector.get('instantiate'); 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.addTelemetry); this.composition.on('add', this.addTelemetry);
this.composition.on('remove', this.removeTelemetry); this.composition.on('remove', this.removeTelemetry);
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) { if (!this.conditionCollection.length) {
this.addCondition(null, true); this.addCondition(null, true);
} else { } else {
@ -186,10 +185,11 @@ export default {
}, },
updateCurrentConditionId() { updateCurrentConditionId() {
let currentConditionIdentifier = this.conditionCollection[this.conditionCollection.length-1]; let currentConditionIdentifier = this.conditionCollection[this.conditionCollection.length-1];
for (let i=0, ii = this.conditionCollection.length-1; i< ii; i++) { // for (let i=0, ii = this.conditionCollection.length-1; i< ii; i++) {
for (let i = 0; i < this.conditionCollection.length-1; i++) {
let conditionIdAsString = this.openmct.objects.makeKeyString(this.conditionCollection[i]); let conditionIdAsString = this.openmct.objects.makeKeyString(this.conditionCollection[i]);
if (this.conditionResults[conditionIdAsString]) { if (this.conditionResults[conditionIdAsString]) {
//first condition to be true wins // TODO: first condition to be true wins
currentConditionIdentifier = this.conditionCollection[i]; currentConditionIdentifier = this.conditionCollection[i];
break; break;
} }
@ -233,8 +233,11 @@ export default {
criteria: isDefault ? [] : [{ criteria: isDefault ? [] : [{
operation: '', operation: '',
input: '', input: '',
metaDataKey: this.openmct.telemetry.getMetadata(this.telemetryObjs[0]).values()[0].key, metaDataKey: '',
key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null, identifier: {
namespace: '',
key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null
}
}] }]
}, },
summary: 'summary description' summary: 'summary description'
@ -245,7 +248,6 @@ export default {
return newDomainObject.useCapability('adapter'); return newDomainObject.useCapability('adapter');
}, },
updateCondition(updatedCondition) { updateCondition(updatedCondition) {
//TODO: this should only happen for reordering
let index = _.findIndex(this.conditions, (condition) => condition.id === updatedCondition.id); let index = _.findIndex(this.conditions, (condition) => condition.id === updatedCondition.id);
this.conditions[index] = updatedCondition; this.conditions[index] = updatedCondition;
}, },

View File

@ -44,7 +44,7 @@
<label>Condition Name</label> <label>Condition Name</label>
<span class="controls"> <span class="controls">
<input v-model="condition.definition.name" <input v-model="condition.definition.name"
class="t-condition-name-input" class="t-condition-input__name"
type="text" type="text"
> >
</span> </span>
@ -57,15 +57,15 @@
> >
<option value="">- Select Output -</option> <option value="">- Select Output -</option>
<option v-for="option in outputOptions" <option v-for="option in outputOptions"
:key="option.key" :key="option"
:value="option.key" :value="option"
> >
{{ option.text }} {{ option }}
</option> </option>
</select> </select>
<input v-if="selectedOutputKey === outputOptions[2].key" <input v-if="selectedOutputKey === outputOptions[2]"
v-model="condition.definition.output" v-model="condition.definition.output"
class="t-condition-name-input" class="t-condition-input__output"
type="text" type="text"
> >
</span> </span>
@ -88,17 +88,17 @@
<ul v-if="telemetry.length" <ul v-if="telemetry.length"
class="t-widget-condition-config"> class="t-widget-condition-config">
<li v-for="(criteria, index) in condition.definition.criteria" <li v-for="(criteria, index) in condition.definition.criteria"
:key="criteria.key.key" :key="criteria.identifier.key"
class="has-local-controls t-condition" class="has-local-controls t-condition"
> >
<label>{{ index === 0 ? 'when' : 'and when' }}</label> <label>{{ index === 0 ? 'when' : 'and when' }}</label>
<span class="t-configuration"> <span class="t-configuration">
<span class="controls"> <span class="controls">
<select v-model="selectedTelemetryKey[currentCriteria.key]" <select v-model="selectedTelemetryKey"
@change="updateTelemetryMetaData" @change="updateTelemetryOptions"
> >
<option value="">- Select Telemetry -</option> <option value="">- Select Telemetry -</option>
<option v-for="telemetryOption in telemetry" <option v-for="telemetryOption in telemetryObj"
:key="telemetryOption.identifier.key" :key="telemetryOption.identifier.key"
:value="telemetryOption.identifier" :value="telemetryOption.identifier"
> >
@ -107,9 +107,9 @@
</select> </select>
</span> </span>
<span class="controls"> <span class="controls">
<select v-model="selectedMetaDataKey[currentCriteria.key]"> <select @change="updateFieldOptions">
<option value="">- Select Field -</option> <option value="">- Select Field -</option>
<option v-for="option in telemetryMetadata" <option v-for="option in telemetryMetadata[currentCriteria.identifier]"
:key="option.key" :key="option.key"
:value="option.key" :value="option.key"
> >
@ -118,9 +118,7 @@
</select> </select>
</span> </span>
<span class="controls"> <span class="controls">
<select v-model="selectOperationName" <select @change="updateComparisonOptions">
@change="setInputValueVisibility"
>
<option value="">- Select Comparison -</option> <option value="">- Select Comparison -</option>
<option v-for="option in operations" <option v-for="option in operations"
:key="option.name" :key="option.name"
@ -129,9 +127,7 @@
{{ option.text }} {{ option.text }}
</option> </option>
</select> </select>
<input v-if="comparisonValueField" <input class="t-condition-name-input"
v-model="operationValue[currentCriteria.key]"
class="t-condition-name-input"
type="text" type="text"
> >
</span> </span>
@ -188,31 +184,30 @@ export default {
currentCriteria: this.currentCriteria, currentCriteria: this.currentCriteria,
expanded: true, expanded: true,
trigger: 'any', trigger: 'any',
telemetryObject: this.telemetryObject, telemetryObj: this.telemetry,
telemetryMetadata: this.telemetryMetadata, telemetryMetadata: {},
operations: OPERATIONS, operations: OPERATIONS,
selectedMetaDataKey: '', selectedMetadataKey: {},
selectedTelemetryKey: '', selectedTelemetryKey: {},
selectOperationName: '', selectedOperationName: {},
operationValue: {},
selectedOutputKey: '', selectedOutputKey: '',
stringOutputField: false, stringOutputField: {},
comparisonValueField: false, comparisonInputValue: {},
operationValue: this.operationValue, outputOptions: ['false', 'true', 'string']
outputOptions: [ // {
{ // key: 'false',
key: 'false', // text: 'False'
text: 'False' // },
}, // {
{ // key: 'true',
key: 'true', // text: 'True'
text: 'True' // },
}, // {
{ // key: 'string',
key: 'string', // text: 'String'
text: 'String' // }
} // ]
]
}; };
}, },
destroyed() { destroyed() {
@ -234,12 +229,14 @@ export default {
const criteriaObject = { const criteriaObject = {
operation: '', operation: '',
input: '', input: '',
metaDataKey: '', metadataKey: '',
key: { key: {
namespace: '', namespace: '',
key: uuid() key: uuid()
} }
} }
this.selectedOperationName[this.currentCriteria.identifier] = undefined;
// this.comparisonValueField[this.currentCriteria.identifier] = false;
this.condition.definition.criteria.push(criteriaObject); this.condition.definition.criteria.push(criteriaObject);
}, },
dragStart(e) { dragStart(e) {
@ -247,11 +244,10 @@ export default {
}, },
initialize() { initialize() {
if (this.condition.definition.criteria.length) { if (this.condition.definition.criteria.length) {
console.log('initialize found criteria')
this.setCurrentCriterion(0); this.setCurrentCriterion(0);
this.setOutput(); this.setOutput();
this.updateTelemetryKeys();
this.setOperation(); this.setOperation();
this.updateTelemetry();
this.conditionClass = new ConditionClass(this.condition, this.openmct); this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this)); this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
} }
@ -260,14 +256,14 @@ export default {
this.currentCriteria = this.condition.definition.criteria[index]; this.currentCriteria = this.condition.definition.criteria[index];
}, },
destroy() { destroy() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this)); // this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') { // if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
this.conditionClass.destroy(); // this.conditionClass.destroy();
delete this.conditionClass; // delete this.conditionClass;
} // }
}, },
reset() { reset() {
this.selectedMetaDataKey = {}; this.selectedMetadataKey = {};
this.selectedTelemetryKey = {}; this.selectedTelemetryKey = {};
this.selectedOperationKey = {}; this.selectedOperationKey = {};
this.operationValue = {}; this.operationValue = {};
@ -297,84 +293,88 @@ export default {
}); });
}, },
setOutput() { setOutput() {
console.log('this.condition.definition.output', this.condition.definition.output === '');
let conditionOutput = this.condition.definition.output; let conditionOutput = this.condition.definition.output;
if (conditionOutput !== 'false' && conditionOutput !== 'true') {
this.selectedOutputKey = this.outputOptions[2].key; if (!conditionOutput) {
} else { if (conditionOutput !== 'false' && conditionOutput !== 'true') {
if (conditionOutput === 'true') { this.selectedOutputKey = this.outputOptions[2].key;
this.selectedOutputKey = this.outputOptions[1].key;
} else { } else {
this.selectedOutputKey = this.outputOptions[0].key; if (conditionOutput === 'true') {
this.selectedOutputKey = this.outputOptions[1].key;
} else {
this.selectedOutputKey = this.outputOptions[0].key;
}
} }
this.persist(); // maybe not needed
} }
}, },
setOperation() { setOperation() {
if (this.currentCriteria && this.currentCriteria.operation) { if (this.selectedOperationName[this.currentCriteria.identifier] !== undefined) {
for (let i=0, ii=this.operations.length; i < ii; i++) { if (this.operationValue[this.currentCriteria.identifier] !== undefined) {
if (this.currentCriteria.operation === this.operations[i].name) { for (let i=0, ii=this.operations.length; i < ii; i++) {
this.selectedOperationKey[this.currentCriteria.key] = this.operations[i].name; if (this.currentCriteria.operation === this.operations[i].name) {
this.comparisonValueField[this.currentCriteria.key] = this.operations[i].inputCount > 0; this.selectedOperationName[this.currentCriteria.identifier] = this.operations[i].name;
if (this.comparisonValueField[this.currentCriteria.key]) {
this.operationValue[this.currentCriteria.key] = this.currentCriteria.input[0]; this.comparisonInputValue[this.currentCriteria.identifier] = this.operations[i].inputCount > 0;
if (this.comparisonInputValue[this.currentCriteria.identifier]) {
this.operationValue[this.currentCriteria.identifier] = this.currentCriteria.input[0];
}
} }
} }
} }
} }
}, },
updateTelemetry() { updateTelemetryKeys() {
console.log('this.currentCriteria', this.currentCriteria); console.log('updateTelemetryKeys')
if (this.hasTelemetry()) { if (this.hasTelemetry()) {
console.log('this.currentCriteria.key', this.currentCriteria.key); this.openmct.objects.get(this.currentCriteria.identifier).then((obj) => {
this.openmct.objects.get(this.currentCriteria.key).then((obj) => { this.telemetryMetadata[this.currentCriteria.identifier] = this.openmct.telemetry.getMetadata(obj).values();
console.log('this.telemetryObject', this.telemetryObject); this.selectedMetadataKey[this.currentCriteria.identifier] = this.getTelemetryMetadataKey();
this.telemetryObject = obj; this.selectedTelemetryKey[this.currentCriteria.identifier] = this.getTelemetryKey();
this.telemetryMetadata[this.currentCriteria.key] = this.openmct.telemetry.getMetadata(this.telemetryObject).values(); console.log('this.telemetryMetadata[this.currentCriteria.identifier]', this.telemetryMetadata[this.currentCriteria.identifier])
this.selectedMetaDataKey[this.currentCriteria.key] = this.getTelemetryMetadataKey(); console.log('this.selectedMetadataKey[this.currentCriteria.identifier]', this.selectedMetadataKey[this.currentCriteria.identifier])
this.selectedTelemetryKey[this.currentCriteria.key] = this.getTelemetryKey(); console.log('this.selectedTelemetryKey[this.currentCriteria.identifier]', this.selectedTelemetryKey[this.currentCriteria.identifier])
}); });
} }
}, },
getTelemetryMetadataKey() { getTelemetryMetadataKey() {
// console.log('this.telemetryMetadata[this.currentCriteria.identifier]', this.telemetryMetadata[this.currentCriteria.identifier]);
let index = -1; let index = -1;
if (this.currentCriteria.metaDataKey) { if (this.currentCriteria.identifier) {
index = _.findIndex(this.telemetryMetadata, (metadata) => { index = _.findIndex(this.telemetryMetadata[this.currentCriteria.identifier], (metadata) => {
return metadata.key === this.currentCriteria.metaDataKey; return metadata.key === this.currentCriteria.metadataKey;
}); });
} }
return this.telemetryMetadata.length && index > -1 ? this.telemetryMetadata[index].key : ''; return this.telemetryMetadata[this.currentCriteria.identifier].length && index > -1 ? this.telemetryMetadata[this.currentCriteria.identifier][index].key : '- Select Telemetry -';
}, },
getTelemetryKey() { getTelemetryKey() {
let index = -1; let index = -1;
if (this.currentCriteria) { if (this.currentCriteria && this.currentCriteria.identifier) {
if (this.currentCriteria.key) { let conditionKey = this.openmct.objects.makeKeyString(this.currentCriteria.identifier);
index = _.findIndex(this.telemetry, (obj) => { index = _.findIndex(this.telemetry, (obj) => {
let key = this.openmct.objects.makeKeyString(obj.identifier)
let key = this.openmct.objects.makeKeyString(obj.identifier); return key === conditionKey
let conditionKey = this.openmct.objects.makeKeyString(this.currentCriteria.key); });
return key === conditionKey;
});
}
} }
return this.telemetry.length && index > -1 ? this.telemetry[index].identifier : ''; console.log('index', index, 'this.telemetry[index]', this.telemetry[index]);
return this.telemetry.length && index > -1 ? this.telemetry[index] : '';
}, },
hasTelemetry() { hasTelemetry() {
if (this.currentCriteria && this.currentCriteria.key) { // console.log('this.domainObject.composition', this.domainObject.composition);
console.log('hasTelemetry() returns true'); return this.currentCriteria && this.currentCriteria.identifier;
}
// console.log('this.currentCriteria', this.currentCriteria);
return this.currentCriteria && this.currentCriteria.key;
}, },
updateConditionCriteria() { updateConditionCriteria() {
if (this.condition.definition.criteria.length) { if (this.condition.definition.criteria.length) {
let criterion = this.condition.definition.criteria[0]; let criterion = this.condition.definition.criteria[0];
criterion.key = this.selectedTelemetryKey; criterion.key = this.selectedTelemetryKey[this.currentCriteria.identifier];
criterion.metaDataKey = this.selectedMetaDataKey; criterion.metadataKey = this.selectedMetadataKey[this.currentCriteria.identifier];
criterion.operation = this.selectOperationName; criterion.operation = this.selectedOperationName[this.currentCriteria.identifier];
criterion.input = [this.operationValue]; criterion.input = this.operationValue;
} }
}, },
persist() { persist() {
this.updateConditionCriteria(); // this.updateConditionCriteria();
this.openmct.objects.mutate(this.condition, 'definition', this.condition.definition); this.openmct.objects.mutate(this.condition, 'definition', this.condition.definition);
}, },
checkInputValue() { checkInputValue() {
@ -393,11 +393,40 @@ export default {
} }
//find the criterion being updated and set the operation property //find the criterion being updated and set the operation property
}, },
updateTelemetryMetaData() { updateOutputOption(ev) {
this.selectedMetaDataKey = {}; if (this.selectedOutputKey === this.outputOptions[2].key) {
this.updateConditionCriteria(); this.condition.definition.output = '';
this.updateTelemetry(); } else {
this.condition.definition.output = this.selectedOutputKey;
}
}, },
// I'm thinking the update select options handlers should call different functions
updateTelemetryOptions() {
this.updateConditionCriteria();
this.updateTelemetryKeys();
},
updateFieldOptions() {
this.updateConditionCriteria();
this.updateTelemetryKeys();
},
updateComparisonOptions(ev) {
if (ev.target.value !== undefined) {
this.operationValue[this.currentCriteria.identifier] = ev.target.value;
// for (let i = 0, ii = this.operations.length; i < ii; i++) {
// // console.log('this.selectedOperationName[this.currentCriteria.identifier]', this.selectedOperationName[this.currentCriteria.identifier])
// // console.log('this.operations[i].name', this.operations[i].name)
// if (this.selectedOperationName[this.currentCriteria.identifier] === this.operations[i].name) {
// // console.log('this.operations[i].inputCount', this.operations[i].inputCount);
// //this.comparisonValueField[this.currentCriteria.identifier] = this.operations[i].inputCount > 0;
// console.log('this.comparisonValueField[this.currentCriteria.identifier]', this.comparisonValueField[this.currentCriteria.identifier]);
// break;
// }
// }
} else {
this.operationValue[this.currentCriteria.identifier] = undefined;
}
},
updateCurrentCondition() { updateCurrentCondition() {
this.$emit('updateCurrentCondition', this.conditionIdentifier); this.$emit('updateCurrentCondition', this.conditionIdentifier);
} }
@ -405,3 +434,4 @@ export default {
} }
</script> </script>

View File

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