-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathRequestUserAgent.vue
More file actions
156 lines (138 loc) · 3.24 KB
/
Copy pathRequestUserAgent.vue
File metadata and controls
156 lines (138 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div>
<NcSelect
v-model="currentValue"
:placeholder="t('workflowengine', 'Select a user agent')"
label="label"
:options="options"
:clearable="false"
@input="setValue">
<template #option="option">
<span class="option__icon" :class="option.icon" />
<span class="option__title">
<NcEllipsisedOption :name="String(option.label)" />
</span>
</template>
<template #selected-option="selectedOption">
<span class="option__icon" :class="selectedOption.icon" />
<span class="option__title">
<NcEllipsisedOption :name="String(selectedOption.label)" />
</span>
</template>
</NcSelect>
<input
v-if="!isPredefined"
v-model="newValue"
type="text"
@input="updateCustom">
</div>
</template>
<script>
import NcEllipsisedOption from '@nextcloud/vue/components/NcEllipsisedOption'
import NcSelect from '@nextcloud/vue/components/NcSelect'
import valueMixin from '../../mixins/valueMixin.js'
export default {
name: 'RequestUserAgent',
components: {
NcEllipsisedOption,
NcSelect,
},
mixins: [
valueMixin,
],
props: {
modelValue: {
type: String,
default: '',
},
},
emits: ['update:model-value'],
data() {
return {
newValue: '',
predefinedTypes: [
{ id: 'android', label: t('workflowengine', 'Android client'), icon: 'icon-phone' },
{ id: 'ios', label: t('workflowengine', 'iOS client'), icon: 'icon-phone' },
{ id: 'desktop', label: t('workflowengine', 'Desktop client'), icon: 'icon-desktop' },
{ id: 'mail', label: t('workflowengine', 'Thunderbird & Outlook addons'), icon: 'icon-mail' },
],
}
},
computed: {
options() {
return [...this.predefinedTypes, this.customValue]
},
matchingPredefined() {
return this.predefinedTypes
.find((type) => this.newValue === type.id)
},
isPredefined() {
return !!this.matchingPredefined
},
customValue() {
return {
icon: 'icon-settings-dark',
label: t('workflowengine', 'Custom user agent'),
id: '',
}
},
currentValue: {
get() {
if (this.matchingPredefined) {
return this.matchingPredefined
}
return {
icon: 'icon-settings-dark',
label: t('workflowengine', 'Custom user agent'),
id: this.newValue,
}
},
set(value) {
this.newValue = value
},
},
},
methods: {
validateRegex(string) {
const regexRegex = /^\/(.*)\/([gui]{0,3})$/
const result = regexRegex.exec(string)
return result !== null
},
setValue(value) {
// TODO: check if value requires a regex and set the check operator according to that
if (value !== null) {
this.newValue = value.id
this.$emit('update:model-value', this.newValue)
}
},
updateCustom() {
this.newValue = this.currentValue.id
this.$emit('update:model-value', this.newValue)
},
},
}
</script>
<style scoped>
.v-select,
input[type='text'] {
width: 100%;
}
input[type='text'] {
min-height: 48px;
}
.option__icon {
display: inline-block;
min-width: 30px;
background-position: center;
vertical-align: middle;
}
.option__title {
display: inline-flex;
width: calc(100% - 36px);
vertical-align: middle;
}
</style>