Add address input and refactor federation stuff

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-07-30 10:35:29 +02:00
parent bcfc26ee59
commit 5fbaf42cad
34 changed files with 729 additions and 192 deletions

View File

@@ -0,0 +1,53 @@
<template>
<b-field label="Find an address">
<b-autocomplete
:data="data"
placeholder="e.g. 10 Rue Jangot"
field="description"
:loading="isFetching"
@typing="getAsyncData"
@select="option => selected = option">
<template slot-scope="{option}">
<b>{{ option.description }}</b>
<p>
<small>{{ option.street }}</small>,&#32;
<small>{{ option.locality }}</small>
</p>
</template>
</b-autocomplete>
</b-field>
</template>
<script lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
import { IAddress } from '@/types/address.model';
import { ADDRESS } from '@/graphql/address';
@Component
export default class AddressAutoComplete extends Vue {
@Prop({ required: false, default: () => [] }) initialData!: IAddress[];
data: IAddress[] = this.initialData;
selected: IAddress|null = null;
isFetching: boolean = false;
async getAsyncData(query) {
if (!query.length) {
this.data = [];
return;
}
this.isFetching = true;
const result = await this.$apollo.query({
query: ADDRESS,
variables: { query },
});
this.data = result.data.searchAddress as IAddress[];
}
@Watch("selected")
updateSelected() {
this.$emit('input', this.selected);
}
}
</script>

18
js/src/graphql/address.ts Normal file
View File

@@ -0,0 +1,18 @@
import gql from 'graphql-tag';
export const ADDRESS = gql`
query($query:String!) {
searchAddress(
query: $query
) {
description,
geom,
floor,
street,
locality,
postalCode,
region,
country
}
}
`;

View File

@@ -144,7 +144,8 @@ export const CREATE_EVENT = gql`
$category: String!,
$beginsOn: DateTime!,
$picture: PictureInput,
$tags: [String]
$tags: [String],
$physicalAddress: AddressInput!
) {
createEvent(
title: $title,
@@ -153,7 +154,8 @@ export const CREATE_EVENT = gql`
organizerActorId: $organizerActorId,
category: $category,
picture: $picture,
tags: $tags
tags: $tags,
physicalAddress: $physicalAddress
) {
id,
uuid,

View File

@@ -1,4 +1,5 @@
export interface IAddress {
id: number;
description: string;
floor: string;
street: string;

View File

@@ -14,6 +14,8 @@
<tag-input v-model="event.tags" :data="tags" path="title" />
<address-auto-complete v-model="event.physicalAddress" />
<date-time-picker v-model="event.beginsOn" :label="$gettext('Starts on…')" :step="15"/>
<date-time-picker v-model="event.endsOn" :label="$gettext('Ends on…')" :step="15" />
@@ -57,9 +59,10 @@ import DateTimePicker from '@/components/Event/DateTimePicker.vue';
import TagInput from '@/components/Event/TagInput.vue';
import { TAGS } from '@/graphql/tags';
import { ITag } from '@/types/tag.model';
import AddressAutoComplete from '@/components/Event/AddressAutoComplete.vue';
@Component({
components: { TagInput, DateTimePicker, PictureUpload, Editor },
components: { AddressAutoComplete, TagInput, DateTimePicker, PictureUpload, Editor },
apollo: {
loggedPerson: {
query: LOGGED_PERSON,
@@ -134,9 +137,13 @@ export default class CreateEvent extends Vue {
const obj = {
organizerActorId: this.loggedPerson.id,
beginsOn: this.event.beginsOn.toISOString(),
tags: this.event.tags.map((tag: ITag) => tag.title),
tags: this.event.tags.map((tag: ITag) => tag.title)
};
const res = Object.assign({}, this.event, obj);
let res = Object.assign({}, this.event, obj);
if (this.event.physicalAddress) {
delete this.event.physicalAddress['__typename'];
}
/**
* Transform picture files