@@ -18,6 +18,7 @@ limitations under the License.
18
18
<div class="d-flex flex-row">
19
19
<v-select
20
20
class="selectClass"
21
+ :class="selectClass"
21
22
color="cyan darken-2"
22
23
item-color="cyan darken-2"
23
24
:label="wildcardSelectLabel"
@@ -30,12 +31,21 @@ limitations under the License.
30
31
:hint="wildcardSelectHint"
31
32
persistent-hint
32
33
>
34
+ <template v-slot:selection="{ item }">
35
+ <span v-if="item.customWildcard"><Custom></span>
36
+ <span v-else>{{item.value}}</span>
37
+ </template>
33
38
<template v-slot:item="{ item }">
34
39
<v-list-item-content>
35
40
<v-list-item-title>
36
- <span v-if="item.startsWithWildcard"><prefix></span>
37
- <span>{{item.value}}</span>
38
- <span v-if="item.endsWithWildcard"><suffix></span>
41
+ <template v-if="item.value.length">
42
+ <span v-if="item.startsWithWildcard"><prefix></span>
43
+ <span>{{item.value}}</span>
44
+ <span v-if="item.endsWithWildcard"><suffix></span>
45
+ </template>
46
+ <template v-else>
47
+ <span v-if="item.isWildcard">Custom {{wildcardSelectLabel}}</span>
48
+ </template>
39
49
</v-list-item-title>
40
50
</v-list-item-content>
41
51
</template>
@@ -108,41 +118,63 @@ export default {
108
118
textFieldClass () {
109
119
return this.wildcardSelectedValue.startsWithWildcard ? 'textFieldStartClass' : 'textFieldEndClass'
110
120
},
121
+ selectClass () {
122
+ if (this.wildcardSelectedValue.customWildcard) {
123
+ return 'selectSmallClass'
124
+ }
125
+ return undefined
126
+ },
111
127
wildcardSelectItemObjects () {
112
128
return map(this.wildcardSelectItems, item => {
113
129
let startsWithWildcard = false
114
130
let endsWithWildcard = false
131
+ let customWildcard = false
115
132
const value = trim(item, '*')
116
133
let pattern = value
117
134
118
- if (startsWith(item, '*')) {
135
+ if (item === '*') {
136
+ customWildcard = true
137
+ pattern = '.*'
138
+ } else if (startsWith(item, '*')) {
119
139
startsWithWildcard = true
120
- pattern = '.+' + pattern
121
- }
122
- if (endsWith(item, '*')) {
140
+ pattern = '.*' + pattern
141
+ } else if (endsWith(item, '*')) {
123
142
endsWithWildcard = true
124
- pattern = pattern + '.+ '
143
+ pattern = pattern + '.* '
125
144
}
126
145
127
146
return {
128
- text: value,
129
147
value,
130
148
startsWithWildcard,
131
149
endsWithWildcard,
132
- isWildcard: startsWithWildcard || endsWithWildcard,
150
+ customWildcard,
151
+ isWildcard: startsWithWildcard || endsWithWildcard || customWildcard,
133
152
regex: new RegExp('^' + pattern + '$')
134
153
}
135
154
})
136
155
},
137
156
wildcardTextFieldLabel () {
138
- return this.wildcardSelectedValue.startsWithWildcard ? 'Prefix' : 'Suffix'
157
+ if (this.wildcardSelectedValue.startsWithWildcard) {
158
+ return 'Prefix'
159
+ }
160
+ if (this.wildcardSelectedValue.endsWithWildcard) {
161
+ return 'Suffix'
162
+ }
163
+ if (this.wildcardSelectedValue.customWildcard) {
164
+ return `Custom ${this.wildcardSelectLabel}`
165
+ }
166
+ return undefined
139
167
},
140
168
wildcardSelectHint () {
141
169
if (!this.wildcardSelectedValue.isWildcard) {
142
170
return undefined
143
171
}
144
- const label = this.wildcardSelectedValue.startsWithWildcard ? 'prefix' : 'suffix'
145
- return `Selected wildcard value requires a ${label} which needs to be specified`
172
+ if (this.wildcardSelectedValue.customWildcard) {
173
+ return `Specify custom ${this.wildcardSelectLabel}`
174
+ } else {
175
+ const label = this.wildcardSelectedValue.startsWithWildcard ? 'prefix' : 'suffix'
176
+ return `Selected wildcard value requires a ${label} which needs to be specified`
177
+ }
146
178
},
147
179
internalValue () {
148
180
if (this.wildcardSelectedValue.startsWithWildcard) {
@@ -151,6 +183,9 @@ export default {
151
183
if (this.wildcardSelectedValue.endsWithWildcard) {
152
184
return `${this.wildcardSelectedValue.value}${this.wildcardVariablePart}`
153
185
}
186
+ if (this.wildcardSelectedValue.customWildcard) {
187
+ return this.wildcardVariablePart
188
+ }
154
189
return this.wildcardSelectedValue.value
155
190
}
156
191
},
@@ -174,6 +209,21 @@ export default {
174
209
matches.sort(function (a, b) {
175
210
return b.value.length - a.value.length
176
211
})
212
+ matches.sort(function (a, b) {
213
+ if (a.isWildcard && !b.isWildcard) {
214
+ return 1
215
+ }
216
+ if (b.isWildcard && !a.isWildcard) {
217
+ return -1
218
+ }
219
+ if (a.customWildcard && !b.customWildcard) {
220
+ return 1
221
+ }
222
+ if (b.customWildcard && !a.customWildcard) {
223
+ return -1
224
+ }
225
+ return 0
226
+ })
177
227
178
228
const bestMatch = head(matches)
179
229
if (!bestMatch) {
@@ -215,4 +265,7 @@ export default {
215
265
order: 2;
216
266
margin-left: 5px;
217
267
}
268
+ .selectSmallClass {
269
+ max-width: 120px;
270
+ }
218
271
</style>
0 commit comments