2019-04-03 00:25:12 +02:00
|
|
|
<template lang="pug">
|
2020-01-15 23:33:56 +01:00
|
|
|
el-main
|
2019-06-10 01:25:05 +02:00
|
|
|
//- el-switch.mb-1(v-if='$auth.loggedIn'
|
|
|
|
//- active-text='solo miei'
|
|
|
|
//- inactive-text='tutti'
|
|
|
|
//- inactive-color='lightgreen'
|
|
|
|
//- v-model='onlyMine'
|
|
|
|
//- )
|
2020-01-15 23:33:56 +01:00
|
|
|
el-switch.mt-1.mb-2.ml-2(
|
2019-07-23 01:31:43 +02:00
|
|
|
v-if='recurrentFilter && settings.allow_recurrent_event'
|
2020-01-15 23:33:56 +01:00
|
|
|
:active-text="$t('event.show_recurrent')"
|
2019-07-11 23:31:37 +02:00
|
|
|
v-model='showRecurrent'
|
|
|
|
)
|
2020-01-15 23:33:56 +01:00
|
|
|
el-switch.mt-1.mb-2.ml-2(
|
2019-07-23 01:31:43 +02:00
|
|
|
v-if='pastFilter'
|
2020-01-15 23:33:56 +01:00
|
|
|
:active-text="$t('event.show_past')"
|
2019-05-30 12:04:14 +02:00
|
|
|
v-model='showPast'
|
2019-09-11 19:12:24 +02:00
|
|
|
)
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2020-01-15 23:33:56 +01:00
|
|
|
el-autocomplete.mb-1#search.inline-input(placeholder='Cerca' prefix-icon='el-icon-search'
|
|
|
|
highlight-first-item
|
|
|
|
v-model='search' :debounce='200'
|
|
|
|
:fetch-suggestions='querySearch' clearable
|
|
|
|
@select='addFilter')
|
|
|
|
template(slot-scope='{ item }')
|
|
|
|
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"')
|
|
|
|
br
|
|
|
|
el-tag.mr-1(type='success' v-for='f in filter'
|
|
|
|
disable-transitions closable :key='f.type + f.id'
|
|
|
|
@close='removeFilter(f)') {{f.label}}
|
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-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']),
|
2019-05-30 12:12:51 +02:00
|
|
|
// TOFIX: optimize
|
2019-05-30 12:04:14 +02:00
|
|
|
keywords () {
|
2020-01-15 23:33:56 +01:00
|
|
|
const tags = this.tags.map(t => ({ type: 'tag', label: t, weigth: t.weigth, id: t }))
|
|
|
|
const places = this.places.map(p => ({ type: 'place', label: p.name, weigth: p.weigth, id: p.id }))
|
2019-09-11 19:12:24 +02:00
|
|
|
return tags.concat(places).sort((a, b) => b.weigth - a.weigth)
|
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 }
|
2019-05-30 12:04:14 +02:00
|
|
|
},
|
2020-01-15 23:33:56 +01:00
|
|
|
filter () {
|
|
|
|
// set (filters) {
|
|
|
|
// const tags = filters.filter(f => f[0] === 't').map(t => t.slice(1))
|
|
|
|
// this.setSearchTags(tags)
|
|
|
|
// const places = filters.filter(f => f[0] === 'p').map(p => +p.slice(1))
|
|
|
|
// this.setSearchPlaces(places)
|
|
|
|
// },
|
|
|
|
// get () {
|
|
|
|
return this.filters.tags.concat(this.filters.places)
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions(['setSearchPlaces', 'setSearchTags',
|
|
|
|
'showPastEvents', 'showRecurrentEvents', 'updateEvent']),
|
|
|
|
removeFilter (item) {
|
|
|
|
if (item.type === 'tag') {
|
|
|
|
this.setSearchTags(this.filters.tags.filter(t => t.id !== item.id))
|
|
|
|
} else {
|
|
|
|
this.setSearchPlaces(this.filters.places.filter(p => p.id !== item.id))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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') {
|
|
|
|
this.setSearchTags(this.filters.tags.concat(item))
|
|
|
|
} else {
|
|
|
|
this.setSearchPlaces(this.filters.places.concat(item))
|
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'>
|
|
|
|
#search {
|
|
|
|
border: none;
|
|
|
|
border-radius: 0px;
|
|
|
|
border-bottom: 2px solid lightgray;
|
|
|
|
color: white;
|
|
|
|
background-color: #333;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-switch__label {
|
|
|
|
color: #aaa;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-switch__label.is-active {
|
|
|
|
color: lightgreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-switch__core {
|
|
|
|
background-color: #555;
|
|
|
|
border-color: #777;
|
|
|
|
}
|
|
|
|
</style>
|