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">
|
2019-09-02 14:35:50 +02:00
|
|
|
<translate v-if="isUpdate === false">Create a new event</translate>
|
|
|
|
<translate v-else>Update event {{ event.name }}</translate>
|
2019-01-21 15:08:22 +01:00
|
|
|
</h1>
|
2019-09-02 14:35:50 +02:00
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
<div v-if="$apollo.loading">Loading...</div>
|
2019-09-02 14:35:50 +02:00
|
|
|
|
2019-05-28 18:55:02 +02:00
|
|
|
<div class="columns is-centered" v-else>
|
2019-09-02 14:35:50 +02:00
|
|
|
<form class="column is-two-thirds-desktop" @submit="createOrUpdate">
|
2019-07-30 16:40:59 +02:00
|
|
|
<h2 class="subtitle">
|
|
|
|
<translate>
|
2019-09-02 14:35:50 +02:00
|
|
|
General information
|
2019-07-30 16:40:59 +02:00
|
|
|
</translate>
|
|
|
|
</h2>
|
2019-07-26 11:30:28 +02:00
|
|
|
<picture-upload v-model="pictureFile" />
|
|
|
|
|
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-07-26 11:30:28 +02:00
|
|
|
<tag-input v-model="event.tags" :data="tags" path="title" />
|
|
|
|
|
2019-07-30 10:35:29 +02:00
|
|
|
<address-auto-complete v-model="event.physicalAddress" />
|
|
|
|
|
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-08-07 16:51:48 +02:00
|
|
|
<!--<b-field :label="$gettext('Category')">
|
2019-01-21 15:08:22 +01:00
|
|
|
<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>
|
2019-08-07 16:51:48 +02:00
|
|
|
</b-field>-->
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-07-30 16:40:59 +02:00
|
|
|
<h2 class="subtitle">
|
|
|
|
<translate>
|
|
|
|
Visibility
|
|
|
|
</translate>
|
|
|
|
</h2>
|
|
|
|
<label class="label">{{ $gettext('Event visibility') }}</label>
|
|
|
|
<div class="field">
|
2019-09-02 14:35:50 +02:00
|
|
|
<b-radio v-model="event.visibility" name="name" :native-value="EventVisibility.PUBLIC">
|
2019-07-30 16:40:59 +02:00
|
|
|
<translate>Visible everywhere on the web (public)</translate>
|
|
|
|
</b-radio>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2019-09-02 14:35:50 +02:00
|
|
|
<b-radio v-model="event.visibility" name="name" :native-value="EventVisibility.PRIVATE">
|
2019-07-30 16:40:59 +02:00
|
|
|
<translate>Only accessible through link and search (private)</translate>
|
|
|
|
</b-radio>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button class="button is-primary">
|
2019-09-02 14:35:50 +02:00
|
|
|
|
|
|
|
<translate v-if="isUpdate === false">Create my event</translate>
|
|
|
|
<translate v-else>Update my event</translate>
|
2019-01-21 15:08:22 +01:00
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-09-02 14:35:50 +02:00
|
|
|
import { CREATE_EVENT, EDIT_EVENT, FETCH_EVENT } from '@/graphql/event';
|
|
|
|
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
|
|
|
import { EventModel, EventVisibility, IEvent } from '@/types/event.model';
|
2019-03-22 10:57:14 +01:00
|
|
|
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-07-26 11:30:28 +02:00
|
|
|
import TagInput from '@/components/Event/TagInput.vue';
|
|
|
|
import { TAGS } from '@/graphql/tags';
|
|
|
|
import { ITag } from '@/types/tag.model';
|
2019-07-30 10:35:29 +02:00
|
|
|
import AddressAutoComplete from '@/components/Event/AddressAutoComplete.vue';
|
2019-09-02 14:35:50 +02:00
|
|
|
import { buildFileFromIPicture, buildFileVariable } from '@/utils/image';
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-03-05 12:07:58 +01:00
|
|
|
@Component({
|
2019-07-30 10:35:29 +02:00
|
|
|
components: { AddressAutoComplete, TagInput, 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-07-26 11:30:28 +02:00
|
|
|
tags: {
|
|
|
|
query: TAGS,
|
|
|
|
},
|
2019-03-22 10:57:14 +01:00
|
|
|
},
|
2019-03-05 12:07:58 +01:00
|
|
|
})
|
2019-09-02 14:35:50 +02:00
|
|
|
export default class EditEvent extends Vue {
|
|
|
|
@Prop({ type: Boolean, default: false }) isUpdate!: boolean;
|
2019-01-21 15:08:22 +01:00
|
|
|
@Prop({ required: false, type: String }) uuid!: string;
|
|
|
|
|
2019-09-02 14:35:50 +02:00
|
|
|
eventId!: string | undefined;
|
|
|
|
|
|
|
|
loggedPerson = new Person();
|
|
|
|
event = new EventModel();
|
2019-07-23 17:14:03 +02:00
|
|
|
pictureFile: File | null = null;
|
2019-09-02 14:35:50 +02:00
|
|
|
|
2019-07-30 16:40:59 +02:00
|
|
|
EventVisibility = EventVisibility;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-09-02 14:35:50 +02:00
|
|
|
// categories: string[] = Object.keys(Category);
|
|
|
|
|
|
|
|
@Watch('$route.params.eventId', { immediate: true })
|
|
|
|
async onEventIdParamChanged (val: string) {
|
|
|
|
if (this.isUpdate !== true) return;
|
|
|
|
|
|
|
|
this.eventId = val;
|
|
|
|
|
|
|
|
if (this.eventId) {
|
|
|
|
this.event = await this.getEvent();
|
|
|
|
|
|
|
|
this.pictureFile = await buildFileFromIPicture(this.event.picture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-07 17:19:30 +02:00
|
|
|
created() {
|
|
|
|
const now = new Date();
|
|
|
|
const end = new Date();
|
|
|
|
end.setUTCHours(now.getUTCHours() + 3);
|
2019-09-02 14:35:50 +02:00
|
|
|
|
2019-06-07 17:19:30 +02:00
|
|
|
this.event.beginsOn = now;
|
|
|
|
this.event.endsOn = end;
|
|
|
|
}
|
|
|
|
|
2019-09-02 14:35:50 +02:00
|
|
|
createOrUpdate(e: Event) {
|
2019-01-21 15:08:22 +01:00
|
|
|
e.preventDefault();
|
2019-07-23 17:14:03 +02:00
|
|
|
|
2019-09-02 14:35:50 +02:00
|
|
|
if (this.eventId) return this.updateEvent();
|
|
|
|
|
|
|
|
return this.createEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
async createEvent() {
|
|
|
|
try {
|
|
|
|
const data = await this.$apollo.mutate({
|
|
|
|
mutation: CREATE_EVENT,
|
|
|
|
variables: this.buildVariables(),
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log('Event created', data);
|
|
|
|
|
|
|
|
this.$router.push({
|
|
|
|
name: 'Event',
|
|
|
|
params: { uuid: data.createEvent.uuid },
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateEvent() {
|
|
|
|
try {
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: EDIT_EVENT,
|
|
|
|
variables: this.buildVariables(),
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$router.push({
|
|
|
|
name: 'Event',
|
|
|
|
params: { uuid: this.eventId as string },
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
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() {
|
2019-07-26 11:30:28 +02:00
|
|
|
const obj = {
|
2019-07-23 17:14:03 +02:00
|
|
|
organizerActorId: this.loggedPerson.id,
|
|
|
|
beginsOn: this.event.beginsOn.toISOString(),
|
2019-08-13 08:43:37 +02:00
|
|
|
tags: this.event.tags.map((tag: ITag) => tag.title),
|
2019-07-23 17:14:03 +02:00
|
|
|
};
|
2019-08-13 08:43:37 +02:00
|
|
|
const res = Object.assign({}, this.event, obj);
|
2019-07-30 10:35:29 +02:00
|
|
|
|
|
|
|
if (this.event.physicalAddress) {
|
|
|
|
delete this.event.physicalAddress['__typename'];
|
|
|
|
}
|
2019-07-23 17:14:03 +02:00
|
|
|
|
2019-09-02 14:35:50 +02:00
|
|
|
const pictureObj = buildFileVariable(this.pictureFile, 'picture');
|
2019-07-23 17:14:03 +02:00
|
|
|
|
|
|
|
return Object.assign({}, res, pictureObj);
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
|
2019-09-02 14:35:50 +02:00
|
|
|
private async getEvent() {
|
|
|
|
const result = await this.$apollo.query({
|
|
|
|
query: FETCH_EVENT,
|
|
|
|
variables: {
|
|
|
|
uuid: this.eventId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return new EventModel(result.data.event);
|
|
|
|
}
|
|
|
|
|
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}`
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
2019-09-02 14:35:50 +02:00
|
|
|
</script>
|