2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
|
|
|
<div class="columns is-centered">
|
|
|
|
<div class="column is-three-quarters">
|
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
|
|
|
<div class="card" v-if="event">
|
|
|
|
<div class="card-image">
|
|
|
|
<figure class="image is-4by3">
|
|
|
|
<img src="https://picsum.photos/600/400/">
|
|
|
|
</figure>
|
|
|
|
</div>
|
|
|
|
<div class="card-content">
|
2019-03-22 10:57:14 +01:00
|
|
|
<span>{{ event.beginsOn | formatDay }}</span>
|
2019-02-22 16:54:01 +01:00
|
|
|
<span class="tag is-primary">{{ event.category }}</span>
|
2019-01-21 15:08:22 +01:00
|
|
|
<h1 class="title">{{ event.title }}</h1>
|
|
|
|
<router-link
|
|
|
|
:to="{name: 'Profile', params: { name: event.organizerActor.preferredUsername } }"
|
|
|
|
>
|
|
|
|
<figure v-if="event.organizerActor.avatarUrl">
|
|
|
|
<img :src="event.organizerActor.avatarUrl">
|
|
|
|
</figure>
|
|
|
|
</router-link>
|
|
|
|
<span
|
|
|
|
v-if="event.organizerActor"
|
|
|
|
>Organisé par {{ event.organizerActor.name ? event.organizerActor.name : event.organizerActor.preferredUsername }}</span>
|
|
|
|
<div class="field has-addons">
|
|
|
|
<p class="control">
|
|
|
|
<router-link
|
|
|
|
v-if="actorIsOrganizer()"
|
|
|
|
class="button"
|
|
|
|
:to="{ name: 'EditEvent', params: {uuid: event.uuid}}"
|
|
|
|
>
|
|
|
|
<translate>Edit</translate>
|
|
|
|
</router-link>
|
|
|
|
</p>
|
|
|
|
<p class="control">
|
|
|
|
<a class="button" @click="downloadIcsEvent()">
|
|
|
|
<translate>Download</translate>
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
<p class="control">
|
|
|
|
<a class="button is-danger" v-if="actorIsOrganizer()" @click="deleteEvent()">
|
|
|
|
<translate>Delete</translate>
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2019-03-22 10:57:14 +01:00
|
|
|
<span>{{ event.beginsOn | formatDate }} - {{ event.endsOn | formatDate }}</span>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
<p v-if="actorIsOrganizer()">
|
2019-02-25 17:20:06 +01:00
|
|
|
<translate>You are an organizer.</translate>
|
2019-01-21 15:08:22 +01:00
|
|
|
</p>
|
|
|
|
<div v-else>
|
|
|
|
<p v-if="actorIsParticipant()">
|
2019-02-25 17:20:06 +01:00
|
|
|
<translate>You announced that you're going to this event.</translate>
|
2019-01-21 15:08:22 +01:00
|
|
|
</p>
|
|
|
|
<p v-else>
|
2019-02-25 17:20:06 +01:00
|
|
|
<translate>Are you going to this event?</translate><br />
|
|
|
|
<span>
|
|
|
|
<translate
|
|
|
|
:translate-n="event.participants.length"
|
|
|
|
translate-plural="%{event.participants.length} persons are going"
|
|
|
|
>
|
|
|
|
One person is going.
|
|
|
|
</translate>
|
|
|
|
</span>
|
2019-01-21 15:08:22 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div v-if="!actorIsOrganizer()">
|
|
|
|
<a v-if="!actorIsParticipant()" @click="joinEvent" class="button">
|
|
|
|
<translate>Join</translate>
|
|
|
|
</a>
|
2019-02-07 16:37:40 +01:00
|
|
|
<a v-if="actorIsParticipant()" @click="leaveEvent" class="button">Leave</a>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
<h2 class="subtitle">Details</h2>
|
|
|
|
<p v-if="event.description">
|
2019-02-25 17:20:06 +01:00
|
|
|
<vue-simple-markdown :source="event.description"></vue-simple-markdown>
|
2019-01-21 15:08:22 +01:00
|
|
|
</p>
|
|
|
|
<h2 class="subtitle">Participants</h2>
|
|
|
|
<span v-if="event.participants.length === 0">No participants yet.</span>
|
|
|
|
<div class="columns">
|
|
|
|
<router-link
|
|
|
|
class="card column"
|
|
|
|
v-for="participant in event.participants"
|
|
|
|
:key="participant.preferredUsername"
|
|
|
|
:to="{name: 'Profile', params: { name: participant.actor.preferredUsername }}"
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<figure>
|
|
|
|
<img v-if="!participant.actor.avatarUrl" src="https://picsum.photos/125/125/">
|
|
|
|
<img v-else :src="participant.actor.avatarUrl">
|
|
|
|
</figure>
|
|
|
|
<span>{{ participant.actor.preferredUsername }}</span>
|
|
|
|
</div>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-03-22 10:57:14 +01:00
|
|
|
import { DELETE_EVENT, FETCH_EVENT, JOIN_EVENT, LEAVE_EVENT } from '@/graphql/event';
|
2019-02-22 11:24:41 +01:00
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
|
|
|
import { LOGGED_PERSON } from '@/graphql/actor';
|
|
|
|
import { IEvent, IParticipant } from '@/types/event.model';
|
|
|
|
import { IPerson } from '@/types/actor.model';
|
2019-02-25 17:20:06 +01:00
|
|
|
import { RouteName } from '@/router';
|
|
|
|
import 'vue-simple-markdown/dist/vue-simple-markdown.css';
|
2019-01-21 15:08:22 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
event: {
|
|
|
|
query: FETCH_EVENT,
|
|
|
|
variables() {
|
|
|
|
return {
|
2019-03-22 10:57:14 +01:00
|
|
|
uuid: this.uuid,
|
2019-01-21 15:08:22 +01:00
|
|
|
};
|
2019-03-22 10:57:14 +01:00
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
},
|
|
|
|
loggedPerson: {
|
2019-03-22 10:57:14 +01:00
|
|
|
query: LOGGED_PERSON,
|
|
|
|
},
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
})
|
|
|
|
export default class Event extends Vue {
|
|
|
|
@Prop({ type: String, required: true }) uuid!: string;
|
|
|
|
|
|
|
|
event!: IEvent;
|
|
|
|
loggedPerson!: IPerson;
|
|
|
|
validationSent: boolean = false;
|
|
|
|
|
2019-02-22 11:24:41 +01:00
|
|
|
async deleteEvent() {
|
2019-01-21 15:08:22 +01:00
|
|
|
const router = this.$router;
|
2019-02-22 11:24:41 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await this.$apollo.mutate<IParticipant>({
|
|
|
|
mutation: DELETE_EVENT,
|
|
|
|
variables: {
|
|
|
|
id: this.event.id,
|
|
|
|
actorId: this.loggedPerson.id,
|
2019-03-22 10:57:14 +01:00
|
|
|
},
|
2019-02-22 11:24:41 +01:00
|
|
|
});
|
|
|
|
|
2019-03-22 10:57:14 +01:00
|
|
|
router.push({ name: RouteName.EVENT });
|
2019-02-22 11:24:41 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async joinEvent() {
|
|
|
|
try {
|
2019-02-22 11:24:41 +01:00
|
|
|
await this.$apollo.mutate<IParticipant>({
|
|
|
|
mutation: JOIN_EVENT,
|
|
|
|
variables: {
|
2019-02-25 17:20:06 +01:00
|
|
|
eventId: this.event.id,
|
2019-02-22 11:24:41 +01:00
|
|
|
actorId: this.loggedPerson.id,
|
|
|
|
},
|
|
|
|
update: (store, { data: { joinEvent } }) => {
|
|
|
|
const event = store.readQuery<IEvent>({ query: FETCH_EVENT });
|
|
|
|
if (event === null) {
|
2019-02-25 17:20:06 +01:00
|
|
|
console.error('Cannot update event participant cache, because of null value.');
|
2019-03-22 10:57:14 +01:00
|
|
|
return;
|
2019-02-22 11:24:41 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 10:57:14 +01:00
|
|
|
event.participants = event.participants.concat([joinEvent]);
|
2019-02-22 11:24:41 +01:00
|
|
|
|
|
|
|
store.writeQuery({ query: FETCH_EVENT, data: event });
|
2019-03-22 10:57:14 +01:00
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 11:24:41 +01:00
|
|
|
async leaveEvent() {
|
|
|
|
try {
|
|
|
|
await this.$apollo.mutate<IParticipant>({
|
|
|
|
mutation: LEAVE_EVENT,
|
|
|
|
variables: {
|
2019-02-25 17:20:06 +01:00
|
|
|
eventId: this.event.id,
|
2019-02-22 11:24:41 +01:00
|
|
|
actorId: this.loggedPerson.id,
|
|
|
|
},
|
|
|
|
update: (store, { data: { leaveEvent } }) => {
|
|
|
|
const event = store.readQuery<IEvent>({ query: FETCH_EVENT });
|
|
|
|
if (event === null) {
|
|
|
|
console.error('Cannot update event participant cache, because of null value.');
|
2019-03-22 10:57:14 +01:00
|
|
|
return;
|
2019-02-22 11:24:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
event.participants = event.participants
|
|
|
|
.filter(p => p.actor.id !== leaveEvent.actor.id);
|
|
|
|
|
|
|
|
store.writeQuery({ query: FETCH_EVENT, data: event });
|
2019-03-22 10:57:14 +01:00
|
|
|
},
|
2019-02-22 11:24:41 +01:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
downloadIcsEvent() {
|
|
|
|
// FIXME: remove eventFetch
|
|
|
|
// eventFetch(`/events/${this.uuid}/ics`, this.$store, { responseType: 'arraybuffer' })
|
|
|
|
// .then(response => response.text())
|
|
|
|
// .then((response) => {
|
|
|
|
// const blob = new Blob([ response ], { type: 'text/calendar' });
|
|
|
|
// const link = document.createElement('a');
|
|
|
|
// link.href = window.URL.createObjectURL(blob);
|
|
|
|
// link.download = `${this.event.title}.ics`;
|
|
|
|
// document.body.appendChild(link);
|
|
|
|
// link.click();
|
|
|
|
// document.body.removeChild(link);
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
|
|
|
actorIsParticipant() {
|
2019-02-22 11:24:41 +01:00
|
|
|
if (this.actorIsOrganizer()) return true;
|
|
|
|
|
|
|
|
return this.loggedPerson &&
|
|
|
|
this.event.participants
|
|
|
|
.some(participant => participant.actor.id === this.loggedPerson.id);
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
2019-02-22 11:24:41 +01:00
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
actorIsOrganizer() {
|
2019-02-22 11:24:41 +01:00
|
|
|
return this.loggedPerson &&
|
|
|
|
this.loggedPerson.id === this.event.organizerActor.id;
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|