From f3dab2d315e8fb00f541af6bde2de6487d5dc60c Mon Sep 17 00:00:00 2001 From: lesion Date: Sat, 2 Mar 2019 00:02:13 +0100 Subject: [PATCH] fix #3 --- app/controller/export.js | 1 - client/src/App.vue | 48 ++++++++++++++--------------- client/src/components/Calendar.vue | 19 ++++++++++-- client/src/components/Event.vue | 2 +- client/src/components/Export.vue | 1 - client/src/components/Typeahead.vue | 2 +- client/src/store.js | 2 ++ 7 files changed, 44 insertions(+), 31 deletions(-) diff --git a/app/controller/export.js b/app/controller/export.js index effde999..6ad3c5c7 100644 --- a/app/controller/export.js +++ b/app/controller/export.js @@ -19,7 +19,6 @@ const exportController = { if (places) { wherePlace.name = places.split(',') } - console.log(wherePlace.name) const events = await Event.findAll({ order: [['start_datetime', 'ASC']], where: { start_datetime: { [Sequelize.Op.gte]: yesterday } }, diff --git a/client/src/App.vue b/client/src/App.vue index ac75a7c4..ae3c560e 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -6,7 +6,6 @@ b-collapse#nav_collapse(is-nav) b-navbar-nav.ml-auto(v-if='logged') b-nav-item(to='/new_event') {{$t('Add Event')}} - b-nav-item(@click='search=!search') {{$t('Search')}} b-nav-item(to='/settings') {{$t('Settings')}} b-nav-item(v-if='user.is_admin' to='/admin') {{$t('Admin')}} b-nav-item(variant='danger' @click='logout') {{$t('Logout')}} @@ -15,24 +14,29 @@ b-nav-item(to='/register') {{$t('Register')}} b-nav-item(to='/login') {{$t('Login')}} transition(name='toggle') - b-navbar#search(v-if='search' type='dark' variant="dark" toggleable='lg') - b-navbar-nav - b-nav-form - typeahead.ml-1(v-model='filters_places' - textField='name' valueField='name' - updateOnMatchOnly - :data='places' multiple placeholder='Luogo') - b-nav-form - typeahead.ml-1(v-model='filters_tags' - updateOnMatchOnly - textField='tag' valueField='tag' - :data='tags' multiple placeholder='Tags') - b-navbar-nav.ml-auto(variant='dark') - b-nav-item(to='/export/feed' href='#') feed - b-nav-item(to='/export/ics') cal - b-nav-item(to='/export/email') mail - b-nav-item(to='/export/embed') embed - b-nav-item(to='/export/print') print + b-navbar#search(type='dark' variant="dark" toggleable='lg') + b-navbar-toggle(target='nav_search') + v-icon(name='search') + b-collapse#nav_search(is-nav) + + + b-navbar-nav + b-nav-form + typeahead.ml-1.mt-1(v-model='filters_places' + textField='name' valueField='name' + updateOnMatchOnly + :data='places' multiple placeholder='Luogo') + b-nav-form + typeahead.ml-1.mt-1(v-model='filters_tags' + updateOnMatchOnly + textField='tag' valueField='tag' + :data='tags' multiple placeholder='Tags') + b-navbar-nav.ml-auto(variant='dark') + b-nav-item(to='/export/feed' href='#') feed + b-nav-item(to='/export/ics') cal + b-nav-item(to='/export/email') mail + b-nav-item(to='/export/embed') embed + b-nav-item(to='/export/print') print Home transition(name="fade" mode="out-in") router-view(name='modal') @@ -54,20 +58,14 @@ export default { mounted () { this.updateMeta() }, - data () { - return {search: false} - }, components: { Register, Login, Home, Settings, newEvent, eventDetail }, computed: { ...mapState(['logged', 'user', 'filters', 'tags', 'places']), filters_tags: { set (value) { - console.log('dentro set ', value) this.setSearchTags(value) }, get () { - console.log('dentro get') - console.log(this.filters) return this.filters.tags } }, diff --git a/client/src/components/Calendar.vue b/client/src/components/Calendar.vue index aa6b3a0b..3d11bd8f 100644 --- a/client/src/components/Calendar.vue +++ b/client/src/components/Calendar.vue @@ -10,6 +10,7 @@ import { mapState, mapActions } from 'vuex' import filters from '@/filters' import moment from 'moment' +import { intersection } from 'lodash' export default { name: 'Calendar', @@ -58,7 +59,21 @@ export default { } }, computed: { - ...mapState(['events', 'tags']), + filteredEvents () { + if (!this.filters.tags.length && !this.filters.places.length) return this.events + return this.events.filter(e => { + if (this.filters.tags.length) { + const m = intersection(e.tags.map(t => t.tag), this.filters.tags) + if (m.length>0) return true + } + if (this.filters.places.length) { + if (this.filters.places.find(p => p === e.place.name)) + return true + } + return 0 + }) + }, + ...mapState(['events', 'tags', 'filters']), attributes () { return [ { key: 'todaly', dates: new Date(), @@ -67,7 +82,7 @@ export default { }, popover: {label: this.$t('Today')} }, - ...this.events.map(this.eventToAttribute) + ...this.filteredEvents.map(this.eventToAttribute) ] } } diff --git a/client/src/components/Event.vue b/client/src/components/Event.vue index b59844d0..bf7d55d4 100644 --- a/client/src/components/Event.vue +++ b/client/src/components/Event.vue @@ -2,7 +2,7 @@ b-card(bg-variant='dark' text-variant='white' @click='$router.push("/event/" + event.id)' :img-src='imgPath') - h4 {{event.title}} + h5 {{event.title}} div {{event.start_datetime|datetime}} span(v-b-popover.hover="event.place && event.place.address || ''") {{event.place.name}} br diff --git a/client/src/components/Export.vue b/client/src/components/Export.vue index 35e17c5d..626858c3 100644 --- a/client/src/components/Export.vue +++ b/client/src/components/Export.vue @@ -29,7 +29,6 @@ img(v-if='event.image_path' slot="aside" :src="imgPath(event)" alt="Media Aside" style='max-height: 60px') small.float-right {{event.start_datetime|short_datetime}} h5.mb-1 {{event.title}} - small.mb-1 {{event.description}} b-badge.float-right.ml-1(v-for='tag in event.tags') {{tag.tag}} small.float-right(v-b-popover.hover='event.place.address') {{event.place.name}} Calendar(v-else) diff --git a/client/src/components/Typeahead.vue b/client/src/components/Typeahead.vue index 42cddcd7..dc3a1410 100644 --- a/client/src/components/Typeahead.vue +++ b/client/src/components/Typeahead.vue @@ -19,7 +19,7 @@ div b-badge.mr-1(@click="removeSelected(sel)" v-for="sel in selectedLabel" - :key="sel") {{sel}} + :key="sel") {{sel}} b-list-group.groupMenu(v-show='showDropdown') b-list-group-item(:key="$index" v-for="(item, $index) in matched" diff --git a/client/src/store.js b/client/src/store.js index 41f4ffe4..461ad1ec 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -62,6 +62,8 @@ export default new Vuex.Store({ addSearchTag (state, tag) { if (!state.filters.tags.find(t => t === tag.tag)) { state.filters.tags.push(tag.tag) + } else { + state.filters.tags = state.filters.tags.filter(t => t !== tag.tag) } }, setSearchTags (state, tags) {