Allow to select multiple events

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-10-10 14:59:29 +02:00 committed by Arthur Schiwon
parent 7b82a09a3b
commit 6878d36e50
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 30 additions and 16 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div> <div class="event">
<div v-if="operation.isComplex && operation.fixedEntity !== ''" class="isComplex"> <div v-if="operation.isComplex && operation.fixedEntity !== ''" class="isComplex">
<img class="option__icon" :src="entity.icon"> <img class="option__icon" :src="entity.icon">
<span class="option__title option__title_single">{{ operation.triggerHint }}</span> <span class="option__title option__title_single">{{ operation.triggerHint }}</span>
@ -7,14 +7,16 @@
<Multiselect v-else <Multiselect v-else
:value="currentEvent" :value="currentEvent"
:options="allEvents" :options="allEvents"
label="eventName"
track-by="id" track-by="id"
:allow-empty="false" :multiple="true"
:auto-limit="false"
:disabled="allEvents.length <= 1" :disabled="allEvents.length <= 1"
@input="updateEvent"> @input="updateEvent">
<template slot="singleLabel" slot-scope="props"> <template slot="selection" slot-scope="{ values, search, isOpen }">
<img class="option__icon" :src="props.option.entity.icon"> <div v-if="values.length && !isOpen" class="eventlist">
<span class="option__title option__title_single">{{ props.option.displayName }}</span> <img class="option__icon" :src="values[0].entity.icon">
<span class="text option__title option__title_single" v-for="(value, index) in values">{{ value.displayName }} <span v-if="index+1 < values.length">, </span></span>
</div>
</template> </template>
<template slot="option" slot-scope="props"> <template slot="option" slot-scope="props">
<img class="option__icon" :src="props.option.entity.icon"> <img class="option__icon" :src="props.option.entity.icon">
@ -49,23 +51,22 @@ export default {
return this.$store.getters.getEventsForOperation(this.operation) return this.$store.getters.getEventsForOperation(this.operation)
}, },
currentEvent() { currentEvent() {
if (!this.rule.events) { return this.allEvents.filter(event => event.entity.id === this.rule.entity && this.rule.events.indexOf(event.eventName) !== -1)
return this.allEvents.length > 0 ? this.allEvents[0] : null
}
return this.allEvents.find(event => event.entity.id === this.rule.entity && this.rule.events.indexOf(event.eventName) !== -1)
} }
}, },
methods: { methods: {
updateEvent(event) { updateEvent(events) {
this.$set(this.rule, 'entity', event.entity.id) this.$set(this.rule, 'events', events.map(event => event.eventName))
this.$set(this.rule, 'events', [event.eventName]) this.$emit('update', this.rule)
this.$store.dispatch('updateRule', this.rule)
} }
} }
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.event {
margin-bottom: 5px;
}
.isComplex { .isComplex {
img { img {
vertical-align: top; vertical-align: top;
@ -78,6 +79,11 @@ export default {
display: inline-block; display: inline-block;
} }
} }
.multiselect {
width: 100%;
max-width: 550px;
margin-top: 4px;
}
.multiselect::v-deep .multiselect__single { .multiselect::v-deep .multiselect__single {
display: flex; display: flex;
} }
@ -86,8 +92,10 @@ export default {
border: 1px solid transparent; border: 1px solid transparent;
} }
.multiselect::v-deep .multiselect__tags .multiselect__single { .multiselect::v-deep .multiselect__tags {
background-color: var(--color-main-background) !important; background-color: var(--color-main-background) !important;
height: auto;
min-height: 34px;
} }
.multiselect:not(.multiselect--disabled)::v-deep .multiselect__tags .multiselect__single { .multiselect:not(.multiselect--disabled)::v-deep .multiselect__tags .multiselect__single {
@ -107,4 +115,9 @@ export default {
.option__title_single { .option__title_single {
font-weight: 900; font-weight: 900;
} }
.eventlist img,
.eventlist .text {
vertical-align: middle;
}
</style> </style>

View File

@ -63,7 +63,7 @@ export default {
h3 { h3 {
margin: 0; margin: 0;
padding: 0; padding: 0;
font-weight: 500; font-weight: 600;
} }
small { small {
font-size: 10pt; font-size: 10pt;
@ -82,6 +82,7 @@ export default {
.actions__item__description { .actions__item__description {
padding-top: 5px; padding-top: 5px;
text-align: left; text-align: left;
width: calc(100% - 105px);
small { small {
padding: 0; padding: 0;
} }