From f9ba46fe85c65b37ff934d5e54c787e40d55fc6c Mon Sep 17 00:00:00 2001 From: Joel McKinnon Date: Wed, 29 Jan 2020 12:45:34 -0800 Subject: [PATCH] added button and set up iteratable render of criteria --- .../components/ConditionCollection.vue | 149 ++++++++++++++---- .../condition/components/ConditionEdit.vue | 81 +++++++--- .../condition/components/condition-set.scss | 4 +- .../condition/components/condition.scss | 51 +++++- 4 files changed, 224 insertions(+), 61 deletions(-) diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index 7b28e0c6c7..bf221647da 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -28,27 +28,37 @@ Add Condition -
-
-
- +
    +
  • +
    +
    + +
    +
    + -
    -
    - -
    -
+ /> +
+ +
@@ -59,6 +69,7 @@ import Condition from '../../condition/components/Condition.vue'; import ConditionEdit from '../../condition/components/ConditionEdit.vue'; import uuid from 'uuid'; + export default { inject: ['openmct', 'domainObject'], components: { @@ -75,6 +86,7 @@ export default { conditionCollection: [], conditions: [], currentConditionIdentifier: this.currentConditionIdentifier || {}, + moveIndex: null, telemetryObjs: this.telemetryObjs }; }, @@ -97,6 +109,50 @@ export default { } }, methods: { + setMoveIndex(index) { + this.moveIndex = index; + }, + dropCondition(e) { + let targetIndex = Array.from(document.querySelectorAll('.c-c__drag-ghost')).indexOf(e.target); + if (targetIndex > this.moveIndex) { targetIndex-- } + 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 = []; + + for (let i = 0; i < oldIndexArr.length; i++) { + reorderPlan.push({oldIndex: Number(newIndexArr[i]), newIndex: i}); + } + + this.reorder(reorderPlan); + + e.target.classList.remove("dragging"); + }, + dragEnter(e) { + let targetIndex = Array.from(document.querySelectorAll('.c-c__drag-ghost')).indexOf(e.target); + + if (targetIndex > this.moveIndex) { targetIndex-- } + 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; @@ -127,34 +183,49 @@ export default { this.telemetryObjs.splice(index, 1); } }, - addCondition(event, isDefault) { - let conditionDO = this.getConditionDomainObject(!!isDefault); + /* + 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, definition, index) { + let conditionDO = this.getConditionDomainObject(!!isDefault, isClone, definition); //persist the condition DO 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(conditionDO, 'created', new Date()); - this.conditionCollection.unshift(conditionDO.identifier); + if (!isClone) { + this.conditionCollection.unshift(conditionDO.identifier); + } else { + this.conditionCollection.splice(index + 1, 0, conditionDO.identifier); + } this.persist(); }, updateCurrentCondition(identifier) { this.currentConditionIdentifier = identifier; }, - getConditionDomainObject(isDefault) { + getConditionDomainObject(isDefault, isClone, definition) { + const definitionTemplate = { + name: isDefault ? 'Default' : 'Unnamed Condition', + output: 'false', + trigger: 'any', + criteria: isDefault ? [] : [{ + operation: '', + input: '', + metaDataKey: '', + key: '' + }] + }; 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: '' - }] - }, + definition: isClone ? definition: definitionTemplate, summary: 'summary description' }; let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier); @@ -178,10 +249,17 @@ export default { this.updateCurrentConditionId(); }, reorder(reorderPlan) { - let oldConditions = this.conditionCollection.slice(); + let oldConditions = Array.from(this.conditionCollection); reorderPlan.forEach((reorderEvent) => { this.$set(this.conditionCollection, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]); }); + this.persist(); + }, + cloneCondition(condition) { + this.openmct.objects.get(condition.identifier).then((obj) => { + obj.definition.name = 'Copy of ' + obj.definition.name; + this.addCondition(null, false, true, obj.definition, condition.index); + }); }, persist() { this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.conditionCollection); @@ -189,3 +267,4 @@ export default { } } + diff --git a/src/plugins/condition/components/ConditionEdit.vue b/src/plugins/condition/components/ConditionEdit.vue index d4625aed5c..a5dc04ca3e 100644 --- a/src/plugins/condition/components/ConditionEdit.vue +++ b/src/plugins/condition/components/ConditionEdit.vue @@ -1,18 +1,21 @@