diff --git a/src/app/pages/championship/championship/championship.page.ts b/src/app/pages/championship/championship/championship.page.ts index a53dd9ad..49356d1d 100644 --- a/src/app/pages/championship/championship/championship.page.ts +++ b/src/app/pages/championship/championship/championship.page.ts @@ -10,7 +10,25 @@ import { ToastController, } from "@ionic/angular"; import { User } from "@angular/fire/auth"; -import { Observable, Subscription, catchError, combineLatest, concatMap, defaultIfEmpty, finalize, forkJoin, from, lastValueFrom, map, mergeMap, of, switchMap, take, tap, timeout } from "rxjs"; +import { + Observable, + Subscription, + catchError, + combineLatest, + concatMap, + defaultIfEmpty, + finalize, + forkJoin, + from, + lastValueFrom, + map, + mergeMap, + of, + switchMap, + take, + tap, + timeout, +} from "rxjs"; import { Game } from "src/app/models/game"; import { AuthService } from "src/app/services/auth.service"; import { FirebaseService } from "src/app/services/firebase.service"; @@ -43,7 +61,7 @@ export class ChampionshipPage implements OnInit { filterList: any[] = []; filterValue: string = ""; - teamRankings$: Observable;; + teamRankings$: Observable; constructor( public toastController: ToastController, @@ -56,14 +74,12 @@ export class ChampionshipPage implements OnInit { private readonly menuCtrl: MenuController, private cdr: ChangeDetectorRef, private navCtrl: NavController, - private router: Router, - private translate: TranslateService, + private translate: TranslateService ) { this.menuCtrl.enable(true, "menu"); } ngOnInit() { - this.teamRankings$ = this.getTeamsWithRankingsForYear("2023"); this.teamRankings$.subscribe({ next: () => { @@ -71,7 +87,7 @@ export class ChampionshipPage implements OnInit { this.cdr.detectChanges(); }, error: (err) => console.error("RANKING Error in subscription:", err), - complete: () => console.log("RANKING Observable completed") + complete: () => console.log("RANKING Observable completed"), }); this.gameList$ = this.getTeamGamesUpcoming(); @@ -81,10 +97,9 @@ export class ChampionshipPage implements OnInit { this.cdr.detectChanges(); }, error: (err) => console.error("GAMES Error in subscription:", err), - complete: () => console.log("GAMES Observable completed") + complete: () => console.log("GAMES Observable completed"), }); - this.gameListPast$ = this.getTeamGamesPast(); this.gameListPast$.subscribe({ next: () => { @@ -92,14 +107,12 @@ export class ChampionshipPage implements OnInit { this.cdr.detectChanges(); }, error: (err) => console.error("GAMES PAST Error in subscription:", err), - complete: () => console.log("GAMES PAST Observable completed") + complete: () => console.log("GAMES PAST Observable completed"), }); - - } ngOnDestroy(): void { - /* if (this.subscription) { + /* if (this.subscription) { this.subscription.unsubscribe(); } if (this.subscriptionPast) { @@ -107,157 +120,218 @@ export class ChampionshipPage implements OnInit { }*/ } - getTeamsWithRankingsForYear(year: string = '2023') { + getTeamsWithRankingsForYear(year: string = "2023") { return this.authService.getUser$().pipe( take(1), - tap(user => console.log("User:", user)), - switchMap(user => { + tap((user) => console.log("User:", user)), + switchMap((user) => { if (!user) return of([]); // If no user, return an empty array return this.fbService.getUserTeamRefs(user); }), - tap(teams => console.log("Teams:", teams)), - mergeMap(teams => { + tap((teams) => console.log("Teams:", teams)), + mergeMap((teams) => { if (teams.length === 0) return of([]); return combineLatest( - teams.map(team => + teams.map((team) => combineLatest({ teamDetails: of(team), - rankingsTable: this.championshipService.getTeamRankingTable(team.id, year), - rankingDetails: this.championshipService.getTeamRanking(team.id, year) + rankingsTable: this.championshipService.getTeamRankingTable( + team.id, + year + ), + rankingDetails: this.championshipService.getTeamRanking( + team.id, + year + ), }).pipe( map(({ teamDetails, rankingsTable, rankingDetails }) => ({ ...teamDetails, rankings: rankingsTable, - details: rankingDetails + details: rankingDetails, })), - tap(result => console.log("Team with rankings and details:", result)) + tap((result) => + console.log("Team with rankings and details:", result) + ) ) ) ); }), - tap(results => console.log("Final results:", results)), - catchError(err => { + tap((results) => console.log("Final results:", results)), + catchError((err) => { console.error("Error in getTeamsWithRankingsForYear:", err); return of([]); // Return an empty array on error }) ); } - getTeamGamesUpcoming() { return this.authService.getUser$().pipe( take(1), - tap(user => { + tap((user) => { this.user = user; }), - switchMap(user => { + switchMap((user) => { if (!user) return of([]); return this.fbService.getUserTeamRefs(user); }), - tap(teams => console.log("Teams:", teams)), - mergeMap(teams => { + tap((teams) => console.log("Teams:", teams)), + mergeMap((teams) => { if (teams.length === 0) return of([]); return combineLatest( - teams.map(team => + teams.map((team) => this.championshipService.getTeamGamesRefs(team.id).pipe( - switchMap(teamGames => { + switchMap((teamGames) => { if (teamGames.length === 0) return of([]); return combineLatest( - teamGames.map(game => - this.championshipService.getTeamGameAttendeesRef(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 - ) + teamGames.map((game) => + this.championshipService + .getTeamGameAttendeesRef(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 + map((gamesWithAttendees) => gamesWithAttendees), // Flatten games array for each team catchError(() => of([])) // If error in fetching games, return empty array ) ) ).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 + 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 => { + tap((results) => console.log("Final results with all games:", results)), + catchError((err) => { console.error("Error in getTeamGamesUpcoming:", err); return of([]); // Return an empty array on error }) ); } - - getTeamGamesPast() { - return this.authService.getUser$().pipe( - take(1), - tap(user=>{ - this.user = user; - }), - switchMap(user => { - if (!user) return of([]); - return this.fbService.getUserTeamRefs(user); - }), - tap(teams => console.log("Teams:", teams)), - mergeMap(teams => { - if (teams.length === 0) return of([]); - return combineLatest( - teams.map(team => - this.championshipService.getTeamGamesPastRefs(team.id).pipe( - switchMap(teamGames => { - if (teamGames.length === 0) return of([]); - return combineLatest( - teamGames.map(game => - this.championshipService.getTeamGameAttendeesRef(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,}) + getTeamGamesPast() { + return this.authService.getUser$().pipe( + take(1), + tap((user) => { + this.user = user; + }), + switchMap((user) => { + if (!user) return of([]); + return this.fbService.getUserTeamRefs(user); + }), + tap((teams) => console.log("Teams:", teams)), + mergeMap((teams) => { + if (teams.length === 0) return of([]); + return combineLatest( + teams.map((team) => + this.championshipService.getTeamGamesPastRefs(team.id).pipe( + switchMap((teamGames) => { + if (teamGames.length === 0) return of([]); + return combineLatest( + teamGames.map((game) => + this.championshipService + .getTeamGameAttendeesRef(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 + 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 - ) - ) - ).pipe( - map(teamsGames => teamsGames.flat()), // Flatten to get all games across all teams - map(allGames => - allGames.sort((b, a) => Timestamp.fromMillis(a.dateTime).seconds - Timestamp.fromMillis(b.dateTime).seconds) // Sort games by date + ) + ); + }), + map((gamesWithAttendees) => gamesWithAttendees), // Flatten games array for each team + catchError(() => of([])) // If error in fetching games, return empty array ) - ); - }), - tap(results => console.log("Final results with all games:", results)), - catchError(err => { - console.error("Error in getTeamGamesUpcoming:", err); - return of([]); // Return an empty array on error - }) - ); - } - - + ) + ).pipe( + map((teamsGames) => teamsGames.flat()), // Flatten to get all games across all teams + map( + (allGames) => + allGames.sort( + (b, a) => + 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 getTeamGamesUpcoming:", err); + return of([]); // Return an empty array on error + }) + ); + } + async openChampionshipDetailModal(game: Game) { // const presentingElement = await this.modalCtrl.getTop(); - game['abc'] = new Date().toISOString(); - let extras : NavigationExtras = { + game["abc"] = new Date().toISOString(); + let extras: NavigationExtras = { queryParams: { - data: JSON.stringify(game) - } - } - console.log(extras) - this.navCtrl.navigateForward(['championship-details'],extras).catch(e=>{ - console.log(e); - }) + data: JSON.stringify(game), + }, + }; + console.log(extras); + this.navCtrl + .navigateForward(["championship-details"], extras) + .catch((e) => { + console.log(e); + }); // const modal = await this.modalCtrl.create({ // component: ChampionshipDetailPage, // presentingElement: this.routerOutlet.nativeEl, @@ -278,7 +352,9 @@ export class ChampionshipPage implements OnInit { // List item async toggle(status: boolean, game: Game) { - console.log(`Set Status ${status} for user ${this.user.uid} and team ${game.teamId} and game ${game.id}`); + console.log( + `Set Status ${status} for user ${this.user.uid} and team ${game.teamId} and game ${game.id}` + ); await this.championshipService.setTeamGameAttendeeStatus( this.user.uid, status, @@ -313,8 +389,6 @@ export class ChampionshipPage implements OnInit { toast.present(); } - - async openFilter(ev: Event) { /* let filterList = []; @@ -384,6 +458,4 @@ this.subscription = forkJoin([teams$]).subscribe({ }); */ } - } - diff --git a/src/app/pages/event/event-detail/event-detail.page.html b/src/app/pages/event/event-detail/event-detail.page.html index 0e1da7e3..b3a0d60c 100644 --- a/src/app/pages/event/event-detail/event-detail.page.html +++ b/src/app/pages/event/event-detail/event-detail.page.html @@ -52,7 +52,7 @@

{{event.description}}

- + {{"attendances__absences" | translate}} diff --git a/src/app/pages/event/event-detail/event-detail.page.ts b/src/app/pages/event/event-detail/event-detail.page.ts index be6025a8..ecb05390 100644 --- a/src/app/pages/event/event-detail/event-detail.page.ts +++ b/src/app/pages/event/event-detail/event-detail.page.ts @@ -26,6 +26,7 @@ import { UserProfileService } from "src/app/services/firebase/user-profile.servi }) export class EventDetailPage implements OnInit { @Input("data") event: Veranstaltung; + @Input("isFuture") isFuture: boolean; event$: Observable; diff --git a/src/app/pages/event/events/events.page.html b/src/app/pages/event/events/events.page.html index 72b29047..a651acd9 100644 --- a/src/app/pages/event/events/events.page.html +++ b/src/app/pages/event/events/events.page.html @@ -39,40 +39,60 @@ - - - - -

- {{event.name}} -

-

- - {{event.date.toDate() | date:'dd.MM.YYYY '}} {{event.timeFrom | date:'HH:mm'}} Uhr - - {{event.timeTo | date:'HH:mm'}} Uhr -

-

- - {{event.location}} {{event.streetAndNumber}} {{event.city}} -

- - -
- + + + + +

{{event.name}}

+

+ + {{event.date.toDate() | date:'dd.MM.YYYY '}} {{event.timeFrom | + date:'HH:mm'}} Uhr - {{event.timeTo | date:'HH:mm'}} Uhr +

+

+ + {{event.location}} {{event.streetAndNumber}} {{event.city}} +

+
+ {{event.countAttendees}}
- + - + @@ -85,16 +105,13 @@

- {{"upcomming__events" | translate}} - - {{"no_event__found" | translate}} - + {{"no_event__found" | translate}} @@ -113,43 +130,50 @@

- - - - -

- {{event.name}} -

-

- - {{event.date.toDate() | date:'dd.MM.YYYY '}} {{event.timeFrom | date:'HH:mm'}} Uhr - - {{event.timeTo | date:'HH:mm'}} Uhr -

-

- - {{event.location}} {{event.streetAndNumber}} {{event.city}} -

- - -
- + + + + +

{{event.name}}

+

+ + {{event.date.toDate() | date:'dd.MM.YYYY '}} {{event.timeFrom | + date:'HH:mm'}} Uhr - {{event.timeTo | date:'HH:mm'}} Uhr +

+

+ + {{event.location}} {{event.streetAndNumber}} {{event.city}} +

+
+ {{event.countAttendees}}
- -
{{"past__events" | translate}} - - {{"no_event__found" | translate}} - + {{"no_event__found" | translate}} @@ -164,27 +188,54 @@

- + - + - + - - - - - + + + + + - \ No newline at end of file + diff --git a/src/app/pages/event/events/events.page.ts b/src/app/pages/event/events/events.page.ts index b4bc80e8..583fb228 100644 --- a/src/app/pages/event/events/events.page.ts +++ b/src/app/pages/event/events/events.page.ts @@ -8,7 +8,25 @@ import { AlertController, } from "@ionic/angular"; import { User } from "@angular/fire/auth"; -import { Observable, Subscription, catchError, combineLatest, concatMap, defaultIfEmpty, finalize, forkJoin, from, lastValueFrom, map, mergeMap, of, switchMap, take, tap, timeout} from "rxjs"; +import { + Observable, + Subscription, + catchError, + combineLatest, + concatMap, + defaultIfEmpty, + finalize, + forkJoin, + from, + lastValueFrom, + 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"; @@ -50,7 +68,6 @@ export class EventsPage implements OnInit { } ngOnInit() { - this.eventList$ = this.getClubEvent(); this.eventList$.subscribe({ next: (data) => { @@ -58,10 +75,9 @@ export class EventsPage implements OnInit { this.cdr.detectChanges(); }, error: (err) => console.error("EVENT Error in subscription:", err), - complete: () => console.log("EVENT Observable completed") + complete: () => console.log("EVENT Observable completed"), }); - this.eventListPast$ = this.getClubEventPast(); this.eventListPast$.subscribe({ next: () => { @@ -69,104 +85,157 @@ export class EventsPage implements OnInit { this.cdr.detectChanges(); }, error: (err) => console.error("EVENT PAST Error in subscription:", err), - complete: () => console.log("EVENT PAST Observable completed") + complete: () => console.log("EVENT PAST Observable completed"), }); - } getClubEvent() { return this.authService.getUser$().pipe( take(1), - tap(user=>{ + tap((user) => { this.user = user; }), - switchMap(user => { + switchMap((user) => { if (!user) return of([]); return this.fbService.getUserClubRefs(user); }), - tap(clubs => console.log("Teams:", clubs)), - mergeMap(teams => { + tap((clubs) => console.log("Teams:", clubs)), + mergeMap((teams) => { if (teams.length === 0) return of([]); return combineLatest( - teams.map(team => + teams.map((team) => this.eventService.getClubEventsRef(team.id).pipe( - switchMap(clubEvents => { + 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 - ) + 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 + map((gamesWithAttendees) => gamesWithAttendees), // Flatten games array for each team catchError(() => of([])) // If error in fetching games, return empty array ) ) ).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 + 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 => { + 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(user=>{ + tap((user) => { this.user = user; }), - switchMap(user => { + switchMap((user) => { if (!user) return of([]); return this.fbService.getUserClubRefs(user); }), - tap(clubs => console.log("Teams:", clubs)), - mergeMap(teams => { + tap((clubs) => console.log("Teams:", clubs)), + mergeMap((teams) => { if (teams.length === 0) return of([]); return combineLatest( - teams.map(team => + teams.map((team) => this.eventService.getClubEventsPastRef(team.id).pipe( - switchMap(teamGames => { + 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 - ) + 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 + map((gamesWithAttendees) => gamesWithAttendees), // Flatten games array for each team catchError(() => of([])) // If error in fetching games, return empty array ) ) ).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 + 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 => { + 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 }) @@ -186,7 +255,11 @@ export class EventsPage implements OnInit { this.presentToast(); } - async toggleItem(slidingItem: IonItemSliding, status: boolean, event: Veranstaltung) { + async toggleItem( + slidingItem: IonItemSliding, + status: boolean, + event: Veranstaltung + ) { slidingItem.closeOpened(); console.log( @@ -230,10 +303,8 @@ export class EventsPage implements OnInit { if (role === "confirm") { } - } - async deleteEvent(slidingItem: IonItemSliding, event) { slidingItem.closeOpened(); const toast = await this.toastController.create({ @@ -245,7 +316,7 @@ export class EventsPage implements OnInit { toast.present(); } - async openFilter(ev: Event){ + async openFilter(ev: Event) { /* let filterList = []; @@ -315,7 +386,7 @@ export class EventsPage implements OnInit { error: err => console.error('Error in the observable chain:', err) }); */ -} + } async openEventCreateModal() { // const presentingElement = await this.modalCtrl.getTop(); @@ -336,7 +407,7 @@ export class EventsPage implements OnInit { } } - async openEventDetailModal(event: Veranstaltung) { + async openEventDetailModal(event: Veranstaltung, isFuture: boolean) { // const presentingElement = await this.modalCtrl.getTop(); const modal = await this.modalCtrl.create({ component: EventDetailPage, @@ -345,6 +416,7 @@ export class EventsPage implements OnInit { showBackdrop: true, componentProps: { data: event, + isFuture: isFuture, }, }); modal.present(); @@ -354,5 +426,4 @@ export class EventsPage implements OnInit { if (role === "confirm") { } } - } diff --git a/src/app/pages/helfer/helfer-detail/helfer-detail.page.html b/src/app/pages/helfer/helfer-detail/helfer-detail.page.html index 185a91e8..0c85fea3 100644 --- a/src/app/pages/helfer/helfer-detail/helfer-detail.page.html +++ b/src/app/pages/helfer/helfer-detail/helfer-detail.page.html @@ -52,7 +52,7 @@

{{event.description}}

- + {{"attendances__absences" | translate}} diff --git a/src/app/pages/helfer/helfer-detail/helfer-detail.page.ts b/src/app/pages/helfer/helfer-detail/helfer-detail.page.ts index e211347c..2d86a2e9 100644 --- a/src/app/pages/helfer/helfer-detail/helfer-detail.page.ts +++ b/src/app/pages/helfer/helfer-detail/helfer-detail.page.ts @@ -25,6 +25,7 @@ import { UserProfileService } from "src/app/services/firebase/user-profile.servi }) export class HelferDetailPage implements OnInit { @Input("data") event: HelferEvent; + @Input("isFuture") isFuture: boolean; event$: Observable; diff --git a/src/app/pages/helfer/helfer/helfer.page.html b/src/app/pages/helfer/helfer/helfer.page.html index 8df154bc..79530bcd 100644 --- a/src/app/pages/helfer/helfer/helfer.page.html +++ b/src/app/pages/helfer/helfer/helfer.page.html @@ -36,45 +36,64 @@ - - - - -

- {{event.name}} -

+ + + + +

{{event.name}}

- {{event.date.toDate() | date:'dd.MM.YYYY '}} {{event.timeFrom | date:'HH:mm'}} Uhr - - {{event.timeTo | date:'HH:mm'}} Uhr + {{event.date.toDate() | date:'dd.MM.YYYY '}} {{event.timeFrom | + date:'HH:mm'}} Uhr - {{event.timeTo | date:'HH:mm'}} Uhr

{{event.location}} {{event.streetAndNumber}} {{event.city}}

- -
- + {{event.countAttendees}}
- + - + - @@ -83,7 +102,6 @@

- @@ -91,9 +109,7 @@

{{"upcomming__helper_event" | translate}} - - {{"no_event__found" | translate}} - + {{"no_event__found" | translate}} @@ -112,44 +128,50 @@

- - - - -

- {{event.name}} -

-

- - {{event.date.toDate() | date:'dd.MM.YYYY '}} {{event.timeFrom | date:'HH:mm'}} Uhr - - {{event.timeTo | date:'HH:mm'}} Uhr -

-

- - {{event.location}} {{event.streetAndNumber}} {{event.city}} -

- - -
- + + + + +

{{event.name}}

+

+ + {{event.date.toDate() | date:'dd.MM.YYYY '}} {{event.timeFrom | + date:'HH:mm'}} Uhr - {{event.timeTo | date:'HH:mm'}} Uhr +

+

+ + {{event.location}} {{event.streetAndNumber}} {{event.city}} +

+
+ {{event.countAttendees}}
- - -
{{"past__helper_events" | translate}} - - {{"no_event__found" | translate}} - + {{"no_event__found" | translate}} @@ -164,27 +186,54 @@

- + - + - + - - - - - + + + + + - \ No newline at end of file + diff --git a/src/app/pages/helfer/helfer/helfer.page.ts b/src/app/pages/helfer/helfer/helfer.page.ts index 18186974..efab0709 100644 --- a/src/app/pages/helfer/helfer/helfer.page.ts +++ b/src/app/pages/helfer/helfer/helfer.page.ts @@ -400,7 +400,7 @@ export class HelferPage implements OnInit { } } - async openEventDetailModal(event: HelferEvent) { + async openEventDetailModal(event: HelferEvent, isFuture: boolean) { // const presentingElement = await this.modalCtrl.getTop(); const modal = await this.modalCtrl.create({ component: HelferDetailPage, @@ -409,6 +409,7 @@ export class HelferPage implements OnInit { showBackdrop: true, componentProps: { data: event, + isFuture: isFuture, }, }); modal.present(); diff --git a/src/app/pages/training/training-detail/training-detail.page.html b/src/app/pages/training/training-detail/training-detail.page.html index adafa363..217c9a66 100644 --- a/src/app/pages/training/training-detail/training-detail.page.html +++ b/src/app/pages/training/training-detail/training-detail.page.html @@ -52,7 +52,7 @@

{{training.description}}

- + {{"attendances__absences" | translate}} @@ -93,6 +93,7 @@

{{training.description}}

+ diff --git a/src/app/pages/training/training-detail/training-detail.page.ts b/src/app/pages/training/training-detail/training-detail.page.ts index 157d1329..75c6b978 100644 --- a/src/app/pages/training/training-detail/training-detail.page.ts +++ b/src/app/pages/training/training-detail/training-detail.page.ts @@ -25,6 +25,7 @@ import { UserProfileService } from "src/app/services/firebase/user-profile.servi }) export class TrainingDetailPage implements OnInit { @Input("data") training: Training; + @Input("isFuture") isFuture: boolean; training$: Observable; diff --git a/src/app/pages/training/trainings/trainings.page.html b/src/app/pages/training/trainings/trainings.page.html index 62188086..24ba26a7 100644 --- a/src/app/pages/training/trainings/trainings.page.html +++ b/src/app/pages/training/trainings/trainings.page.html @@ -4,7 +4,7 @@ {{"training" | translate}} - @@ -106,15 +122,14 @@

{{"upcomming__training" | translate}} - - {{"no_training__found" | translate}} - + {{"no_training__found" | translate}} - + - {{"past__training" | translate}} @@ -128,62 +143,57 @@

- - - - -

- {{training.name}} -

+ + + + +

{{training.name}}

{{training.streetAndNumber}} {{training.city}}

- {{training.date.toDate() | date:'dd.MM.YYYY '}} {{training.timeFrom | date:'HH:mm'}} Uhr - - {{training.timeTo | date:'HH:mm'}} Uhr + {{training.date.toDate() | date:'dd.MM.YYYY '}} + {{training.timeFrom | date:'HH:mm'}} Uhr - {{training.timeTo | + date:'HH:mm'}} Uhr

{{training.liga}} {{training.teamName}}

- + {{training.countAttendees}}
- - - - - - @@ -194,9 +204,7 @@

{{"past__training" | translate}} - - {{"no_training__found" | translate}} - + {{"no_training__found" | translate}} @@ -208,32 +216,58 @@

- - + - + - + - - - - - + + + + + - \ No newline at end of file + diff --git a/src/app/pages/training/trainings/trainings.page.ts b/src/app/pages/training/trainings/trainings.page.ts index b620143a..3360b98e 100644 --- a/src/app/pages/training/trainings/trainings.page.ts +++ b/src/app/pages/training/trainings/trainings.page.ts @@ -8,7 +8,18 @@ import { ToastController, } from "@ionic/angular"; import { User } from "@angular/fire/auth"; -import { Observable, catchError, combineLatest, lastValueFrom, map, mergeMap, of, switchMap, take, tap } from "rxjs"; +import { + Observable, + catchError, + combineLatest, + lastValueFrom, + map, + mergeMap, + of, + switchMap, + take, + tap, +} from "rxjs"; import { Training } from "src/app/models/training"; import { AuthService } from "src/app/services/auth.service"; import { FirebaseService } from "src/app/services/firebase.service"; @@ -50,7 +61,6 @@ export class TrainingsPage implements OnInit { } ngOnInit() { - this.trainingList$ = this.getTeamTraining(); this.trainingList$.subscribe({ next: (data) => { @@ -58,128 +68,182 @@ export class TrainingsPage implements OnInit { this.cdr.detectChanges(); }, error: (err) => console.error("Training Error in subscription:", err), - complete: () => console.log("Training Observable completed") + complete: () => console.log("Training Observable completed"), }); - this.trainingListPast$ = this.getTeamTrainingPast(); this.trainingListPast$.subscribe({ next: () => { console.log("Training PAST Data received"); this.cdr.detectChanges(); }, - error: (err) => console.error("Training PAST Error in subscription:", err), - complete: () => console.log("Training PAST Observable completed") + error: (err) => + console.error("Training PAST Error in subscription:", err), + complete: () => console.log("Training PAST Observable completed"), }); - } - ngOnDestroy(): void { - - } + ngOnDestroy(): void {} getTeamTraining() { return this.authService.getUser$().pipe( take(1), - tap(user=>{ + tap((user) => { this.user = user; }), - switchMap(user => { + switchMap((user) => { if (!user) return of([]); return this.fbService.getUserTeamRefs(user); }), - tap(teams => console.log("Teams:", teams)), - mergeMap(teams => { + tap((teams) => console.log("Teams:", teams)), + mergeMap((teams) => { if (teams.length === 0) return of([]); return combineLatest( - teams.map(team => + teams.map((team) => this.trainingService.getTeamTrainingsRefs(team.id).pipe( - switchMap(teamTrainings => { + switchMap((teamTrainings) => { if (teamTrainings.length === 0) return of([]); return combineLatest( - teamTrainings.map(training => - this.trainingService.getTeamTrainingsAttendeesRef(team.id, training.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 ({...training, attendees, status: status, countAttendees: attendees.filter(att => att.status == true).length, teamId: team.id,}) - }), - catchError(() => of({ ...training, attendees: [], status: null, countAttendees: 0, teamId: team.id,})) // If error, return training with empty attendees - ) + teamTrainings.map((training) => + this.trainingService + .getTeamTrainingsAttendeesRef(team.id, training.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 { + ...training, + attendees, + status: status, + countAttendees: attendees.filter( + (att) => att.status == true + ).length, + teamId: team.id, + }; + }), + catchError(() => + of({ + ...training, + attendees: [], + status: null, + countAttendees: 0, + teamId: team.id, + }) + ) // If error, return training with empty attendees + ) ) ); }), - map(trainingsWithAttendees => trainingsWithAttendees), // Flatten trainings array for each team + map((trainingsWithAttendees) => trainingsWithAttendees), // Flatten trainings array for each team catchError(() => of([])) // If error in fetching trainings, return empty array ) ) ).pipe( - map(teamsTrainings => teamsTrainings.flat()), // Flatten to get all trainings across all teams - map(allTrainings => - allTrainings.sort((a, b) => Timestamp.fromMillis(a.dateTime).seconds - Timestamp.fromMillis(b.dateTime).seconds) // Sort trainings by date + map((teamsTrainings) => teamsTrainings.flat()), // Flatten to get all trainings across all teams + map( + (allTrainings) => + allTrainings.sort( + (a, b) => + Timestamp.fromMillis(a.dateTime).seconds - + Timestamp.fromMillis(b.dateTime).seconds + ) // Sort trainings by date ) ); }), - tap(results => console.log("Final results with all trainings:", results)), - catchError(err => { + tap((results) => + console.log("Final results with all trainings:", results) + ), + catchError((err) => { console.error("Error in getTeamTrainingsUpcoming:", err); return of([]); // Return an empty array on error }) ); } - getTeamTrainingPast() { return this.authService.getUser$().pipe( take(1), - tap(user=>{ + tap((user) => { this.user = user; }), - switchMap(user => { + switchMap((user) => { if (!user) return of([]); return this.fbService.getUserTeamRefs(user); }), - tap(teams => console.log("Teams:", teams)), - mergeMap(teams => { + tap((teams) => console.log("Teams:", teams)), + mergeMap((teams) => { if (teams.length === 0) return of([]); return combineLatest( - teams.map(team => + teams.map((team) => this.trainingService.getTeamTrainingsPastRefs(team.id).pipe( - switchMap(teamTrainings => { + switchMap((teamTrainings) => { if (teamTrainings.length === 0) return of([]); return combineLatest( - teamTrainings.map(training => - this.trainingService.getTeamTrainingsAttendeesRef(team.id, training.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 ({...training, attendees, status: status, countAttendees: attendees.filter(att => att.status == true).length, teamId: team.id,}) - }), - catchError(() => of({ ...training, attendees: [], status: null, countAttendees: 0, teamId: team.id,})) // If error, return training with empty attendees - ) + teamTrainings.map((training) => + this.trainingService + .getTeamTrainingsAttendeesRef(team.id, training.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 { + ...training, + attendees, + status: status, + countAttendees: attendees.filter( + (att) => att.status == true + ).length, + teamId: team.id, + }; + }), + catchError(() => + of({ + ...training, + attendees: [], + status: null, + countAttendees: 0, + teamId: team.id, + }) + ) // If error, return training with empty attendees + ) ) ); }), - map(trainingsWithAttendees => trainingsWithAttendees), // Flatten trainings array for each team + map((trainingsWithAttendees) => trainingsWithAttendees), // Flatten trainings array for each team catchError(() => of([])) // If error in fetching trainings, return empty array ) ) ).pipe( - map(teamsTrainings => teamsTrainings.flat()), // Flatten to get all trainings across all teams - map(allTrainings => - allTrainings.sort((b, a) => Timestamp.fromMillis(a.dateTime).seconds - Timestamp.fromMillis(b.dateTime).seconds) // Sort trainings by date + map((teamsTrainings) => teamsTrainings.flat()), // Flatten to get all trainings across all teams + map( + (allTrainings) => + allTrainings.sort( + (b, a) => + Timestamp.fromMillis(a.dateTime).seconds - + Timestamp.fromMillis(b.dateTime).seconds + ) // Sort trainings by date ) ); }), - tap(results => console.log("Final results with all trainings:", results)), - catchError(err => { + tap((results) => + console.log("Final results with all trainings:", results) + ), + catchError((err) => { console.error("Error in getTeamTrainingsUpcoming:", err); return of([]); // Return an empty array on error }) ); } - - async openTrainingDetailModal(training: Training) { + + async openTrainingDetailModal(training: Training, isFuture: boolean) { // const presentingElement = await this.modalCtrl.getTop(); const modal = await this.modalController.create({ component: TrainingDetailPage, @@ -188,6 +252,7 @@ export class TrainingsPage implements OnInit { showBackdrop: true, componentProps: { data: training, + isFuture: isFuture, }, }); modal.present(); @@ -198,7 +263,6 @@ export class TrainingsPage implements OnInit { } } - async openTrainingCreateModal() { // const presentingElement = await this.modalCtrl.getTop(); const modal = await this.modalController.create({ @@ -218,7 +282,6 @@ export class TrainingsPage implements OnInit { } } - async copyTraining(slidingItem: IonItemSliding, training) { slidingItem.closeOpened(); @@ -238,10 +301,8 @@ export class TrainingsPage implements OnInit { if (role === "confirm") { } - } - async deleteTraining(slidingItem: IonItemSliding, training) { slidingItem.closeOpened(); const toast = await this.toastController.create({ @@ -253,7 +314,6 @@ export class TrainingsPage implements OnInit { toast.present(); } - async toggle(status: boolean, training: Training) { console.log( `Set Status ${status} for user ${this.user.uid} and team ${training.teamId} and training ${training.id}` @@ -296,10 +356,8 @@ export class TrainingsPage implements OnInit { toast.present(); } - async openFilter(ev: Event) { - - /* + /* let filterList = []; @@ -369,5 +427,4 @@ export class TrainingsPage implements OnInit { }); */ } - }