diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index e05d78b1..b9f73515 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -127,6 +127,10 @@ const routes: Routes = [ path: 'helfer-add', loadChildren: () => import('./pages/helfer/helfer-add/helfer-add.module').then( m => m.HelferAddPageModule) }, + { + path: 'helfer-detail', + loadChildren: () => import('./pages/helfer/helfer-detail/helfer-detail.module').then( m => m.HelferDetailPageModule) + }, ]; diff --git a/src/app/pages/championship/championship/championship.page.ts b/src/app/pages/championship/championship/championship.page.ts index ebd33c77..9b0dc3c2 100644 --- a/src/app/pages/championship/championship/championship.page.ts +++ b/src/app/pages/championship/championship/championship.page.ts @@ -90,153 +90,10 @@ export class ChampionshipPage implements OnInit { }); -/* - const TIMEOUT_DURATION = 1000; // 5 seconds, adjust as needed - - const teamGameList: Game[] = []; - const teamGamePastList: Game[] = []; - - // CURRENT GAMES - const teamGame$ = this.authService.getUser$().pipe( - take(1), - tap(() => console.log("Fetching user...")), - switchMap(user => { - console.log("Got user:", user); - this.user = user; - return this.fbService.getUserTeamRefs(user); - }), - tap(teams => console.log("Fetched teams:", teams)), - concatMap(teamsArray => from(teamsArray)), - tap(team => console.log("Processing team:", team.id)), - concatMap(team => this.championshipService.getTeamGamesRefs(team.id).pipe( - timeout(TIMEOUT_DURATION), // Adding timeout here - take(1), - tap(games => console.log(`Fetched games for team ${team.id}:`, games)), - switchMap(games => { - // Fetch attendees for each game and combine the results - const gameWithAttendees$ = games.map(game => - this.championshipService.getTeamGameAttendeesRef(team.id, game.id).pipe( - take(1), - map(attendees => { - const userAttendee = attendees.find(att => att.id == this.user.uid); - const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list - return { - ...game, - teamId: team.id, - status: status, - countAttendees: attendees.filter(att => att.status == true).length, - attendees: attendees - }; - }) - ) - ); - return forkJoin(gameWithAttendees$); - }), - catchError(error => { - if (error.name === 'TimeoutError') { - console.error(`Error fetching games for team ${team.id}:`); - return of([]); - } else { - // Handle other errors, maybe rethrow or return a default object - throw error; - } - }) - )), - tap(games => games.forEach(game => teamGameList.push(game))), - finalize(() => console.log("Team Game fetching completed")) - ); - - // PAST GAMES - const teamGamePast$ = this.authService.getUser$().pipe( - take(1), - tap(() => console.log("Fetching user...")), - switchMap(user => { - console.log("Got user:", user); - this.user = user; - return this.fbService.getUserTeamRefs(user); - }), - tap(teams => console.log("Fetched teams:", teams)), - concatMap(teamsArray => from(teamsArray)), - tap(team => console.log("Processing team:", team.id)), - concatMap(team => this.championshipService.getTeamGamesPastRefs(team.id).pipe( - timeout(TIMEOUT_DURATION), // Adding timeout here - take(1), - tap(games => console.log(`Fetched games for team ${team.id}:`, games)), - switchMap(games => { - // Fetch attendees for each game and combine the results - const gameWithAttendees$ = games.map(game => - this.championshipService.getTeamGameAttendeesRef(team.id, game.id).pipe( - take(1), - map(attendees => { - const userAttendee = attendees.find(att => att.id == this.user.uid); - console.log(">>>>" + JSON.stringify(userAttendee)) - const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list - return { - ...game, - teamId: team.id, - status: status, - countAttendees: attendees.filter(att => att.status == true).length, - attendees: attendees - }; - }) - ) - ); - return forkJoin(gameWithAttendees$); - }), - catchError(error => { - if (error.name === 'TimeoutError') { - console.error(`Error fetching games for team ${team.id}:`); - return of([]); - } else { - // Handle other errors, maybe rethrow or return a default object - throw error; - } - }) - )), - tap(games => games.forEach(game => teamGamePastList.push(game))), - finalize(() => console.log("Team Game fetching completed")) - ); - - // Use combineLatest to get results when both observables have emitted - this.subscription = combineLatest([teamGame$]).subscribe({ - next: () => { - this.gameList = [...teamGameList].sort((a, b):any => { - return a.dateTime.seconds > b.dateTime.seconds; - }); - this.gameList = this.gameList.filter((game, index, self) => - index === self.findIndex((t) => (t.id === game.id)) - ); - this.gameList$ = of(this.gameList); - console.log("Combined Game list created"); - }, - error: err => console.error('Error in the observable chain:', err) - }); - - this.subscriptionPast = combineLatest([teamGamePast$]).subscribe({ - next: () => { - this.gameListPast = [...teamGamePastList].sort((a, b):any => { - return a.dateTime.seconds < b.dateTime.seconds; - }); - this.gameListPast = this.gameListPast.filter((game, index, self) => - index === self.findIndex((t) => (t.id === game.id)) - ); - this.gameListPast$ = of(this.gameListPast); - console.log("Combined Game list PAST created"); - }, - error: err => console.error('Error in the observable chain:', err) - }); - -*/ - } ngOnDestroy(): void { - /* if (this.subscription) { - this.subscription.unsubscribe(); - } - if (this.subscriptionPast) { - this.subscriptionPast.unsubscribe(); - }*/ + } getTeamsWithRankingsForYear(year: string = '2023') { diff --git a/src/app/pages/event/events/events.page.html b/src/app/pages/event/events/events.page.html index ee296f3d..7302455d 100644 --- a/src/app/pages/event/events/events.page.html +++ b/src/app/pages/event/events/events.page.html @@ -22,7 +22,7 @@ - + Kommende Veranstaltungen @@ -105,9 +105,17 @@

--> + + + Kommende Veranstaltungen + + + keine Veranstaltungen gefunden + + - + Vergangene Veranstaltungen @@ -188,6 +196,14 @@

--> + + + Vergangene Veranstaltungen + + + keine Veranstaltungen gefunden + + diff --git a/src/app/pages/event/events/events.page.ts b/src/app/pages/event/events/events.page.ts index ab727d52..885951d2 100644 --- a/src/app/pages/event/events/events.page.ts +++ b/src/app/pages/event/events/events.page.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from "@angular/core"; +import { ChangeDetectorRef, Component, OnInit } from "@angular/core"; import { IonItemSliding, IonRouterOutlet, @@ -8,14 +8,14 @@ import { AlertController, } from "@ionic/angular"; import { User } from "@angular/fire/auth"; -import { Observable, Subscription, catchError, combineLatest, concatMap, defaultIfEmpty, finalize, forkJoin, from, map, of, switchMap, take, tap, timeout} from "rxjs"; +import { Observable, Subscription, catchError, combineLatest, concatMap, defaultIfEmpty, finalize, forkJoin, from, map, mergeMap, of, switchMap, take, tap, timeout} from "rxjs"; import { Veranstaltung } from "src/app/models/event"; import { AuthService } from "src/app/services/auth.service"; import { FirebaseService } from "src/app/services/firebase.service"; import { EventService } from "src/app/services/firebase/event.service"; -import { Club } from "src/app/models/club"; -import { Team } from "src/app/models/team"; import { EventAddPage } from "../event-add/event-add.page"; +import { Timestamp } from "firebase/firestore"; +import { EventDetailPage } from "../event-detail/event-detail.page"; @Component({ selector: "app-events", @@ -28,14 +28,8 @@ export class EventsPage implements OnInit { user$: Observable; user: User; - eventsList$: Observable; - eventsListPast$: Observable; - - eventsList: Veranstaltung[]; - eventsListPast: Veranstaltung[]; - - private subscription: Subscription; - private subscriptionPast: Subscription; + eventList$: Observable; + eventListPast$: Observable; filterList: any[] = []; filterValue: string = ""; @@ -43,156 +37,139 @@ export class EventsPage implements OnInit { constructor( public toastController: ToastController, private readonly routerOutlet: IonRouterOutlet, - private readonly modalController: ModalController, + private readonly modalCtrl: ModalController, private readonly authService: AuthService, private readonly fbService: FirebaseService, private readonly eventService: EventService, - private readonly alertCtrl: AlertController, - private readonly menuCtrl: MenuController + private readonly menuCtrl: MenuController, + private cdr: ChangeDetectorRef, ) { this.menuCtrl.enable(true, "menu"); } ngOnInit() { - const TIMEOUT_DURATION = 1000; // 5 seconds, adjust as needed + this.eventList$ = this.getClubEvent(); + this.eventList$.subscribe({ + next: (data) => { + console.log("EVENT Data received"); + this.cdr.detectChanges(); + }, + error: (err) => console.error("EVENT Error in subscription:", err), + complete: () => console.log("EVENT Observable completed") + }); - const teamEventList: Veranstaltung[] = []; - const teamEventPastList: Veranstaltung[] = []; - // CURRENT EventS - /*const teamEvent$ = this.authService.getUser$().pipe( + this.eventListPast$ = this.getClubEventPast(); + this.eventListPast$.subscribe({ + next: () => { + console.log("EVENT PAST Data received"); + this.cdr.detectChanges(); + }, + error: (err) => console.error("EVENT PAST Error in subscription:", err), + complete: () => console.log("EVENT PAST Observable completed") + }); + + } + getClubEvent() { + return this.authService.getUser$().pipe( take(1), - tap(() => console.log("Fetching user...")), - switchMap(user => { - console.log("Got user:", user); + tap(user=>{ this.user = user; - return this.fbService.getUserTeamRefs(user); }), - tap(teams => console.log("Fetched teams:", teams)), - concatMap(teamsArray => from(teamsArray)), - tap(team => console.log("Processing team:", team.id)), - concatMap(team => this.eventService.getTeamEventsRef(team.id).pipe( - timeout(TIMEOUT_DURATION), // Adding timeout here - take(1), - tap(events => console.log(`Fetched Events for team ${team.id}:`, events)), - switchMap(events => { - // Fetch attendees for each Event and combine the results - const EventWithAttendees$ = events.map(event => - this.eventService.getTeamEventsAttendeesRef(team.id, event.id).pipe( - take(1), - map(attendees => { - const userAttendee = attendees.find(att => att.id == this.user.uid); - const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list - return { - ...event, - teamId: team.id, - status: status, - countAttendees: attendees.filter(att => att.status == true).length, - attendees: attendees - }; - }) + switchMap(user => { + if (!user) return of([]); + return this.fbService.getUserClubRefs(user); + }), + tap(clubs => console.log("Teams:", clubs)), + mergeMap(teams => { + if (teams.length === 0) return of([]); + return combineLatest( + teams.map(team => + this.eventService.getClubEventsRef(team.id).pipe( + switchMap(clubEvents => { + if (clubEvents.length === 0) return of([]); + return combineLatest( + clubEvents.map(game => + this.eventService.getClubEventAttendeesRef(team.id, game.id).pipe( + map(attendees => { + const userAttendee = attendees.find(att => att.id == this.user.uid); + const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list + return ({...game, attendees, status: status, countAttendees: attendees.filter(att => att.status == true).length, teamId: team.id,}) + }), + catchError(() => of({ ...game, attendees: [], status: null, countAttendees: 0, teamId: team.id,})) // If error, return game with empty attendees + ) + ) + ); + }), + map(gamesWithAttendees => gamesWithAttendees), // Flatten games array for each team + catchError(() => of([])) // If error in fetching games, return empty array ) - ); - return forkJoin(EventWithAttendees$); - }), - catchError(error => { - if (error.name === 'TimeoutError') { - console.error(`Error fetching Events for team ${team.id}:`); - return of([]); - } else { - // Handle other errors, maybe rethrow or return a default object - throw error; - } - }) - )), - tap(events => events.forEach(event => teamEventList.push(event))), - finalize(() => console.log("Team Event fetching completed")) - );*/ - - // PAST EventS - /*const teamEventPast$ = this.authService.getUser$().pipe( + ) + ).pipe( + map(teamsGames => teamsGames.flat()), // Flatten to get all games across all teams + map(allGames => + allGames.sort((a, b) => Timestamp.fromMillis(a.dateTime).seconds - Timestamp.fromMillis(b.dateTime).seconds) // Sort games by date + ) + ); + }), + tap(results => console.log("Final results with all games:", results)), + catchError(err => { + console.error("Error in getClubEvent:", err); + return of([]); // Return an empty array on error + }) + ); + } + + getClubEventPast() { + return this.authService.getUser$().pipe( take(1), - tap(() => console.log("Fetching user...")), - switchMap(user => { - console.log("Got user:", user); + tap(user=>{ this.user = user; - return this.fbService.getUserTeamRefs(user); }), - tap(teams => console.log("Fetched teams:", teams)), - concatMap(teamsArray => from(teamsArray)), - tap(team => console.log("Processing team:", team.id)), - concatMap(team => this.eventService.getTeamEventsRefPast(team.id).pipe( - timeout(TIMEOUT_DURATION), // Adding timeout here - take(1), - tap(events => console.log(`Fetched Events for team ${team.id}:`, events)), - switchMap(events => { - // Fetch attendees for each Event and combine the results - const EventWithAttendees$ = events.map(event => - this.eventService.getTeamEventsAttendeesRef(team.id, event.id).pipe( - take(1), - map(attendees => { - const userAttendee = attendees.find(att => att.id == this.user.uid); - const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list - return { - ...event, - teamId: team.id, - status: status, - countAttendees: attendees.filter(att => att.status == true).length, - attendees: attendees - }; - }) + switchMap(user => { + if (!user) return of([]); + return this.fbService.getUserClubRefs(user); + }), + tap(clubs => console.log("Teams:", clubs)), + mergeMap(teams => { + if (teams.length === 0) return of([]); + return combineLatest( + teams.map(team => + this.eventService.getClubEventsRef(team.id).pipe( + switchMap(teamGames => { + if (teamGames.length === 0) return of([]); + return combineLatest( + teamGames.map(game => + this.eventService.getClubEventAttendeesRef(team.id, game.id).pipe( + map(attendees => { + const userAttendee = attendees.find(att => att.id == this.user.uid); + const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list + return ({...game, attendees, status: status, countAttendees: attendees.filter(att => att.status == true).length, teamId: team.id,}) + }), + catchError(() => of({ ...game, attendees: [], status: null, countAttendees: 0, teamId: team.id,})) // If error, return game with empty attendees + ) + ) + ); + }), + map(gamesWithAttendees => gamesWithAttendees), // Flatten games array for each team + catchError(() => of([])) // If error in fetching games, return empty array ) - ); - return forkJoin(EventWithAttendees$); - }), - catchError(error => { - if (error.name === 'TimeoutError') { - console.error(`Error fetching Events for team ${team.id}:`); - return of([]); - } else { - // Handle other errors, maybe rethrow or return a default object - throw error; - } - }) - )), - tap(events => events.forEach(event => teamEventPastList.push(event))), - finalize(() => console.log("Team Event fetching completed")) - );*/ - - // Use combineLatest to get results when both observables have emitted - /*this.subscription = combineLatest([teamEvent$]).subscribe({ - next: () => { - this.eventsList = [...teamEventList].sort((a, b):any => { - // return a.date.getTime() > b.date.getTime(); - return a.date.toMillis() < b.date.seconds ; - }); - this.eventsList = this.eventsList.filter((event, index, self) => - index === self.findIndex((t) => (t.id === event.id)) - ); - this.eventsList$ = of(this.eventsList); - console.log("Combined Event list created"); - }, - error: err => console.error('Error in the observable chain:', err) - }); - - this.subscriptionPast = combineLatest([teamEventPast$]).subscribe({ - next: () => { - this.eventsListPast = [...teamEventPastList].sort((a, b):any => { - // return a.date.getTime() > b.date.getTime(); - return a.date.seconds > b.date.seconds ; - }); - this.eventsListPast = this.eventsListPast.filter((event, index, self) => - index === self.findIndex((t) => (t.id === event.id)) + ) + ).pipe( + map(teamsGames => teamsGames.flat()), // Flatten to get all games across all teams + map(allGames => + allGames.sort((a, b) => Timestamp.fromMillis(a.dateTime).seconds - Timestamp.fromMillis(b.dateTime).seconds) // Sort games by date + ) ); - this.eventsListPast$ = of(this.eventsListPast); - console.log("Combined Event list PAST created"); - }, - error: err => console.error('Error in the observable chain:', err) - });*/ - + }), + tap(results => console.log("Final results with all games:", results)), + catchError(err => { + console.error("Error in getClubEventPast:", err); + return of([]); // Return an empty array on error + }) + ); } - async toggle(status: boolean, event: Veranstaltung) { console.log( `Set Status ${status} for user ${this.user.uid} and club ${event.clubId} and event ${event.id}` @@ -233,6 +210,7 @@ export class EventsPage implements OnInit { } async openFilter(ev: Event){ + /* let filterList = []; const clubs$ = this.authService.getUser$().pipe( @@ -258,26 +236,6 @@ export class EventsPage implements OnInit { finalize(() => console.log("Get Club completed")) ); - /* const teams$ = this.authService.getUser$().pipe( - take(1), - switchMap(user => this.fbService.getUserTeamRefs(user).pipe(take(1))), - concatMap(teamsArray => from(teamsArray)), - tap((team:Team)=>console.log(team.id)), - concatMap(team => - this.fbService.getTeamRef(team.id).pipe( - take(1), - defaultIfEmpty(null), // gibt null zurück, wenn kein Wert von getClubRef gesendet wird - map(result => [result]), - catchError(error => { - console.error('Error fetching TeamDetail:', error); - return of([]); - }) - ) - ), - tap(teamList => teamList.forEach(team => filterList.push(team))), - finalize(() => console.log("Get Teams completed")) - );*/ - this.subscription = forkJoin([clubs$]).subscribe({ next: () => { const alertInputs = []; @@ -320,12 +278,12 @@ export class EventsPage implements OnInit { }, error: err => console.error('Error in the observable chain:', err) }); - + */ } async openEventCreateModal() { // const presentingElement = await this.modalCtrl.getTop(); - const modal = await this.modalController.create({ + const modal = await this.modalCtrl.create({ component: EventAddPage, presentingElement: this.routerOutlet.nativeEl, canDismiss: true, @@ -341,5 +299,24 @@ export class EventsPage implements OnInit { if (role === "confirm") { } } + + async openEventDetailModal(event: Veranstaltung) { + // const presentingElement = await this.modalCtrl.getTop(); + const modal = await this.modalCtrl.create({ + component: EventDetailPage, + presentingElement: this.routerOutlet.nativeEl, + canDismiss: true, + showBackdrop: true, + componentProps: { + data: event, + }, + }); + modal.present(); + + const { data, role } = await modal.onWillDismiss(); + + if (role === "confirm") { + } + } } diff --git a/src/app/pages/helfer/helfer-detail/helfer-detail-routing.module.ts b/src/app/pages/helfer/helfer-detail/helfer-detail-routing.module.ts new file mode 100644 index 00000000..5f062d34 --- /dev/null +++ b/src/app/pages/helfer/helfer-detail/helfer-detail-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { HelferDetailPage } from './helfer-detail.page'; + +const routes: Routes = [ + { + path: '', + component: HelferDetailPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class HelferDetailPageRoutingModule {} diff --git a/src/app/pages/helfer/helfer-detail/helfer-detail.module.ts b/src/app/pages/helfer/helfer-detail/helfer-detail.module.ts new file mode 100644 index 00000000..875b0393 --- /dev/null +++ b/src/app/pages/helfer/helfer-detail/helfer-detail.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { HelferDetailPageRoutingModule } from './helfer-detail-routing.module'; + +import { HelferDetailPage } from './helfer-detail.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + HelferDetailPageRoutingModule + ], + declarations: [HelferDetailPage] +}) +export class HelferDetailPageModule {} diff --git a/src/app/pages/helfer/helfer-detail/helfer-detail.page.html b/src/app/pages/helfer/helfer-detail/helfer-detail.page.html new file mode 100644 index 00000000..83332fde --- /dev/null +++ b/src/app/pages/helfer/helfer-detail/helfer-detail.page.html @@ -0,0 +1,13 @@ + + + helfer-detail + + + + + + + helfer-detail + + + diff --git a/src/app/pages/helfer/helfer-detail/helfer-detail.page.scss b/src/app/pages/helfer/helfer-detail/helfer-detail.page.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/pages/helfer/helfer-detail/helfer-detail.page.spec.ts b/src/app/pages/helfer/helfer-detail/helfer-detail.page.spec.ts new file mode 100644 index 00000000..cd241edd --- /dev/null +++ b/src/app/pages/helfer/helfer-detail/helfer-detail.page.spec.ts @@ -0,0 +1,17 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { HelferDetailPage } from './helfer-detail.page'; + +describe('HelferDetailPage', () => { + let component: HelferDetailPage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + fixture = TestBed.createComponent(HelferDetailPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/helfer/helfer-detail/helfer-detail.page.ts b/src/app/pages/helfer/helfer-detail/helfer-detail.page.ts new file mode 100644 index 00000000..970a44f9 --- /dev/null +++ b/src/app/pages/helfer/helfer-detail/helfer-detail.page.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-helfer-detail', + templateUrl: './helfer-detail.page.html', + styleUrls: ['./helfer-detail.page.scss'], +}) +export class HelferDetailPage implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/pages/helfer/helfer/helfer.page.html b/src/app/pages/helfer/helfer/helfer.page.html index 73732f3f..52a83999 100644 --- a/src/app/pages/helfer/helfer/helfer.page.html +++ b/src/app/pages/helfer/helfer/helfer.page.html @@ -102,6 +102,14 @@

--> + + + Kommende Veranstaltungen + + + keine Veranstaltungen gefunden + + @@ -185,6 +193,14 @@

--> + + + Vergangene Veranstaltungen + + + keine Veranstaltungen gefunden + + diff --git a/src/app/pages/helfer/helfer/helfer.page.ts b/src/app/pages/helfer/helfer/helfer.page.ts index d9c18fe9..2f0200d7 100644 --- a/src/app/pages/helfer/helfer/helfer.page.ts +++ b/src/app/pages/helfer/helfer/helfer.page.ts @@ -8,15 +8,14 @@ import { AlertController, } from "@ionic/angular"; import { User } from "@angular/fire/auth"; -import { Observable, Subscription, catchError, combineLatest, concatMap, defaultIfEmpty, finalize, forkJoin, from, map, mergeMap, of, switchMap, take, tap, timeout} from "rxjs"; -import { HelferEvent, Veranstaltung } from "src/app/models/event"; +import { Observable, catchError, combineLatest, map, mergeMap, of, switchMap, take, tap} from "rxjs"; +import { Veranstaltung } from "src/app/models/event"; import { AuthService } from "src/app/services/auth.service"; import { FirebaseService } from "src/app/services/firebase.service"; import { EventService } from "src/app/services/firebase/event.service"; -import { Club } from "src/app/models/club"; -import { Team } from "src/app/models/team"; import { HelferAddPage } from '../helfer-add/helfer-add.page'; import { Timestamp } from 'firebase/firestore'; +import { HelferDetailPage } from '../helfer-detail/helfer-detail.page'; @Component({ selector: 'app-helfer', @@ -38,7 +37,7 @@ export class HelferPage implements OnInit { constructor( public toastController: ToastController, private readonly routerOutlet: IonRouterOutlet, - private readonly modalController: ModalController, + private readonly modalCtrl: ModalController, private readonly authService: AuthService, private readonly fbService: FirebaseService, private readonly eventService: EventService, @@ -73,86 +72,6 @@ export class HelferPage implements OnInit { error: (err) => console.error("HELFER PAST Error in subscription:", err), complete: () => console.log("HELFER PAST Observable completed") }); - - - - - - - - -/* - const TIMEOUT_DURATION = 1000; // 5 seconds, adjust as needed - - const helferEventList: HelferEvent[] = []; - const helferEventPastList: HelferEvent[] = []; - - // CURRENT EventS - const helferEvent$ = this.authService.getUser$().pipe( - take(1), - tap(() => console.log("Fetching user...")), - switchMap(user => { - console.log("Got user:", user); - this.user = user; - return this.fbService.getUserClubRefs(user); - }), - tap(clubs => console.log("Fetched clubs:", clubs)), - concatMap(clubArray => from(clubArray)), - tap(club => console.log("Processing club:", club.id)), - concatMap(club => this.eventService.getClubHelferEventRefs(club.id).pipe( - timeout(TIMEOUT_DURATION), // Adding timeout here - take(1), - tap(events => console.log(`Fetched Events for Club ${club.id}:`, events)), - switchMap(events => { - // Fetch attendees for each Event and combine the results - const eventWithAttendees$ = events.map(event => - this.eventService.getClubHelferEventAttendeesRef(club.id, event.id).pipe( - take(1), - map(attendees => { - const userAttendee = attendees.find(att => att.id == this.user.uid); - const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list - return { - ...event, - status: status, - countAttendees: attendees.filter(att => att.status == true).length, - attendees: attendees - }; - }) - ) - ); - return forkJoin(eventWithAttendees$); - }), - catchError(error => { - if (error.name === 'TimeoutError') { - console.error(`Error fetching Events for Club ${club.id}:`); - return of([]); - } else { - // Handle other errors, maybe rethrow or return a default object - throw error; - } - }) - )), - tap(events => events.forEach(event => helferEventList.push(event))), - finalize(() => console.log("Team Event fetching completed")) - ); - - - // Use combineLatest to get results when both observables have emitted - this.subscription = combineLatest([helferEvent$]).subscribe({ - next: () => { - this.eventsList = [...helferEventList].sort((a, b):any => { - // return a.date.getTime() > b.date.getTime(); - return a.date.toMillis() < b.date.seconds ; - }); - this.eventsList = this.eventsList.filter((event, index, self) => - index === self.findIndex((t) => (t.id === event.id)) - ); - this.eventsList$ = of(this.eventsList); - console.log("Combined Event list created"); - }, - error: err => console.error('Error in the observable chain:', err) - }); -*/ } getHelferEvent() { @@ -368,7 +287,7 @@ export class HelferPage implements OnInit { async openEventCreateModal() { // const presentingElement = await this.modalCtrl.getTop(); - const modal = await this.modalController.create({ + const modal = await this.modalCtrl.create({ component: HelferAddPage, presentingElement: this.routerOutlet.nativeEl, canDismiss: true, @@ -385,4 +304,25 @@ export class HelferPage implements OnInit { } } + async openEventDetailModal(event: Veranstaltung) { + // const presentingElement = await this.modalCtrl.getTop(); + const modal = await this.modalCtrl.create({ + component: HelferDetailPage, + presentingElement: this.routerOutlet.nativeEl, + canDismiss: true, + showBackdrop: true, + componentProps: { + data: event, + }, + }); + modal.present(); + + const { data, role } = await modal.onWillDismiss(); + + if (role === "confirm") { + } + } + + + } diff --git a/src/app/services/firebase/event.service.ts b/src/app/services/firebase/event.service.ts index e3f34a11..f2b00117 100644 --- a/src/app/services/firebase/event.service.ts +++ b/src/app/services/firebase/event.service.ts @@ -114,6 +114,13 @@ export class EventService { ); } + getClubEventAttendeesRef(clubId: string, eventId: string): Observable { + const attendeesRefList = collection(this.firestore, `club/${clubId}/events/${eventId}/attendees`); + return collectionData(attendeesRefList, { + idField: "id", + }) as unknown as Observable; + } + /* HELFER EVENTS */ getClubHelferEventRefs(clubId: string): Observable{ @@ -163,4 +170,7 @@ export class EventService { ); } + + + }