diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index fc52c2251a..cde15c22f9 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -69,6 +69,7 @@ :is-editing="isEditing" @updateCurrentCondition="updateCurrentCondition" @removeCondition="removeCondition" + @cloneCondition="cloneCondition" @conditionResultUpdated="handleConditionResult" @setMoveIndex="setMoveIndex" /> @@ -209,36 +210,52 @@ export default { this.telemetryObjs.splice(index, 1); } }, - addCondition(event, isDefault) { - let conditionDomainObject = this.createConditionDomainObject(!!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, 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', conditionDomainObject.created); - this.conditionCollection.unshift(conditionDomainObject.identifier); + 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) { this.currentConditionIdentifier = identifier; }, - createConditionDomainObject(isDefault) { + createConditionDomainObject(isDefault, isClone, configuration) { + const configurationTemplate = { + name: isDefault ? 'Default' : (isClone ? 'Copy of ' : '') + 'Unnamed Condition', + output: 'false', + trigger: 'any', + criteria: isDefault ? [] : [{ + telemetry: '', + operation: '', + input: '', + metadata: '', + key: '' + }] + }; let conditionObj = { isDefault: isDefault, type: 'condition', - name: isDefault ? 'Default' : 'Unnamed Condition', + name: isDefault ? 'Default' : (isClone ? 'Copy of ' : '') + 'Unnamed Condition', identifier: { namespace: this.domainObject.identifier.namespace, key: uuid() }, - configuration: { - name: isDefault ? 'Default' : 'Unnamed Condition', - output: 'false', - trigger: 'any', - criteria: isDefault ? [] : [{ - telemetry: '', - operation: '', - input: '', - metadata: '' - }] - }, + configuration: isClone ? configuration: configurationTemplate, summary: 'summary description', created: new Date() }; @@ -262,12 +279,18 @@ 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.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); } diff --git a/src/plugins/condition/components/ConditionEdit.vue b/src/plugins/condition/components/ConditionEdit.vue new file mode 100644 index 0000000000..60295d157f --- /dev/null +++ b/src/plugins/condition/components/ConditionEdit.vue @@ -0,0 +1,389 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + + + +