import { Observable } from 'rxjs' ; import { Injectable , Inject } from '@angular/core' ; import { EventEmitter , PRIMARY_EVENT_EMITTER } from './event-emitter' ; import { UserKind , Preset , EventSourceKind } from './constants' ; import { ParticipationService } from '../services/participation.service' ; @ Injectable ( ) export class ActionCreator { constructor ( @ Inject ( PRIMARY_EVENT_EMITTER ) private dispatcher , private service ) { } changeUrl ( url ) { this . dispatcher . emit ( 'changeUrl' , url ) ; } checkUserKind ( userKind , checked ) { this . dispatcher . emit ( checked ? 'includeUserKind' : 'excludeUserKind' , userKind ) ; } changeWaitingNumber ( num ) { this . dispatcher . emit ( 'changeWaitingNumber' , num ) ; } changePreset ( preset ) { this . dispatcher . emit ( 'changePreset' , preset ) ; } uploadCustomBg ( url ) { this . dispatcher . emit ( 'uploadCustomBg' , url ) ; } updateUsers ( url , eventSourceKind ) { this . fetch ( url , eventSourceKind ) . subscribe ( ( ) => { const users = this . service . extractUsers ( ) ; const eventInfo = this . service . extractEventInfo ( ) ; this . dispatcher . emit ( 'updateEventInfo' , eventInfo ) ; this . dispatcher . emit ( 'updateUsers' , users ) ; this . dispatcher . emit ( 'fetchingUsers' , false ) ; } ) ; } fetch ( url , eventSourceKind ) { this . dispatcher . emit ( 'fetchingUsers' , true ) ; return this . service . fetch ( { url , type : eventSourceKind } ) ; } }