2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2019-05-22 14:12:11 +02:00
|
|
|
<section class="container">
|
2019-01-21 15:08:22 +01:00
|
|
|
<h1 class="title">
|
|
|
|
<translate>Create a new event</translate>
|
|
|
|
</h1>
|
|
|
|
<div v-if="$apollo.loading">Loading...</div>
|
2019-05-28 18:55:02 +02:00
|
|
|
<div class="columns is-centered" v-else>
|
2019-06-07 17:19:30 +02:00
|
|
|
<form class="column is-two-thirds-desktop" @submit="createEvent">
|
2019-01-21 15:08:22 +01:00
|
|
|
<b-field :label="$gettext('Title')">
|
2019-06-07 17:19:30 +02:00
|
|
|
<b-input aria-required="true" required v-model="event.title" maxlength="64" />
|
2019-01-21 15:08:22 +01:00
|
|
|
</b-field>
|
|
|
|
|
2019-06-07 17:19:30 +02:00
|
|
|
<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" />
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-05-28 18:55:02 +02:00
|
|
|
<div class="field">
|
|
|
|
<label class="label">{{ $gettext('Description') }}</label>
|
|
|
|
<editor v-model="event.description" />
|
|
|
|
</div>
|
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
<b-field :label="$gettext('Category')">
|
|
|
|
<b-select placeholder="Select a category" v-model="event.category">
|
|
|
|
<option
|
|
|
|
v-for="category in categories"
|
|
|
|
:value="category"
|
2019-02-22 16:54:01 +01:00
|
|
|
:key="category"
|
|
|
|
>{{ $gettext(category) }}</option>
|
2019-01-21 15:08:22 +01:00
|
|
|
</b-select>
|
|
|
|
</b-field>
|
|
|
|
|
2019-07-23 17:14:03 +02:00
|
|
|
<picture-upload v-model="pictureFile" />
|
2019-05-22 14:12:11 +02:00
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
<button class="button is-primary">
|
|
|
|
<translate>Create my event</translate>
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-03-22 10:57:14 +01:00
|
|
|
// import Location from '@/components/Location';
|
|
|
|
import { CREATE_EVENT, EDIT_EVENT } from '@/graphql/event';
|
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
|
|
|
import {
|
2019-03-05 12:07:58 +01:00
|
|
|
Category,
|
|
|
|
IEvent,
|
|
|
|
EventModel,
|
2019-03-22 10:57:14 +01:00
|
|
|
} from '@/types/event.model';
|
|
|
|
import { LOGGED_PERSON } from '@/graphql/actor';
|
2019-04-26 15:22:16 +02:00
|
|
|
import { IPerson, Person } from '@/types/actor';
|
2019-05-22 14:12:11 +02:00
|
|
|
import PictureUpload from '@/components/PictureUpload.vue';
|
2019-05-28 18:55:02 +02:00
|
|
|
import Editor from '@/components/Editor.vue';
|
2019-06-07 17:19:30 +02:00
|
|
|
import DateTimePicker from '@/components/Event/DateTimePicker.vue';
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-03-05 12:07:58 +01:00
|
|
|
@Component({
|
2019-06-07 17:19:30 +02:00
|
|
|
components: { DateTimePicker, PictureUpload, Editor },
|
2019-03-05 12:07:58 +01:00
|
|
|
apollo: {
|
|
|
|
loggedPerson: {
|
|
|
|
query: LOGGED_PERSON,
|
2019-03-22 10:57:14 +01:00
|
|
|
},
|
|
|
|
},
|
2019-03-05 12:07:58 +01:00
|
|
|
})
|
2019-01-21 15:08:22 +01:00
|
|
|
export default class CreateEvent extends Vue {
|
|
|
|
@Prop({ required: false, type: String }) uuid!: string;
|
|
|
|
|
2019-03-05 12:07:58 +01:00
|
|
|
loggedPerson: IPerson = new Person();
|
2019-02-22 16:54:01 +01:00
|
|
|
categories: string[] = Object.keys(Category);
|
2019-03-05 12:07:58 +01:00
|
|
|
event: IEvent = new EventModel();
|
2019-07-23 17:14:03 +02:00
|
|
|
pictureFile: File | null = null;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-06-07 17:19:30 +02:00
|
|
|
created() {
|
|
|
|
const now = new Date();
|
|
|
|
const end = new Date();
|
|
|
|
end.setUTCHours(now.getUTCHours() + 3);
|
|
|
|
this.event.beginsOn = now;
|
|
|
|
this.event.endsOn = end;
|
|
|
|
}
|
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
createEvent(e: Event) {
|
|
|
|
e.preventDefault();
|
2019-07-23 17:14:03 +02:00
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-03-22 10:57:14 +01:00
|
|
|
if (this.event.uuid === '') {
|
2019-05-22 14:12:11 +02:00
|
|
|
console.log('event', this.event);
|
2019-01-21 15:08:22 +01:00
|
|
|
this.$apollo
|
|
|
|
.mutate({
|
|
|
|
mutation: CREATE_EVENT,
|
2019-07-23 17:14:03 +02:00
|
|
|
variables: this.buildVariables(),
|
2019-01-21 15:08:22 +01:00
|
|
|
})
|
|
|
|
.then(data => {
|
2019-03-22 10:57:14 +01:00
|
|
|
console.log('event created', data);
|
2019-01-21 15:08:22 +01:00
|
|
|
this.$router.push({
|
2019-03-22 10:57:14 +01:00
|
|
|
name: 'Event',
|
|
|
|
params: { uuid: data.data.createEvent.uuid },
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2019-03-05 12:07:58 +01:00
|
|
|
console.error(error);
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.$apollo
|
|
|
|
.mutate({
|
2019-03-22 10:57:14 +01:00
|
|
|
mutation: EDIT_EVENT,
|
2019-01-21 15:08:22 +01:00
|
|
|
})
|
|
|
|
.then(data => {
|
|
|
|
this.$router.push({
|
2019-03-22 10:57:14 +01:00
|
|
|
name: 'Event',
|
|
|
|
params: { uuid: data.data.uuid },
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2019-04-03 17:29:03 +02:00
|
|
|
console.error(error);
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 17:14:03 +02:00
|
|
|
/**
|
|
|
|
* Build variables for Event GraphQL creation query
|
|
|
|
*/
|
|
|
|
private buildVariables() {
|
|
|
|
/**
|
|
|
|
* Transform general variables
|
|
|
|
*/
|
|
|
|
let pictureObj = {};
|
|
|
|
let obj = {
|
|
|
|
organizerActorId: this.loggedPerson.id,
|
|
|
|
beginsOn: this.event.beginsOn.toISOString(),
|
|
|
|
};
|
|
|
|
let res = Object.assign({}, this.event, obj);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform picture files
|
|
|
|
*/
|
|
|
|
if (this.pictureFile) {
|
|
|
|
pictureObj = {
|
|
|
|
picture: {
|
|
|
|
picture: {
|
|
|
|
name: this.pictureFile.name,
|
|
|
|
file: this.pictureFile,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.assign({}, res, pictureObj);
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
// getAddressData(addressData) {
|
|
|
|
// if (addressData !== null) {
|
|
|
|
// this.event.address = {
|
|
|
|
// geom: {
|
|
|
|
// data: {
|
|
|
|
// latitude: addressData.latitude,
|
|
|
|
// longitude: addressData.longitude
|
|
|
|
// },
|
|
|
|
// type: "point"
|
|
|
|
// },
|
|
|
|
// addressCountry: addressData.country,
|
|
|
|
// addressLocality: addressData.locality,
|
|
|
|
// addressRegion: addressData.administrative_area_level_1,
|
|
|
|
// postalCode: addressData.postal_code,
|
|
|
|
// streetAddress: `${addressData.street_number} ${addressData.route}`
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
</script>
|