initial TreeSearch component
This commit is contained in:
@ -1,22 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<b-input-group class="mt-2">
|
<b-input-group class="mt-2">
|
||||||
<treeselect
|
<treeselect
|
||||||
v-model="settings.search_keywords"
|
v-model="selected1"
|
||||||
:options="facets.Keywords"
|
:options="options"
|
||||||
:load-options="loadChildren"
|
:load-options="loadChildren"
|
||||||
:multiple="true"
|
:multiple="true"
|
||||||
:flat="true"
|
:flat="true"
|
||||||
:auto-load-root-options="false"
|
:auto-load-root-options="false"
|
||||||
searchNested
|
searchNested
|
||||||
:placeholder="$t('Keywords')"
|
:placeholder="placeholder"
|
||||||
:normalizer="normalizer"
|
:normalizer="normalizer"
|
||||||
@input="refreshData(false)"
|
@input="change"
|
||||||
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
|
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
|
||||||
/>
|
/>
|
||||||
<b-input-group-append>
|
<b-input-group-append>
|
||||||
<b-input-group-text>
|
<b-input-group-text>
|
||||||
<b-form-checkbox v-model="settings.search_keywords_or" name="check-button" @change="refreshData(false)" class="shadow-none" switch size="sm">
|
<b-form-checkbox v-model="or1" name="check-button" @change="orChange()" class="shadow-none" switch>
|
||||||
<span class="text-uppercase" v-if="settings.search_keywords_or">{{ $t("or") }}</span>
|
<span class="text-uppercase" v-if="or1">{{ $t("or") }}</span>
|
||||||
<span class="text-uppercase" v-else>{{ $t("and") }}</span>
|
<span class="text-uppercase" v-else>{{ $t("and") }}</span>
|
||||||
</b-form-checkbox>
|
</b-form-checkbox>
|
||||||
</b-input-group-text>
|
</b-input-group-text>
|
||||||
@ -25,31 +25,65 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { ApiMixin } from "@/utils/utils"
|
||||||
import { Treeselect, LOAD_CHILDREN_OPTIONS } from "@riophae/vue-treeselect"
|
import { Treeselect, LOAD_CHILDREN_OPTIONS } from "@riophae/vue-treeselect"
|
||||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
|
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "AdvancedTreeSelect",
|
name: "AdvancedTreeSelect",
|
||||||
props: {
|
props: {
|
||||||
selected: { type: Array },
|
initial_selected1: { type: Array },
|
||||||
|
initial_selected2: { type: Array },
|
||||||
|
initial_selected3: { type: Array },
|
||||||
|
placeholder: { type: String, default: "You forgot to set placeholder" },
|
||||||
|
options: { type: Array },
|
||||||
|
facet: { type: String, default: undefined },
|
||||||
},
|
},
|
||||||
components: { Treeselect },
|
components: { Treeselect },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
shopping: false,
|
selected1: [],
|
||||||
|
selected2: [],
|
||||||
|
selected3: [],
|
||||||
|
callbacks: [],
|
||||||
|
or1: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {},
|
mounted() {},
|
||||||
computed: {},
|
computed: {},
|
||||||
watch: {},
|
watch: {
|
||||||
|
selected1: function (newVal, oldVal) {
|
||||||
|
console.log("test", newVal)
|
||||||
|
this.$emit("change", newVal)
|
||||||
|
},
|
||||||
|
options: function () {
|
||||||
|
this.callbacks.forEach((callback) => {
|
||||||
|
callback()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadChildren: function ({ action, parentNode, callback }) {
|
loadChildren: function ({ action, parentNode, callback }) {
|
||||||
if (action === LOAD_CHILDREN_OPTIONS) {
|
if (action === LOAD_CHILDREN_OPTIONS) {
|
||||||
if (this.facets?.cache_key) {
|
this.callbacks.push(callback)
|
||||||
this.getFacets(this.facets.cache_key, "keyword", parentNode.id).then(callback())
|
this.$emit("load-children", { type: "keyword", parent: parentNode.id })
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
normalizer(node) {
|
||||||
|
let count = node?.count ? " (" + node.count + ")" : ""
|
||||||
|
return {
|
||||||
|
id: node.id,
|
||||||
|
label: node.name + count,
|
||||||
|
children: node.children,
|
||||||
|
isDefaultExpanded: node.isDefaultExpanded,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
orChange: function () {
|
||||||
|
console.log("changed!")
|
||||||
|
},
|
||||||
|
change: function (e) {
|
||||||
|
console.log(e)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -147,6 +147,18 @@
|
|||||||
</b-input-group>
|
</b-input-group>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<AdvancedTreeSelect
|
||||||
|
:initial_selection1="settings.search_keywords"
|
||||||
|
:options="facets.Keywords"
|
||||||
|
facet="keyword"
|
||||||
|
:placeholder="$t('Keywords')"
|
||||||
|
@change="settings.search_keywords = $event"
|
||||||
|
@load-children="loadChildren($event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- foods filter -->
|
<!-- foods filter -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -285,6 +297,7 @@ import GenericMultiselect from "@/components/GenericMultiselect"
|
|||||||
import { Treeselect, LOAD_CHILDREN_OPTIONS } from "@riophae/vue-treeselect" //TODO: delete
|
import { Treeselect, LOAD_CHILDREN_OPTIONS } from "@riophae/vue-treeselect" //TODO: delete
|
||||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css" //TODO: delete
|
import "@riophae/vue-treeselect/dist/vue-treeselect.css" //TODO: delete
|
||||||
import RecipeSwitcher from "@/components/Buttons/RecipeSwitcher"
|
import RecipeSwitcher from "@/components/Buttons/RecipeSwitcher"
|
||||||
|
import AdvancedTreeSelect from "@/apps/RecipeSearchView/AdvancedTreeSelect"
|
||||||
|
|
||||||
Vue.use(VueCookies)
|
Vue.use(VueCookies)
|
||||||
Vue.use(BootstrapVue)
|
Vue.use(BootstrapVue)
|
||||||
@ -512,7 +525,6 @@ export default {
|
|||||||
this.search.pagination_page = page
|
this.search.pagination_page = page
|
||||||
this.refreshData(false)
|
this.refreshData(false)
|
||||||
},
|
},
|
||||||
|
|
||||||
normalizer(node) {
|
normalizer(node) {
|
||||||
let count = node?.count ? " (" + node.count + ")" : ""
|
let count = node?.count ? " (" + node.count + ")" : ""
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user