2019-04-03 15:29:03 +00:00
|
|
|
<template>
|
|
|
|
<section class="container">
|
|
|
|
<h1>
|
2019-09-12 09:34:01 +00:00
|
|
|
{{ $t('Search results: "{search}"', { search: this.searchTerm }) }}
|
2019-04-03 15:29:03 +00:00
|
|
|
</h1>
|
|
|
|
<b-loading :active.sync="$apollo.loading" />
|
|
|
|
<b-tabs v-model="activeTab" type="is-boxed" class="searchTabs" @change="changeTab">
|
|
|
|
<b-tab-item>
|
|
|
|
<template slot="header">
|
|
|
|
<b-icon icon="calendar"></b-icon>
|
2019-09-12 09:34:01 +00:00
|
|
|
<span>
|
|
|
|
{{ $t('Events') }} <b-tag rounded>{{ searchEvents.total }}</b-tag>
|
|
|
|
</span>
|
2019-04-03 15:29:03 +00:00
|
|
|
</template>
|
2019-04-24 17:01:39 +00:00
|
|
|
<div v-if="searchEvents.total > 0" class="columns is-multiline">
|
2019-04-03 15:29:03 +00:00
|
|
|
<div class="column is-one-quarter-desktop is-half-mobile"
|
2019-04-24 17:01:39 +00:00
|
|
|
v-for="event in searchEvents.elements"
|
2019-04-03 15:29:03 +00:00
|
|
|
:key="event.uuid">
|
|
|
|
<EventCard
|
|
|
|
:event="event"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<b-message v-else-if="$apollo.loading === false" type="is-danger">
|
2019-09-12 09:34:01 +00:00
|
|
|
{{ $t('No events found') }}
|
2019-04-03 15:29:03 +00:00
|
|
|
</b-message>
|
|
|
|
</b-tab-item>
|
2019-10-03 10:32:20 +00:00
|
|
|
<!-- <b-tab-item>-->
|
|
|
|
<!-- <template slot="header">-->
|
|
|
|
<!-- <b-icon icon="account-multiple"></b-icon>-->
|
|
|
|
<!-- <span>-->
|
|
|
|
<!-- {{ $t('Groups') }} <b-tag rounded>{{ searchGroups.total }}</b-tag>-->
|
|
|
|
<!-- </span>-->
|
|
|
|
<!-- </template>-->
|
|
|
|
<!-- <div v-if="searchGroups.total > 0" class="columns is-multiline">-->
|
|
|
|
<!-- <div class="column is-one-quarter-desktop is-half-mobile"-->
|
|
|
|
<!-- v-for="group in groups"-->
|
|
|
|
<!-- :key="group.uuid">-->
|
|
|
|
<!-- <group-card :group="group" />-->
|
|
|
|
<!-- </div>-->
|
|
|
|
<!-- </div>-->
|
|
|
|
<!-- <b-message v-else-if="$apollo.loading === false" type="is-danger">-->
|
|
|
|
<!-- {{ $t('No groups found') }}-->
|
|
|
|
<!-- </b-message>-->
|
|
|
|
<!-- </b-tab-item>-->
|
2019-04-03 15:29:03 +00:00
|
|
|
</b-tabs>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
2019-04-24 17:01:39 +00:00
|
|
|
import { SEARCH_EVENTS, SEARCH_GROUPS } from '@/graphql/search';
|
2019-04-03 15:29:03 +00:00
|
|
|
import { RouteName } from '@/router';
|
|
|
|
import EventCard from '@/components/Event/EventCard.vue';
|
|
|
|
import GroupCard from '@/components/Group/GroupCard.vue';
|
2019-04-26 13:22:16 +00:00
|
|
|
import { Group, IGroup } from '@/types/actor';
|
2019-04-24 17:01:39 +00:00
|
|
|
import { SearchEvent, SearchGroup } from '@/types/search.model';
|
2019-04-03 15:29:03 +00:00
|
|
|
|
|
|
|
enum SearchTabs {
|
|
|
|
EVENTS = 0,
|
|
|
|
GROUPS = 1,
|
|
|
|
PERSONS = 2, // not used right now
|
|
|
|
}
|
|
|
|
|
|
|
|
const tabsName = {
|
|
|
|
events: SearchTabs.EVENTS,
|
|
|
|
groups: SearchTabs.GROUPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
2019-04-24 17:01:39 +00:00
|
|
|
searchEvents: {
|
|
|
|
query: SEARCH_EVENTS,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
searchText: this.searchTerm,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return !this.searchTerm;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
searchGroups: {
|
|
|
|
query: SEARCH_GROUPS,
|
2019-04-03 15:29:03 +00:00
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
searchText: this.searchTerm,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return !this.searchTerm;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
GroupCard,
|
|
|
|
EventCard,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class Search extends Vue {
|
|
|
|
@Prop({ type: String, required: true }) searchTerm!: string;
|
|
|
|
@Prop({ type: String, required: false, default: 'events' }) searchType!: string;
|
|
|
|
|
2019-04-24 17:01:39 +00:00
|
|
|
searchEvents: SearchEvent = { total: 0, elements: [] };
|
|
|
|
searchGroups: SearchGroup = { total: 0, elements: [] };
|
2019-04-03 15:29:03 +00:00
|
|
|
activeTab: SearchTabs = tabsName[this.searchType];
|
|
|
|
|
|
|
|
changeTab(index: number) {
|
|
|
|
switch (index) {
|
|
|
|
case SearchTabs.EVENTS:
|
|
|
|
this.$router.push({ name: RouteName.SEARCH, params: { searchTerm: this.searchTerm, searchType: 'events' } });
|
|
|
|
break;
|
|
|
|
case SearchTabs.GROUPS:
|
|
|
|
this.$router.push({ name: RouteName.SEARCH, params: { searchTerm: this.searchTerm, searchType: 'groups' } });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Watch('search')
|
|
|
|
changeTabForResult() {
|
2019-04-24 17:01:39 +00:00
|
|
|
if (this.searchEvents.total === 0 && this.searchGroups.total > 0) {
|
2019-04-03 15:29:03 +00:00
|
|
|
this.activeTab = SearchTabs.GROUPS;
|
|
|
|
}
|
2019-04-24 17:01:39 +00:00
|
|
|
if (this.searchGroups.total === 0 && this.searchEvents.total > 0) {
|
2019-04-03 15:29:03 +00:00
|
|
|
this.activeTab = SearchTabs.EVENTS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Watch('search')
|
|
|
|
@Watch('$route')
|
|
|
|
async loadSearch() {
|
2019-04-24 17:01:39 +00:00
|
|
|
await this.$apollo.queries['searchEvents'].refetch() && this.$apollo.queries['searchGroups'].refetch();
|
2019-04-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get groups(): IGroup[] {
|
2019-04-24 17:01:39 +00:00
|
|
|
return this.searchGroups.elements.map(group => Object.assign(new Group(), group));
|
2019-04-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
|
|
@import "~bulma/sass/utilities/_all";
|
|
|
|
@import "~bulma/sass/components/tabs";
|
|
|
|
@import "~buefy/src/scss/components/tabs";
|
|
|
|
@import "~bulma/sass/elements/tag";
|
|
|
|
|
|
|
|
.searchTabs .tab-content {
|
|
|
|
background: #fff;
|
|
|
|
min-height: 10em;
|
|
|
|
}
|
|
|
|
</style>
|