2020-03-05 19:32:34 +01:00
|
|
|
import {ParticipantRole} from "@/types/event.model";
|
2019-09-20 18:22:03 +02:00
|
|
|
<template>
|
2020-02-18 08:57:00 +01:00
|
|
|
<main class="container">
|
|
|
|
<b-tabs type="is-boxed" v-if="event" v-model="activeTab">
|
|
|
|
<b-tab-item>
|
|
|
|
<template slot="header">
|
|
|
|
<b-icon icon="account-multiple" />
|
|
|
|
<span
|
|
|
|
>{{ $t("Participants") }} <b-tag rounded> {{ participantStats.going }} </b-tag>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<template>
|
|
|
|
<section v-if="participants && participants.total > 0">
|
|
|
|
<h2 class="title">{{ $t("Participants") }}</h2>
|
|
|
|
<ParticipationTable
|
|
|
|
:data="participants.elements"
|
|
|
|
:accept-participant="acceptParticipant"
|
|
|
|
:refuse-participant="refuseParticipant"
|
|
|
|
:showRole="true"
|
|
|
|
:total="participants.total"
|
|
|
|
:perPage="PARTICIPANTS_PER_PAGE"
|
|
|
|
@page-change="(page) => (participantPage = page)"
|
|
|
|
/>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
</b-tab-item>
|
|
|
|
<b-tab-item :disabled="participantStats.notApproved === 0">
|
|
|
|
<template slot="header">
|
|
|
|
<b-icon icon="account-multiple-plus" />
|
|
|
|
<span
|
|
|
|
>{{ $t("Requests") }} <b-tag rounded> {{ participantStats.notApproved }} </b-tag>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<template>
|
|
|
|
<section v-if="queue && queue.total > 0">
|
|
|
|
<h2 class="title">{{ $t("Waiting list") }}</h2>
|
|
|
|
<ParticipationTable
|
|
|
|
:data="queue.elements"
|
|
|
|
:accept-participant="acceptParticipant"
|
|
|
|
:refuse-participant="refuseParticipant"
|
|
|
|
:total="queue.total"
|
|
|
|
:perPage="PARTICIPANTS_PER_PAGE"
|
|
|
|
@page-change="(page) => (queuePage = page)"
|
|
|
|
/>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
</b-tab-item>
|
|
|
|
<b-tab-item :disabled="participantStats.rejected === 0">
|
|
|
|
<template slot="header">
|
|
|
|
<b-icon icon="account-multiple-minus"></b-icon>
|
|
|
|
<span
|
|
|
|
>{{ $t("Rejected") }} <b-tag rounded> {{ participantStats.rejected }} </b-tag>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<template>
|
|
|
|
<section v-if="rejected && rejected.total > 0">
|
|
|
|
<h2 class="title">{{ $t("Rejected participations") }}</h2>
|
|
|
|
<ParticipationTable
|
|
|
|
:data="rejected.elements"
|
|
|
|
:accept-participant="acceptParticipant"
|
|
|
|
:refuse-participant="refuseParticipant"
|
|
|
|
:total="rejected.total"
|
|
|
|
:perPage="PARTICIPANTS_PER_PAGE"
|
|
|
|
@page-change="(page) => (rejectedPage = page)"
|
|
|
|
/>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
</b-tab-item>
|
|
|
|
</b-tabs>
|
|
|
|
</main>
|
2019-09-20 18:22: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 {
|
|
|
|
IEvent,
|
|
|
|
IEventParticipantStats,
|
|
|
|
IParticipant,
|
|
|
|
Participant,
|
|
|
|
ParticipantRole,
|
|
|
|
} from "../../types/event.model";
|
|
|
|
import { PARTICIPANTS, UPDATE_PARTICIPANT } from "../../graphql/event";
|
|
|
|
import ParticipantCard from "../../components/Account/ParticipantCard.vue";
|
|
|
|
import { CURRENT_ACTOR_CLIENT } from "../../graphql/actor";
|
|
|
|
import { IPerson } from "../../types/actor";
|
|
|
|
import { CONFIG } from "../../graphql/config";
|
|
|
|
import { IConfig } from "../../types/config.model";
|
|
|
|
import ParticipationTable from "../../components/Event/ParticipationTable.vue";
|
|
|
|
import { Paginate } from "../../types/paginate";
|
2020-03-05 19:32:34 +01:00
|
|
|
|
|
|
|
const PARTICIPANTS_PER_PAGE = 20;
|
|
|
|
const MESSAGE_ELLIPSIS_LENGTH = 130;
|
2019-09-20 18:22:03 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
2020-03-05 19:32:34 +01:00
|
|
|
ParticipationTable,
|
2019-09-20 18:22:03 +02:00
|
|
|
ParticipantCard,
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
currentActor: {
|
|
|
|
query: CURRENT_ACTOR_CLIENT,
|
|
|
|
},
|
2019-12-20 13:04:34 +01:00
|
|
|
config: CONFIG,
|
2019-09-20 18:22:03 +02:00
|
|
|
event: {
|
|
|
|
query: PARTICIPANTS,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
uuid: this.eventId,
|
|
|
|
page: 1,
|
2020-03-05 19:32:34 +01:00
|
|
|
limit: PARTICIPANTS_PER_PAGE,
|
2019-09-20 18:22:03 +02:00
|
|
|
roles: [ParticipantRole.PARTICIPANT].join(),
|
2019-09-26 16:38:58 +02:00
|
|
|
actorId: this.currentActor.id,
|
2019-09-20 18:22:03 +02:00
|
|
|
};
|
|
|
|
},
|
2019-10-13 13:56:24 +02:00
|
|
|
skip() {
|
|
|
|
return !this.currentActor.id;
|
|
|
|
},
|
2019-09-20 18:22:03 +02:00
|
|
|
},
|
2020-03-05 19:32:34 +01:00
|
|
|
participants: {
|
2019-09-20 18:22:03 +02:00
|
|
|
query: PARTICIPANTS,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
uuid: this.eventId,
|
2020-03-05 19:32:34 +01:00
|
|
|
page: this.participantPage,
|
|
|
|
limit: PARTICIPANTS_PER_PAGE,
|
|
|
|
roles: [ParticipantRole.CREATOR, ParticipantRole.PARTICIPANT].join(),
|
2019-09-26 16:38:58 +02:00
|
|
|
actorId: this.currentActor.id,
|
2019-09-20 18:22:03 +02:00
|
|
|
};
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
update(data) {
|
|
|
|
return this.dataTransform(data);
|
|
|
|
},
|
2019-10-13 13:56:24 +02:00
|
|
|
skip() {
|
|
|
|
return !this.currentActor.id;
|
|
|
|
},
|
2019-09-20 18:22:03 +02:00
|
|
|
},
|
|
|
|
queue: {
|
|
|
|
query: PARTICIPANTS,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
uuid: this.eventId,
|
2020-03-05 19:32:34 +01:00
|
|
|
page: this.queuePage,
|
|
|
|
limit: PARTICIPANTS_PER_PAGE,
|
2019-09-20 18:22:03 +02:00
|
|
|
roles: [ParticipantRole.NOT_APPROVED].join(),
|
2019-09-26 16:38:58 +02:00
|
|
|
actorId: this.currentActor.id,
|
2019-09-20 18:22:03 +02:00
|
|
|
};
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
update(data) {
|
|
|
|
return this.dataTransform(data);
|
|
|
|
},
|
2019-10-13 13:56:24 +02:00
|
|
|
skip() {
|
|
|
|
return !this.currentActor.id;
|
|
|
|
},
|
2019-09-20 18:22:03 +02:00
|
|
|
},
|
2019-09-30 13:48:47 +02:00
|
|
|
rejected: {
|
|
|
|
query: PARTICIPANTS,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
uuid: this.eventId,
|
2020-03-05 19:32:34 +01:00
|
|
|
page: this.rejectedPage,
|
|
|
|
limit: PARTICIPANTS_PER_PAGE,
|
2019-09-30 13:48:47 +02:00
|
|
|
roles: [ParticipantRole.REJECTED].join(),
|
|
|
|
actorId: this.currentActor.id,
|
|
|
|
};
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
update(data) {
|
|
|
|
return this.dataTransform(data);
|
|
|
|
},
|
2019-10-13 13:56:24 +02:00
|
|
|
skip() {
|
|
|
|
return !this.currentActor.id;
|
|
|
|
},
|
2019-09-30 13:48:47 +02:00
|
|
|
},
|
2019-09-20 18:22:03 +02:00
|
|
|
},
|
2020-03-05 19:32:34 +01:00
|
|
|
filters: {
|
2020-02-18 08:57:00 +01:00
|
|
|
ellipsize: (text?: string) => text && text.substr(0, MESSAGE_ELLIPSIS_LENGTH).concat("…"),
|
2020-03-05 19:32:34 +01:00
|
|
|
},
|
2019-09-20 18:22:03 +02:00
|
|
|
})
|
|
|
|
export default class Participants extends Vue {
|
|
|
|
@Prop({ required: true }) eventId!: string;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
page = 1;
|
|
|
|
|
|
|
|
limit = 10;
|
2019-09-20 18:22:03 +02:00
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
participants!: Paginate<IParticipant>;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
participantPage = 1;
|
2020-03-05 19:32:34 +01:00
|
|
|
|
|
|
|
queue!: Paginate<IParticipant>;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
queuePage = 1;
|
2020-03-05 19:32:34 +01:00
|
|
|
|
|
|
|
rejected!: Paginate<IParticipant>;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
rejectedPage = 1;
|
2020-03-05 19:32:34 +01:00
|
|
|
|
2019-09-20 18:22:03 +02:00
|
|
|
event!: IEvent;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
config!: IConfig;
|
2019-09-20 18:22:03 +02:00
|
|
|
|
|
|
|
ParticipantRole = ParticipantRole;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-09-20 18:22:03 +02:00
|
|
|
currentActor!: IPerson;
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
hasMoreParticipants = false;
|
|
|
|
|
|
|
|
activeTab = 0;
|
2019-09-20 18:22:03 +02:00
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
PARTICIPANTS_PER_PAGE = PARTICIPANTS_PER_PAGE;
|
2019-09-20 18:22:03 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
dataTransform(data: { event: IEvent }): Paginate<Participant> {
|
2020-03-05 19:32:34 +01:00
|
|
|
return {
|
|
|
|
total: data.event.participants.total,
|
2020-02-18 08:57:00 +01:00
|
|
|
elements: data.event.participants.elements.map(
|
|
|
|
(participation: IParticipant) => new Participant(participation)
|
|
|
|
),
|
2020-03-05 19:32:34 +01:00
|
|
|
};
|
2019-09-20 18:22:03 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
get participantStats(): IEventParticipantStats | null {
|
|
|
|
if (!this.event) return null;
|
|
|
|
return this.event.participantStats;
|
2019-12-20 13:04:34 +01:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@Watch("participantStats", { deep: true })
|
2019-10-13 13:56:24 +02:00
|
|
|
watchParticipantStats(stats: IEventParticipantStats) {
|
|
|
|
if (!stats) return;
|
2020-02-18 08:57:00 +01:00
|
|
|
if (
|
|
|
|
(stats.notApproved === 0 && this.activeTab === 1) ||
|
|
|
|
(stats.rejected === 0 && this.activeTab === 2)
|
|
|
|
) {
|
2019-10-13 13:56:24 +02:00
|
|
|
this.activeTab = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-20 18:22:03 +02:00
|
|
|
loadMoreParticipants() {
|
|
|
|
this.page += 1;
|
|
|
|
this.$apollo.queries.participants.fetchMore({
|
|
|
|
// New variables
|
|
|
|
variables: {
|
|
|
|
page: this.page,
|
|
|
|
limit: this.limit,
|
|
|
|
},
|
|
|
|
// Transform the previous result with new data
|
|
|
|
updateQuery: (previousResult, { fetchMoreResult }) => {
|
|
|
|
const newParticipations = fetchMoreResult.event.participants;
|
|
|
|
this.hasMoreParticipants = newParticipations.length === this.limit;
|
|
|
|
|
|
|
|
return {
|
|
|
|
loggedUser: {
|
|
|
|
__typename: previousResult.event.__typename,
|
|
|
|
participations: [...previousResult.event.participants, ...newParticipations],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async acceptParticipant(participant: IParticipant) {
|
|
|
|
try {
|
|
|
|
const { data } = await this.$apollo.mutate({
|
2019-09-30 13:48:47 +02:00
|
|
|
mutation: UPDATE_PARTICIPANT,
|
2019-09-20 18:22:03 +02:00
|
|
|
variables: {
|
|
|
|
id: participant.id,
|
|
|
|
moderatorActorId: this.currentActor.id,
|
2019-09-30 13:48:47 +02:00
|
|
|
role: ParticipantRole.PARTICIPANT,
|
2019-09-20 18:22:03 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
if (data) {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.queue.elements = this.queue.elements.filter(
|
|
|
|
(participant) => participant.id !== data.updateParticipation.id
|
|
|
|
);
|
|
|
|
this.rejected.elements = this.rejected.elements.filter(
|
|
|
|
(participant) => participant.id !== data.updateParticipation.id
|
|
|
|
);
|
2019-10-25 17:43:37 +02:00
|
|
|
this.event.participantStats.going += 1;
|
2019-10-13 13:56:24 +02:00
|
|
|
if (participant.role === ParticipantRole.NOT_APPROVED) {
|
2019-10-25 17:43:37 +02:00
|
|
|
this.event.participantStats.notApproved -= 1;
|
2019-10-13 13:56:24 +02:00
|
|
|
}
|
|
|
|
if (participant.role === ParticipantRole.REJECTED) {
|
|
|
|
this.event.participantStats.rejected -= 1;
|
|
|
|
}
|
|
|
|
participant.role = ParticipantRole.PARTICIPANT;
|
2020-03-05 19:32:34 +01:00
|
|
|
this.event.participants.elements.push(participant);
|
2019-09-20 18:22:03 +02:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async refuseParticipant(participant: IParticipant) {
|
|
|
|
try {
|
|
|
|
const { data } = await this.$apollo.mutate({
|
2019-09-30 13:48:47 +02:00
|
|
|
mutation: UPDATE_PARTICIPANT,
|
2019-09-20 18:22:03 +02:00
|
|
|
variables: {
|
|
|
|
id: participant.id,
|
|
|
|
moderatorActorId: this.currentActor.id,
|
2019-09-30 13:48:47 +02:00
|
|
|
role: ParticipantRole.REJECTED,
|
2019-09-20 18:22:03 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
if (data) {
|
2020-03-05 19:32:34 +01:00
|
|
|
this.event.participants.elements = this.event.participants.elements.filter(
|
2020-02-18 08:57:00 +01:00
|
|
|
(participant) => participant.id !== data.updateParticipation.id
|
|
|
|
);
|
|
|
|
this.queue.elements = this.queue.elements.filter(
|
|
|
|
(participant) => participant.id !== data.updateParticipation.id
|
2020-03-05 19:32:34 +01:00
|
|
|
);
|
2019-10-13 13:56:24 +02:00
|
|
|
this.event.participantStats.rejected += 1;
|
|
|
|
if (participant.role === ParticipantRole.PARTICIPANT) {
|
2019-10-25 17:43:37 +02:00
|
|
|
this.event.participantStats.participant -= 1;
|
|
|
|
this.event.participantStats.going -= 1;
|
2019-10-13 13:56:24 +02:00
|
|
|
}
|
|
|
|
if (participant.role === ParticipantRole.NOT_APPROVED) {
|
2019-10-25 17:43:37 +02:00
|
|
|
this.event.participantStats.notApproved -= 1;
|
2019-10-13 13:56:24 +02:00
|
|
|
}
|
|
|
|
participant.role = ParticipantRole.REJECTED;
|
2020-02-18 08:57:00 +01:00
|
|
|
this.rejected.elements = this.rejected.elements.filter(
|
|
|
|
(participantIn) => participantIn.id !== participant.id
|
|
|
|
);
|
2020-03-05 19:32:34 +01:00
|
|
|
this.rejected.elements.push(participant);
|
2019-09-20 18:22:03 +02:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
|
|
<style lang="scss" scoped>
|
2020-02-18 08:57:00 +01:00
|
|
|
section {
|
|
|
|
padding: 1rem 0;
|
|
|
|
}
|
2020-06-17 15:54:24 +02:00
|
|
|
|
|
|
|
/deep/ .tabs.is-boxed {
|
|
|
|
a {
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
|
|
|
}
|
2019-09-20 18:22:03 +02:00
|
|
|
</style>
|
2019-10-09 17:03:35 +02:00
|
|
|
<style lang="scss">
|
2020-02-18 08:57:00 +01:00
|
|
|
nav.tabs li {
|
|
|
|
margin: 3rem 0 0;
|
|
|
|
}
|
2019-10-09 17:03:35 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.tab-content {
|
|
|
|
background: #fff;
|
|
|
|
}
|
2019-10-09 17:03:35 +02:00
|
|
|
</style>
|