This repository was archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathml-facet-suggestions.vue
executable file
·79 lines (76 loc) · 1.92 KB
/
ml-facet-suggestions.vue
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
<template>
<div class="facet-list-suggestion">
<multiselect v-if="suggestions.length && (current.length || (suggestions.length > facet.facetValues.length))"
:v-model="selected"
:options="suggestions"
:multiple="false"
:searchable="true"
:customLabel="nameWithCount"
placeholder="Search more.."
label="name"
track-by="name"
open-direction="bottom"
v-on:search-change="getSuggestions"
v-on:select="onSelected"
>
</multiselect>
</div>
</template>
<script>
import Multiselect from 'vue-multiselect';
import Vue from 'vue';
export default {
name: 'ml-facet-suggestions',
components: {
Multiselect
},
props: {
facet: {
type: Object,
required: true
},
toggle: {
type: Function,
required: true
},
suggest: {
type: Function,
reqiured: true
}
},
data() {
return {
current: '',
selected: null,
suggestions: []
};
},
created() {
this.getSuggestions('');
},
methods: {
onSelected(option) {
this.selected = option;
this.toggle(this.facet.name, this.facet.type, option.name)
.then(() => this.getSuggestions(''));
},
getSuggestions(current) {
var self = this;
this.current = current;
this.suggest(this.facet.name, current)
.then(suggestions => {
if (suggestions.length) {
self.suggestions = suggestions;
} else {
self.suggestions = [{ name: current + '* (no match)'}];
}
});
},
nameWithCount(option) {
return '' + option.name + ' ' + (option.count?'('+option.count+')':'');
},
}
};
</script>
<style lang="less" scoped>
</style>