gancio-upstream/components/Search.vue

133 lines
4.3 KiB
Vue
Raw Normal View History

2022-05-31 15:22:42 +02:00
<template lang="pug">
2022-06-21 22:45:20 +02:00
v-row
v-col(sm=3 cols=12)
2022-06-21 22:45:20 +02:00
v-switch(
v-if='settings.allow_recurrent_event'
v-model='show_recurrent'
@change='change'
inset color='primary'
hide-details
:label="$t('event.show_recurrent')")
v-col(sm="5" cols=12)
2022-06-21 22:45:20 +02:00
v-autocomplete.p-0(
:disabled='!!collection'
v-model="filters"
2023-10-30 09:36:18 +01:00
outlined
:label='$t("common.filter")'
2022-06-21 22:45:20 +02:00
hide-details
color='primary'
hide-selected
small-chips
@focus='search'
:menu-props="{ maxWidth: '400' }"
:items='items'
@change='change'
hide-no-data
@input.native='search'
item-text='label'
return-object
chips
multiple)
template(v-slot:selection="{ attrs, item }")
v-chip(v-bind="attrs"
small
close
@click:close='remove(item)'
:close-icon='mdiCloseCircle')
v-avatar(left)
2023-10-30 09:36:18 +01:00
v-icon(small v-text="item.type === 'place' ? mdiMapMarker : item.type === 'tag' ? mdiTag : mdiCollage")
2022-06-21 22:45:20 +02:00
span {{ item.label }}
template(v-slot:item='{ item }')
v-list-item-avatar
2023-10-30 09:36:18 +01:00
v-icon(v-text="item.type === 'place' ? mdiMapMarker : item.type === 'tag' ? mdiTag : mdiCollage")
2022-06-21 22:45:20 +02:00
v-list-item-content
v-list-item-title(v-text='item.label')
2023-10-30 09:36:18 +01:00
v-list-item-subtitle(v-if='item.type ==="place"' v-text='item.label !== "online" && item.address')
v-col(sm=4 cols=12)
v-autocomplete.p-0(
:disabled='!!filters.length'
v-model="collection"
outlined
:label='$t("common.collections")'
hide-details
color='primary'
hide-selected
:menu-props="{ maxWidth: '400' }"
:items='collections'
@change='change'
hide-no-data
clearable
:clear-icon='mdiCloseCircle'
item-text='name')
template(v-slot:itsdfems='{ item }')
v-list-item-avatar
v-icon(v-text="item.type === 'place' ? mdiMapMarker : item.type === 'tag' ? mdiTag : mdiCollage")
v-list-item-content
v-list-item-title(v-text='item.label')
v-list-item-subtitle(v-if='item.type ==="place"' v-text='item.label !== "online" && item.address')
2019-04-03 00:25:12 +02:00
</template>
<script>
2020-11-13 00:13:44 +01:00
import { mapState } from 'vuex'
2023-10-30 09:36:18 +01:00
import { mdiMapMarker, mdiTag, mdiCloseCircle, mdiCollage } from '@mdi/js'
2022-05-31 15:22:42 +02:00
import debounce from 'lodash/debounce'
2019-04-03 00:25:12 +02:00
export default {
2019-09-11 19:12:24 +02:00
name: 'Search',
2019-06-10 01:25:05 +02:00
props: {
value: { type: Object, default: () => ({ }) }
2019-06-10 01:25:05 +02:00
},
2019-09-11 19:12:24 +02:00
data () {
return {
2023-10-30 09:36:18 +01:00
mdiTag, mdiMapMarker, mdiCloseCircle, mdiCollage,
items: [],
filters: [],
collection: null,
collections: [],
show_recurrent: this.value.show_recurrent || false
2020-11-13 00:13:44 +01:00
}
2020-01-15 23:33:56 +01:00
},
async fetch () {
this.collections = await this.$axios.$get('/collections')
},
2023-10-30 09:36:18 +01:00
computed: {
...mapState(['settings']),
},
2020-01-15 23:33:56 +01:00
methods: {
2022-05-31 15:22:42 +02:00
filter (item, queryText, itemText) {
return itemText.toLocaleLowerCase().indexOf(queryText.toLocaleLowerCase()) > -1 ||
item.address && item.address.toLocaleLowerCase().indexOf(queryText.toLocaleLowerCase()) > -1
},
search: debounce(async function(search) {
this.items = await this.$axios.$get(`/event/meta?search=${search.target.value}`)
console.error('items ', this.items.length)
2022-05-31 15:22:42 +02:00
}, 100),
remove (item) {
// const filters = {
// tags: this.filters.filter(t => t.type === 'tag' && t.label !== item.label).map(t => t.label),
// places: this.filters.filter(p => p.type === 'place' && p.id !== item.id).map(p => p.id),
// show_recurrent: this.show_recurrent
// }
2023-10-30 09:36:18 +01:00
this.filters = this.filters.filter(m => m.type !== item.type || m.type === 'place' ? m.id !== item.id : m.label !== item.label)
// this.$emit('input', filters)
this.change()
2021-01-11 00:17:56 +01:00
},
change () {
if (this.collection) {
this.filters = []
this.$emit('input', { collection: this.collection, places: [], tags: [], show_recurrent: this.show_recurrent })
} else {
const filters = {
tags: this.filters.filter(t => t.type === 'tag').map(t => t.label),
places: this.filters.filter(p => p.type === 'place').map(p => p.id),
show_recurrent: this.show_recurrent
}
this.$emit('input', filters)
2022-05-31 15:22:42 +02:00
}
}
2019-04-03 00:25:12 +02:00
}
}
</script>