add condition

This commit is contained in:
Joel McKinnon 2020-01-06 09:48:11 -08:00
parent cc8ba18ccc
commit c08e9a89ff
2 changed files with 59 additions and 12 deletions

View File

@ -23,19 +23,20 @@
v-show="isEditing" v-show="isEditing"
id="addCondition" id="addCondition"
class="c-cs-button c-cs-button--major add-condition-button" class="c-cs-button c-cs-button--major add-condition-button"
@click="addCondition"
> >
<span class="c-cs-button__label">Add Condition</span> <span class="c-cs-button__label">Add Condition</span>
</button> </button>
</div> </div>
<div v-if="isEditing"> <div v-for="condition in conditions" :key="condition.key">
<ConditionEdit /> <div v-if="isEditing">
<ConditionEdit :is-current="true" /> <ConditionEdit :domain-object="condition.domainObject"
<ConditionEdit :is-default="true" /> :isDefault="condition.isDefault" />
</div> </div>
<div v-else> <div v-else>
<Condition /> <Condition :domain-object="condition.domainObject"
<Condition :is-current="true" /> :isDefault="condition.isDefault" />
<Condition :is-default="true" /> </div>
</div> </div>
</div> </div>
</section> </section>
@ -46,7 +47,7 @@ import Condition from '../../condition/components/Condition.vue';
import ConditionEdit from '../../condition/components/ConditionEdit.vue'; import ConditionEdit from '../../condition/components/ConditionEdit.vue';
export default { export default {
inject: ['openmct'], inject: ['openmct', 'domainObject'],
components: { components: {
Condition, Condition,
ConditionEdit ConditionEdit
@ -56,10 +57,51 @@ export default {
}, },
data() { data() {
return { return {
expanded: true expanded: true,
conditions: [
{
identifier: {
key: 'testConditionKey',
namespace: ''
},
type: 'condition',
isDefault: true
}
]
}; };
}, },
destroyed() {
this.composition.off('add', this.addCondition);
this.composition.off('remove', this.removeCondition);
this.composition.off('reorder', this.reorder);
},
mounted() {
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.load();
},
methods: { methods: {
addCondition() {
let condition = {};
condition.domainObject = this.domainObject;
condition.key = this.openmct.objects.makeKeyString(this.domainObject.identifier);
this.conditions.unshift(condition);
},
removeCondition(identifier) {
console.log(`remove condition`);
let index = _.findIndex(this.conditions, (condition) => this.openmct.objects.makeKeyString(identifier) === item.key);
this.conditions.splice(index, 1);
},
reorder(reorderPlan) {
let oldConditions = this.conditions.slice();
reorderPlan.forEach((reorderEvent) => {
this.$set(this.conditions, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]);
});
}
} }
} }
</script> </script>

View File

@ -37,6 +37,7 @@
></span> ></span>
<span v-if="!isDefault" <span v-if="!isDefault"
class="is-enabled c-c__trash" class="is-enabled c-c__trash"
@click="removeCondition"
></span> ></span>
</div> </div>
<div v-if="expanded" <div v-if="expanded"
@ -84,11 +85,15 @@ export default {
}, },
data() { data() {
return { return {
conditionData: {}, conditions: {},
expanded: true expanded: true
}; };
}, },
methods: { methods: {
removeCondition() {
console.log(this);
// this.conditions.splice(index, 1);
}
} }
} }
</script> </script>