2019-09-20 16:22:03 +00:00
< template >
< main class = "container" >
2019-10-13 11:56:24 +00:00
< b -tabs type = "is-boxed" v-if ="event" v-model="activeTab" >
2019-09-20 16:22:03 +00:00
< b -tab -item >
< template slot = "header" >
2019-12-20 12:04:34 +00:00
< b -icon icon = "account-multiple" / >
2019-10-25 15:43:37 +00:00
< span > { { $t ( 'Participants' ) } } < b -tag rounded > { { participantStats . going } } < / b - t a g > < / s p a n >
2019-09-20 16:22:03 +00:00
< / template >
2019-10-09 15:03:35 +00:00
< template >
< section v-if ="participantsAndCreators.length > 0" >
< h2 class = "title" > { { $t ( 'Participants' ) } } < / h2 >
2019-12-20 12:04:34 +00:00
< p v-if ="confirmedAnonymousParticipantsCountCount > 1" >
{ { $tc ( 'And no anonymous participations|And one anonymous participation|And {count} anonymous participations' , confirmedAnonymousParticipantsCountCount , { count : confirmedAnonymousParticipantsCountCount } ) } }
< / p >
2019-10-17 07:41:52 +00:00
< div class = "columns is-multiline" >
2019-10-09 15:03:35 +00:00
< div class = "column is-one-quarter-desktop" v-for ="participant in participantsAndCreators" :key="participant.actor.id" >
< participant -card
2019-12-20 12:04:34 +00:00
v - if = "participant.actor.id !== config.anonymous.actorId"
2019-10-09 15:03:35 +00:00
: participant = "participant"
: accept = "acceptParticipant"
: reject = "refuseParticipant"
: exclude = "refuseParticipant"
/ >
< / div >
< / div >
< / section >
< / template >
2019-09-20 16:22:03 +00:00
< / b - t a b - i t e m >
2019-10-25 15:43:37 +00:00
< b -tab -item : disabled = "participantStats.notApproved === 0" >
2019-09-20 16:22:03 +00:00
< template slot = "header" >
2019-12-20 12:04:34 +00:00
< b -icon icon = "account-multiple-plus" / >
2019-10-25 15:43:37 +00:00
< span > { { $t ( 'Requests' ) } } < b -tag rounded > { { participantStats . notApproved } } < / b - t a g > < / s p a n >
2019-09-20 16:22:03 +00:00
< / template >
2019-10-09 15:03:35 +00:00
< template >
< section v-if ="queue.length > 0" >
< h2 class = "title" > { { $t ( 'Waiting list' ) } } < / h2 >
< div class = "columns" >
< div class = "column is-one-quarter-desktop" v-for ="participant in queue" :key="participant.actor.id" >
< participant -card
: participant = "participant"
: accept = "acceptParticipant"
: reject = "refuseParticipant"
: exclude = "refuseParticipant"
/ >
< / div >
< / div >
< / section >
< / template >
2019-09-20 16:22:03 +00:00
< / b - t a b - i t e m >
2019-10-09 15:03:35 +00:00
< b -tab -item : disabled = "participantStats.rejected === 0" >
2019-09-30 11:48:47 +00:00
< template slot = "header" >
2019-10-09 15:03:35 +00:00
< b -icon icon = "account-multiple-minus" > < / b - i c o n >
2019-09-30 11:48:47 +00:00
< span > { { $t ( 'Rejected' ) } } < b -tag rounded > { { participantStats . rejected } } < / b - t a g > < / s p a n >
< / template >
2019-10-09 15:03:35 +00:00
< template >
< section v-if ="rejected.length > 0" >
< h2 class = "title" > { { $t ( 'Rejected participations' ) } } < / h2 >
< div class = "columns" >
< div class = "column is-one-quarter-desktop" v-for ="participant in rejected" :key="participant.actor.id" >
< participant -card
: participant = "participant"
: accept = "acceptParticipant"
: reject = "refuseParticipant"
: exclude = "refuseParticipant"
/ >
< / div >
< / div >
< / section >
< / template >
2019-09-30 11:48:47 +00:00
< / b - t a b - i t e m >
2019-09-20 16:22:03 +00:00
< / b - t a b s >
< / main >
< / template >
< script lang = "ts" >
2019-10-13 11:56:24 +00: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' ;
2019-09-20 16:22:03 +00:00
import ParticipantCard from '@/components/Account/ParticipantCard.vue' ;
import { CURRENT _ACTOR _CLIENT } from '@/graphql/actor' ;
import { IPerson } from '@/types/actor' ;
2019-12-20 12:04:34 +00:00
import { CONFIG } from '@/graphql/config' ;
import { IConfig } from '@/types/config.model' ;
2019-09-20 16:22:03 +00:00
@ Component ( {
components : {
ParticipantCard ,
} ,
apollo : {
currentActor : {
query : CURRENT _ACTOR _CLIENT ,
} ,
2019-12-20 12:04:34 +00:00
config : CONFIG ,
2019-09-20 16:22:03 +00:00
event : {
query : PARTICIPANTS ,
variables ( ) {
return {
uuid : this . eventId ,
page : 1 ,
limit : 10 ,
roles : [ ParticipantRole . PARTICIPANT ] . join ( ) ,
2019-09-26 14:38:58 +00:00
actorId : this . currentActor . id ,
2019-09-20 16:22:03 +00:00
} ;
} ,
2019-10-13 11:56:24 +00:00
skip ( ) {
return ! this . currentActor . id ;
} ,
2019-09-20 16:22:03 +00:00
} ,
organizers : {
query : PARTICIPANTS ,
variables ( ) {
return {
uuid : this . eventId ,
page : 1 ,
limit : 20 ,
roles : [ ParticipantRole . CREATOR ] . join ( ) ,
2019-09-26 14:38:58 +00:00
actorId : this . currentActor . id ,
2019-09-20 16:22:03 +00:00
} ;
} ,
update : data => data . event . participants . map ( participation => new Participant ( participation ) ) ,
2019-10-13 11:56:24 +00:00
skip ( ) {
return ! this . currentActor . id ;
} ,
2019-09-20 16:22:03 +00:00
} ,
queue : {
query : PARTICIPANTS ,
variables ( ) {
return {
uuid : this . eventId ,
page : 1 ,
limit : 20 ,
roles : [ ParticipantRole . NOT _APPROVED ] . join ( ) ,
2019-09-26 14:38:58 +00:00
actorId : this . currentActor . id ,
2019-09-20 16:22:03 +00:00
} ;
} ,
update : data => data . event . participants . map ( participation => new Participant ( participation ) ) ,
2019-10-13 11:56:24 +00:00
skip ( ) {
return ! this . currentActor . id ;
} ,
2019-09-20 16:22:03 +00:00
} ,
2019-09-30 11:48:47 +00:00
rejected : {
query : PARTICIPANTS ,
variables ( ) {
return {
uuid : this . eventId ,
page : 1 ,
limit : 20 ,
roles : [ ParticipantRole . REJECTED ] . join ( ) ,
actorId : this . currentActor . id ,
} ;
} ,
update : data => data . event . participants . map ( participation => new Participant ( participation ) ) ,
2019-10-13 11:56:24 +00:00
skip ( ) {
return ! this . currentActor . id ;
} ,
2019-09-30 11:48:47 +00:00
} ,
2019-09-20 16:22:03 +00:00
} ,
} )
export default class Participants extends Vue {
@ Prop ( { required : true } ) eventId ! : string ;
page : number = 1 ;
limit : number = 10 ;
organizers : IParticipant [ ] = [ ] ;
queue : IParticipant [ ] = [ ] ;
2019-09-30 11:48:47 +00:00
rejected : IParticipant [ ] = [ ] ;
2019-09-20 16:22:03 +00:00
event ! : IEvent ;
2019-12-20 12:04:34 +00:00
config ! : IConfig ;
2019-09-20 16:22:03 +00:00
ParticipantRole = ParticipantRole ;
currentActor ! : IPerson ;
hasMoreParticipants : boolean = false ;
2019-10-13 11:56:24 +00:00
activeTab : number = 0 ;
2019-09-20 16:22:03 +00:00
2019-10-13 11:56:24 +00:00
get participantStats ( ) : IEventParticipantStats | null {
if ( ! this . event ) return null ;
2019-09-20 16:22:03 +00:00
return this . event . participantStats ;
}
get participantsAndCreators ( ) : IParticipant [ ] {
if ( this . event ) {
2019-10-13 11:56:24 +00:00
return [ ... this . organizers , ... this . event . participants ]
. filter ( participant => [ ParticipantRole . PARTICIPANT , ParticipantRole . CREATOR ] . includes ( participant . role ) ) ;
2019-09-20 16:22:03 +00:00
}
return [ ] ;
}
2019-12-20 12:04:34 +00:00
get confirmedAnonymousParticipantsCountCount ( ) : number {
return this . participantsAndCreators . filter ( ( { actor : { id } } ) => id === this . config . anonymous . actorId ) . length ;
}
2019-10-13 11:56:24 +00:00
@ Watch ( 'participantStats' , { deep : true } )
watchParticipantStats ( stats : IEventParticipantStats ) {
if ( ! stats ) return ;
2019-10-25 15:43:37 +00:00
if ( ( stats . notApproved === 0 && this . activeTab === 1 ) || stats . rejected === 0 && this . activeTab === 2 ) {
2019-10-13 11:56:24 +00:00
this . activeTab = 0 ;
}
}
2019-09-20 16:22:03 +00: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 11:48:47 +00:00
mutation : UPDATE _PARTICIPANT ,
2019-09-20 16:22:03 +00:00
variables : {
id : participant . id ,
moderatorActorId : this . currentActor . id ,
2019-09-30 11:48:47 +00:00
role : ParticipantRole . PARTICIPANT ,
2019-09-20 16:22:03 +00:00
} ,
} ) ;
if ( data ) {
2019-10-13 11:56:24 +00:00
this . queue = this . queue . filter ( participant => participant . id !== data . updateParticipation . id ) ;
this . rejected = this . rejected . filter ( participant => participant . id !== data . updateParticipation . id ) ;
2019-10-25 15:43:37 +00:00
this . event . participantStats . going += 1 ;
2019-10-13 11:56:24 +00:00
if ( participant . role === ParticipantRole . NOT _APPROVED ) {
2019-10-25 15:43:37 +00:00
this . event . participantStats . notApproved -= 1 ;
2019-10-13 11:56:24 +00:00
}
if ( participant . role === ParticipantRole . REJECTED ) {
this . event . participantStats . rejected -= 1 ;
}
participant . role = ParticipantRole . PARTICIPANT ;
this . event . participants . push ( participant ) ;
2019-09-20 16:22:03 +00:00
}
} catch ( e ) {
console . error ( e ) ;
}
}
async refuseParticipant ( participant : IParticipant ) {
try {
const { data } = await this . $apollo . mutate ( {
2019-09-30 11:48:47 +00:00
mutation : UPDATE _PARTICIPANT ,
2019-09-20 16:22:03 +00:00
variables : {
id : participant . id ,
moderatorActorId : this . currentActor . id ,
2019-09-30 11:48:47 +00:00
role : ParticipantRole . REJECTED ,
2019-09-20 16:22:03 +00:00
} ,
} ) ;
if ( data ) {
2019-10-13 11:56:24 +00:00
this . event . participants = this . event . participants . filter ( participant => participant . id !== data . updateParticipation . id ) ;
this . queue = this . queue . filter ( participant => participant . id !== data . updateParticipation . id ) ;
this . event . participantStats . rejected += 1 ;
if ( participant . role === ParticipantRole . PARTICIPANT ) {
2019-10-25 15:43:37 +00:00
this . event . participantStats . participant -= 1 ;
this . event . participantStats . going -= 1 ;
2019-10-13 11:56:24 +00:00
}
if ( participant . role === ParticipantRole . NOT _APPROVED ) {
2019-10-25 15:43:37 +00:00
this . event . participantStats . notApproved -= 1 ;
2019-10-13 11:56:24 +00:00
}
participant . role = ParticipantRole . REJECTED ;
this . rejected = this . rejected . filter ( participantIn => participantIn . id !== participant . id ) ;
2019-09-30 11:48:47 +00:00
this . rejected . push ( participant ) ;
2019-09-20 16:22:03 +00:00
}
} catch ( e ) {
console . error ( e ) ;
}
}
}
< / script >
<!-- Add "scoped" attribute to limit CSS to this component only -- >
< style lang = "scss" scoped >
section {
2019-10-09 15:03:35 +00:00
padding : 1 rem 0 ;
2019-09-20 16:22:03 +00:00
}
< / style >
2019-10-09 15:03:35 +00:00
< style lang = "scss" >
nav . tabs li {
margin : 3 rem 0 0 ;
}
. tab - content {
background : # fff ;
}
< / style >