2019-04-03 17:29:03 +02:00
|
|
|
<template>
|
2020-02-18 08:57:00 +01:00
|
|
|
<section class="container">
|
2020-07-31 17:52:26 +02:00
|
|
|
<form @submit.prevent="processSearch" v-if="!actualTag">
|
|
|
|
<b-field :label="$t('Event')">
|
|
|
|
<b-input size="is-large" v-model="search" />
|
|
|
|
</b-field>
|
|
|
|
<b-field :label="$t('Location')">
|
|
|
|
<address-auto-complete v-model="location" />
|
|
|
|
</b-field>
|
|
|
|
<b-button native-type="submit">{{ $t("Go") }}</b-button>
|
|
|
|
</form>
|
2020-02-18 08:57:00 +01:00
|
|
|
<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>
|
|
|
|
<span>
|
|
|
|
{{ $t("Events") }}
|
|
|
|
<b-tag rounded>{{ searchEvents.total }}</b-tag>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<div v-if="searchEvents.total > 0" class="columns is-multiline">
|
|
|
|
<div
|
2020-07-06 18:36:51 +02:00
|
|
|
class="column is-one-quarter-desktop"
|
2020-02-18 08:57:00 +01:00
|
|
|
v-for="event in searchEvents.elements"
|
|
|
|
:key="event.uuid"
|
|
|
|
>
|
|
|
|
<EventCard :event="event" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<b-message v-else-if="$apollo.loading === false" type="is-danger">{{
|
|
|
|
$t("No events found")
|
|
|
|
}}</b-message>
|
|
|
|
</b-tab-item>
|
|
|
|
<!-- <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>-->
|
|
|
|
</b-tabs>
|
|
|
|
</section>
|
2019-04-03 17:29:03 +02:00
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
|
|
|
|
import { SEARCH_EVENTS, SEARCH_GROUPS } from "../graphql/search";
|
|
|
|
import RouteName from "../router/name";
|
|
|
|
import EventCard from "../components/Event/EventCard.vue";
|
|
|
|
import GroupCard from "../components/Group/GroupCard.vue";
|
2020-07-31 17:52:26 +02:00
|
|
|
import AddressAutoComplete from "../components/Event/AddressAutoComplete.vue";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Group, IGroup } from "../types/actor";
|
2020-07-31 17:52:26 +02:00
|
|
|
import { IAddress, Address } from "../types/address.model";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { SearchEvent, SearchGroup } from "../types/search.model";
|
2020-07-31 17:52:26 +02:00
|
|
|
import ngeohash from "ngeohash";
|
2019-04-03 17:29:03 +02:00
|
|
|
|
|
|
|
enum SearchTabs {
|
2020-02-18 08:57:00 +01:00
|
|
|
EVENTS = 0,
|
|
|
|
GROUPS = 1,
|
|
|
|
PERSONS = 2, // not used right now
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
const tabsName: { events: number; groups: number } = {
|
2019-04-03 17:29:03 +02:00
|
|
|
events: SearchTabs.EVENTS,
|
|
|
|
groups: SearchTabs.GROUPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
2019-04-24 19:01:39 +02:00
|
|
|
searchEvents: {
|
|
|
|
query: SEARCH_EVENTS,
|
|
|
|
variables() {
|
|
|
|
return {
|
2020-07-31 17:52:26 +02:00
|
|
|
term: this.search,
|
2020-08-03 17:34:50 +02:00
|
|
|
tags: this.actualTag,
|
2020-07-31 17:52:26 +02:00
|
|
|
location: this.geohash,
|
2019-04-24 19:01:39 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
2020-07-31 17:52:26 +02:00
|
|
|
return !this.search && !this.actualTag;
|
2019-04-24 19:01:39 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
searchGroups: {
|
|
|
|
query: SEARCH_GROUPS,
|
2019-04-03 17:29:03 +02:00
|
|
|
variables() {
|
|
|
|
return {
|
2020-07-31 17:52:26 +02:00
|
|
|
searchText: this.search,
|
2019-04-03 17:29:03 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
2020-07-31 17:52:26 +02:00
|
|
|
return !this.search || this.isURL(this.search);
|
2019-04-03 17:29:03 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
GroupCard,
|
|
|
|
EventCard,
|
2020-07-31 17:52:26 +02:00
|
|
|
AddressAutoComplete,
|
2019-04-03 17:29:03 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class Search extends Vue {
|
2020-07-31 17:52:26 +02:00
|
|
|
@Prop({ type: String, required: false }) searchTerm!: string;
|
|
|
|
|
|
|
|
@Prop({ type: String, required: false }) tag!: string;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
@Prop({ type: String, required: false, default: "events" }) searchType!: "events" | "groups";
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2019-04-24 19:01:39 +02:00
|
|
|
searchEvents: SearchEvent = { total: 0, elements: [] };
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-04-24 19:01:39 +02:00
|
|
|
searchGroups: SearchGroup = { total: 0, elements: [] };
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
activeTab: SearchTabs = tabsName[this.searchType];
|
|
|
|
|
2020-07-31 17:52:26 +02:00
|
|
|
search: string = this.searchTerm;
|
|
|
|
actualTag: string = this.tag;
|
|
|
|
location: IAddress = new Address();
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@Watch("searchEvents")
|
2020-02-07 17:04:03 +01:00
|
|
|
async redirectURLToEvent() {
|
|
|
|
if (this.searchEvents.total === 1 && this.isURL(this.searchTerm)) {
|
2020-02-18 08:57:00 +01:00
|
|
|
return await this.$router.replace({
|
|
|
|
name: RouteName.EVENT,
|
|
|
|
params: { uuid: this.searchEvents.elements[0].uuid },
|
|
|
|
});
|
2020-02-07 17:04:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
changeTab(index: number) {
|
|
|
|
switch (index) {
|
|
|
|
case SearchTabs.EVENTS:
|
2020-02-18 08:57:00 +01:00
|
|
|
this.$router.push({
|
|
|
|
name: RouteName.SEARCH,
|
|
|
|
params: { searchTerm: this.searchTerm, searchType: "events" },
|
|
|
|
});
|
2019-04-03 17:29:03 +02:00
|
|
|
break;
|
|
|
|
case SearchTabs.GROUPS:
|
2020-02-18 08:57:00 +01:00
|
|
|
this.$router.push({
|
|
|
|
name: RouteName.SEARCH,
|
|
|
|
params: { searchTerm: this.searchTerm, searchType: "groups" },
|
|
|
|
});
|
2019-04-03 17:29:03 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@Watch("search")
|
2019-04-03 17:29:03 +02:00
|
|
|
changeTabForResult() {
|
2019-04-24 19:01:39 +02:00
|
|
|
if (this.searchEvents.total === 0 && this.searchGroups.total > 0) {
|
2019-04-03 17:29:03 +02:00
|
|
|
this.activeTab = SearchTabs.GROUPS;
|
|
|
|
}
|
2019-04-24 19:01:39 +02:00
|
|
|
if (this.searchGroups.total === 0 && this.searchEvents.total > 0) {
|
2019-04-03 17:29:03 +02:00
|
|
|
this.activeTab = SearchTabs.EVENTS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@Watch("search")
|
|
|
|
@Watch("$route")
|
2019-04-03 17:29:03 +02:00
|
|
|
async loadSearch() {
|
2020-02-18 08:57:00 +01:00
|
|
|
(await this.$apollo.queries.searchEvents.refetch()) &&
|
|
|
|
this.$apollo.queries.searchGroups.refetch();
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get groups(): IGroup[] {
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.searchGroups.elements.map((group) => Object.assign(new Group(), group));
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
|
2020-02-07 17:04:03 +01:00
|
|
|
isURL(url: string): boolean {
|
2020-02-18 08:57:00 +01:00
|
|
|
const a = document.createElement("a");
|
2020-02-07 17:04:03 +01:00
|
|
|
a.href = url;
|
|
|
|
return (a.host && a.host !== window.location.host) as boolean;
|
|
|
|
}
|
2020-07-31 17:52:26 +02:00
|
|
|
|
|
|
|
processSearch() {
|
|
|
|
this.$apollo.queries.searchEvents.refetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
get geohash() {
|
|
|
|
if (this.location && this.location.geom) {
|
|
|
|
const [lon, lat] = this.location.geom.split(";");
|
|
|
|
return ngeohash.encode(lat, lon, 6);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang="scss">
|
2020-02-18 08:57:00 +01:00
|
|
|
@import "~bulma/sass/utilities/_all";
|
|
|
|
@import "~bulma/sass/components/tabs";
|
|
|
|
@import "~buefy/src/scss/components/tabs";
|
|
|
|
@import "~bulma/sass/elements/tag";
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.searchTabs .tab-content {
|
|
|
|
background: #fff;
|
|
|
|
min-height: 10em;
|
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
</style>
|