gancio-upstream/components/Search.vue

147 lines
4.1 KiB
Vue
Raw Normal View History

2019-04-03 00:25:12 +02:00
<template lang="pug">
2020-07-25 21:41:22 +02:00
v-container
v-switch.mt-0(
2019-07-23 01:31:43 +02:00
v-if='recurrentFilter && settings.allow_recurrent_event'
2020-07-25 21:41:22 +02:00
inset color='primary'
:label="$t('event.show_recurrent')"
2020-01-21 15:09:23 +01:00
v-model='showRecurrent')
2020-07-25 21:41:22 +02:00
v-switch.mt-0(
v-if='pastFilter' inset color='primary'
:label="$t('event.show_past')"
2020-01-21 15:09:23 +01:00
v-model='showPast')
2019-05-30 12:04:14 +02:00
2020-07-31 01:03:19 +02:00
p {{filter}}
v-autocomplete.mt-0(
:label='$t("common.filter")'
:items='keywords'
v-model='filter'
:search-input.sync='search'
item-text='label'
2020-10-07 10:05:18 +02:00
chips rounded outlined single-line
2020-07-31 01:03:19 +02:00
multiple
)
template(v-slot:selection="data")
v-chip(v-bind="data.attrs"
:input-value="data.selected"
close
@click="data.select"
@click:close="remove(data.item)")
v-avatar(left)
v-icon
//- <v-img :src="data.item.avatar"></v-img>
//- </v-avatar>
span {{ data.item.name }}
template(v-slot:item='{ item }')
v-list-item-content
v-list-item-title(v-text='item.label')
//- span.float-left {{ item.label }}
//- i.float-right.el-icon-place(v-if='item.type==="place"')
//- i.float-right.el-icon-collection-tag(v-if='item.type==="tag"')
//- #filters
//- v-vtn.mr-1.bg-dark(type='text' round plain v-for='t in filters.tags' size='mini'
//- :key='t' @click='removeTag(t)') {{t}}
//- v-btn.mr-1.bg-dark.text-warning(type='text' round plain v-for='p in selectedPlaces' size='mini'
//- :key='p.id' @click='removePlace(p.id)') {{p.name}}
2019-04-03 00:25:12 +02:00
</template>
<script>
2019-09-11 19:12:24 +02:00
import { mapState, mapActions } from 'vuex'
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: {
2019-07-11 23:31:37 +02:00
pastFilter: Boolean,
recurrentFilter: Boolean
2019-06-10 01:25:05 +02:00
},
2019-09-11 19:12:24 +02:00
data () {
return {
2020-07-31 01:03:19 +02:00
filter: null,
2020-01-15 23:33:56 +01:00
search: ''
2019-09-11 19:12:24 +02:00
}
},
2019-04-03 00:25:12 +02:00
computed: {
2019-07-23 01:31:43 +02:00
...mapState(['tags', 'places', 'filters', 'settings']),
2020-07-31 01:03:19 +02:00
// selectedPlaces () {
// return this.places.filter(p => this.filters.places.includes(p.id))
// },
2019-05-30 12:04:14 +02:00
keywords () {
2020-02-09 18:15:44 +01:00
const tags = this.tags.filter(t => !this.filters.tags.includes(t.tag)).map(t => ({ type: 'tag', label: t.tag, weigth: t.weigth, id: t.tag }))
2020-05-22 00:28:42 +02:00
const places = this.places.filter(p => !this.filters.places.includes(p.id))
.map(p => ({ type: 'place', label: p.name, weigth: p.weigth, id: p.id }))
2020-01-21 01:17:45 +01:00
const keywords = tags.concat(places).sort((a, b) => b.weigth - a.weigth)
return keywords
2019-05-30 12:04:14 +02:00
},
2019-07-11 23:31:37 +02:00
showPast: {
set (value) { this.showPastEvents(value) },
get () { return this.filters.show_past_events }
},
showRecurrent: {
set (value) { this.showRecurrentEvents(value) },
get () { return this.filters.show_recurrent_events }
2020-01-15 23:33:56 +01:00
}
2020-07-31 01:03:19 +02:00
// filter () {
// return this.filters.tags.concat(this.filters.places)
// }
2020-01-15 23:33:56 +01:00
},
methods: {
...mapActions(['setSearchPlaces', 'setSearchTags',
'showPastEvents', 'showRecurrentEvents', 'updateEvent']),
2020-02-09 18:15:44 +01:00
removeTag (tag) {
this.setSearchTags(this.filters.tags.filter(t => t !== tag))
},
removePlace (place) {
this.setSearchPlaces(this.filters.places.filter(p => p !== place))
2020-01-15 23:33:56 +01:00
},
querySearch (queryString, cb) {
const ret = this.keywords
.filter(k => !this.filter.map(f => f.id).includes(k.id))
.filter(k => k.label.toLowerCase().includes(queryString))
.slice(0, 5)
cb(ret)
},
addFilter (item) {
if (item.type === 'tag') {
2020-02-09 18:15:44 +01:00
this.setSearchTags(this.filters.tags.concat(item.id))
2020-01-15 23:33:56 +01:00
} else {
2020-02-09 18:15:44 +01:00
this.setSearchPlaces(this.filters.places.concat(item.id))
2019-05-30 12:04:14 +02:00
}
2020-01-15 23:33:56 +01:00
this.search = ''
2019-09-11 19:12:24 +02:00
}
2019-04-03 00:25:12 +02:00
}
}
</script>
2020-01-15 23:33:56 +01:00
<style lang='less'>
2020-07-25 21:41:22 +02:00
// #search {
// #searchInput {
// border: none;
// border-radius: 0px;
// border-bottom: 2px solid lightgray;
// color: white;
// background-color: #111;
// }
2020-02-09 18:15:44 +01:00
2020-07-25 21:41:22 +02:00
// .el-switch__label {
// color: #aaa;
// }
2020-01-15 23:33:56 +01:00
2020-07-25 21:41:22 +02:00
// .el-switch__label.is-active {
// color: lightgreen;
// }
2020-01-15 23:33:56 +01:00
2020-07-25 21:41:22 +02:00
// .el-switch__core {
// background-color: #555;
// border-color: #777;
// }
2020-02-21 17:46:57 +01:00
2020-07-25 21:41:22 +02:00
// .is-checked .el-switch__core {
// background-color: lightgreen;
// }
2020-01-15 23:33:56 +01:00
2020-07-25 21:41:22 +02:00
// #filters {
// line-height: 2rem;
// }
// }
2020-02-21 17:46:57 +01:00
2020-01-15 23:33:56 +01:00
</style>