From 6878d36e501801daa736a97a3b0137083272bc84 Mon Sep 17 00:00:00 2001
From: Julius Härtl <jus@bitgrid.net>
Date: Thu, 10 Oct 2019 14:59:29 +0200
Subject: Allow to select multiple events
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Julius Härtl <jus@bitgrid.net>
---
 apps/workflowengine/src/components/Event.vue | 43 ++++++++++++++++++----------
 1 file changed, 28 insertions(+), 15 deletions(-)

(limited to 'apps/workflowengine/src/components/Event.vue')

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


From fce33f39d3a5459ac98662c799ad4eee41fa98bf Mon Sep 17 00:00:00 2001
From: Julius Härtl <jus@bitgrid.net>
Date: Fri, 11 Oct 2019 15:05:58 +0200
Subject: Fix operation list when scope is limited
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Julius Härtl <jus@bitgrid.net>
---
 apps/workflowengine/src/components/Checks/FileMimeType.vue | 4 ++--
 apps/workflowengine/src/components/Checks/RequestTime.vue  | 8 ++++++--
 apps/workflowengine/src/components/Event.vue               | 2 +-
 apps/workflowengine/src/helpers/validators.js              | 9 +++------
 apps/workflowengine/src/store.js                           | 4 +++-
 5 files changed, 15 insertions(+), 12 deletions(-)

(limited to 'apps/workflowengine/src/components/Event.vue')

diff --git a/apps/workflowengine/src/components/Checks/FileMimeType.vue b/apps/workflowengine/src/components/Checks/FileMimeType.vue
index 862c4a42011..e91636f5130 100644
--- a/apps/workflowengine/src/components/Checks/FileMimeType.vue
+++ b/apps/workflowengine/src/components/Checks/FileMimeType.vue
@@ -33,12 +33,12 @@
 			@input="setValue">
 			<template slot="singleLabel" slot-scope="props">
 				<span v-if="props.option.icon" class="option__icon" :class="props.option.icon" />
-				<img v-else :src="props.option.iconUrl" />
+				<img v-else :src="props.option.iconUrl">
 				<span class="option__title option__title_single">{{ props.option.label }}</span>
 			</template>
 			<template slot="option" slot-scope="props">
 				<span v-if="props.option.icon" class="option__icon" :class="props.option.icon" />
-				<img v-else :src="props.option.iconUrl" />
+				<img v-else :src="props.option.iconUrl">
 				<span class="option__title">{{ props.option.label }}</span>
 			</template>
 		</Multiselect>
diff --git a/apps/workflowengine/src/components/Checks/RequestTime.vue b/apps/workflowengine/src/components/Checks/RequestTime.vue
index cd702ecae82..196f3e2afa4 100644
--- a/apps/workflowengine/src/components/Checks/RequestTime.vue
+++ b/apps/workflowengine/src/components/Checks/RequestTime.vue
@@ -10,7 +10,9 @@
 			type="text"
 			placeholder="e.g. 18:00"
 			@input="update">
-		<p v-if="!valid" class="invalid-hint">{{ t('workflowengine', 'Please enter a valid time span')}}</p>
+		<p v-if="!valid" class="invalid-hint">
+			{{ t('workflowengine', 'Please enter a valid time span') }}
+		</p>
 	</div>
 </template>
 
@@ -56,7 +58,9 @@ export default {
 						timezone: data[0].split(' ', 2)[1]
 					}
 				}
-			} catch (e) {}
+			} catch (e) {
+				// ignore invalid values
+			}
 		},
 		validate() {
 			return this.newValue.startTime && this.newValue.startTime.match(/^(0[0-9]|1[0-9]|2[0-3]|[0-9]):[0-5][0-9]$/i) !== null
diff --git a/apps/workflowengine/src/components/Event.vue b/apps/workflowengine/src/components/Event.vue
index 1afdfa80be7..97608fde062 100644
--- a/apps/workflowengine/src/components/Event.vue
+++ b/apps/workflowengine/src/components/Event.vue
@@ -15,7 +15,7 @@
 			<template slot="selection" slot-scope="{ values, search, isOpen }">
 				<div v-if="values.length && !isOpen" class="eventlist">
 					<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>
+					<span v-for="(value, index) in values" :key="value.id" class="text option__title option__title_single">{{ value.displayName }} <span v-if="index+1 < values.length">, </span></span>
 				</div>
 			</template>
 			<template slot="option" slot-scope="props">
diff --git a/apps/workflowengine/src/helpers/validators.js b/apps/workflowengine/src/helpers/validators.js
index 4936b9200f7..d64adfa1385 100644
--- a/apps/workflowengine/src/helpers/validators.js
+++ b/apps/workflowengine/src/helpers/validators.js
@@ -27,24 +27,21 @@ const validateRegex = function(string) {
 	if (!string) {
 		return false
 	}
-	const result = regexRegex.exec(string)
-	return result !== null
+	return regexRegex.exec(string) !== null
 }
 
 const validateIPv4 = function(string) {
 	if (!string) {
 		return false
 	}
-	const result = regexIPv4.exec(string)
-	return result !== null
+	return regexIPv4.exec(string) !== null
 }
 
 const validateIPv6 = function(string) {
 	if (!string) {
 		return false
 	}
-	const result = regexIPv6.exec(string)
-	return result !== null
+	return regexIPv6.exec(string) !== null
 }
 
 const stringValidator = (check) => {
diff --git a/apps/workflowengine/src/store.js b/apps/workflowengine/src/store.js
index cbd9b29c81c..a18540f8035 100644
--- a/apps/workflowengine/src/store.js
+++ b/apps/workflowengine/src/store.js
@@ -71,7 +71,9 @@ const store = new Vuex.Store({
 			plugin = Object.assign(
 				{ color: 'var(--color-primary-element)' },
 				plugin, state.operations[plugin.id] || {})
-			Vue.set(state.operations, plugin.id, plugin)
+			if (typeof state.operations[plugin.id] !== 'undefined') {
+				Vue.set(state.operations, plugin.id, plugin)
+			}
 		}
 	},
 	actions: {
-- 
cgit v1.2.3

