diff --git a/src/app/models/event.ts b/src/app/models/event.ts index b7d83df5..78692359 100644 --- a/src/app/models/event.ts +++ b/src/app/models/event.ts @@ -4,16 +4,30 @@ export interface Event { id: string name: string description: string - dateTime: Timestamp + location: string + streetAndNumber: string + postalCode: string city: string - date: Date - time: string + + date: Timestamp, + + startDate: string + endDate: string + + timeFrom: string + timeTo: string + teamId: string + teamName: string + liga: string + clubId: string + clubName: string // Business Logic Fields status: boolean attendees: any + countAttendees: number } export interface HelferEvent extends Event { schichten: [Schicht] diff --git a/src/app/models/training.ts b/src/app/models/training.ts index bc24a226..84693a00 100644 --- a/src/app/models/training.ts +++ b/src/app/models/training.ts @@ -1,3 +1,5 @@ +import { Timestamp } from 'firebase/firestore'; + export interface Training { id: string; name: string; @@ -9,7 +11,7 @@ export interface Training { city: string; // actual date of training - date: any; + date: Timestamp; timeFrom: string; timeTo: string; diff --git a/src/app/pages/event/event-add/event-add.page.html b/src/app/pages/event/event-add/event-add.page.html index 2c3b54a3..6ac54696 100644 --- a/src/app/pages/event/event-add/event-add.page.html +++ b/src/app/pages/event/event-add/event-add.page.html @@ -1,16 +1,114 @@ - - + + schliessen + + Veranstaltung erstellen + + erstellen - Events Add + + + + + + {{club.name}} + + + + + + {{team.name}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Start Veranstaltung: + + + + + + + + + + + Ende Veranstaltung: + - - - - Events Add - - + + + + + + + + + Startdatum: + + + + + + + + + + + + Enddatum: + + + + + + + + + + + + + + + diff --git a/src/app/pages/event/event-add/event-add.page.ts b/src/app/pages/event/event-add/event-add.page.ts index 4d4dfdf1..6a975a6c 100644 --- a/src/app/pages/event/event-add/event-add.page.ts +++ b/src/app/pages/event/event-add/event-add.page.ts @@ -1,4 +1,14 @@ import { Component, OnInit } from '@angular/core'; +import { ModalController, NavParams } from '@ionic/angular'; +import { User } from 'firebase/auth'; +import { Timestamp } from 'firebase/firestore'; +import { Observable, Subscription, catchError, concatMap, defaultIfEmpty, finalize, forkJoin, from, map, of, switchMap, take, tap } from "rxjs"; +import { Club } from 'src/app/models/club'; +import { Event } from 'src/app/models/event'; +import { Team } from 'src/app/models/team'; +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'; @Component({ selector: 'app-event-add', @@ -6,7 +16,209 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./event-add.page.scss'], }) export class EventAddPage implements OnInit { - constructor () {} + event: Event; + user$: Observable; + user: User; + private subscription: Subscription; + teamList: Team[] = []; + clubList: Club[] = []; - ngOnInit () {} + constructor ( + private readonly modalCtrl: ModalController, + private eventService: EventService, + private readonly authService: AuthService, + private fbService: FirebaseService, + public navParams: NavParams + ) { + this.event = { + id: "", + name: "", + description: "", + + location: "", + streetAndNumber: "", + postalCode: "", + city: "", + + date: Timestamp.fromDate(new Date()), + + timeFrom: new Date().toISOString(), + timeTo: new Date().toISOString(), + + startDate: new Date().toISOString(), + endDate: new Date().toISOString(), + + teamId: "", + teamName: "", + liga: "", + + clubId: "", + clubName: "", + + status: true, + attendees: [], + countAttendees: 0, + }; + } + + ngOnInit () { + let teamsList: any[] = []; + const teams$ = this.authService.getUser$().pipe( + take(1), + tap(user=>this.user = user), + switchMap(user => this.fbService.getAdminTeamRefs(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({}), // 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 => teamsList.push(team))), + finalize(() => console.log("Get Teams completed")) + ); + + this.subscription = forkJoin([teams$]).subscribe({ + next: () => { + // console.log(">>>" + teamsList); + this.teamList = teamsList; + this.event.teamId = this.teamList[0].id; + }, + error: err => console.error('Error in the observable chain:', err) + }); + + let clubList: any[] = []; + const clubs$ = this.authService.getUser$().pipe( + take(1), + tap(user=>this.user = user), + switchMap(user => this.fbService.getAdminClubRefs(user).pipe(take(1))), + concatMap(clubsArray => from(clubsArray)), + tap((club:Club)=>console.log(club.id)), + concatMap(club => + this.fbService.getClubRef(club.id).pipe( + take(1), + defaultIfEmpty({}), // 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(clubList => clubList.forEach(club => clubList.push(team))), + finalize(() => console.log("Get Club completed")) + ); + + this.subscription = forkJoin([clubs$]).subscribe({ + next: () => { + // console.log(">>>" + teamsList); + this.clubList = clubList; + this.event.clubId = this.clubList[0].id; + }, + error: err => console.error('Error in the observable chain:', err) + }); + + } + + + ngOnDestroy(): void { + if (this.subscription) { + this.subscription.unsubscribe(); + } + + } + + async close() { + return this.modalCtrl.dismiss(null, "close"); + } + + + async createTeamEvent() { + //Set Hours/Minutes of endDate to TimeFrom of training + console.log(`Start Date before calculation: ${this.event.startDate}`); + const calculatedStartDate = new Date(this.event.startDate); + calculatedStartDate.setHours(new Date(this.event.timeFrom).getHours()); + calculatedStartDate.setMinutes(new Date(this.event.timeFrom).getMinutes()); + calculatedStartDate.setSeconds(0); + calculatedStartDate.setMilliseconds(0); + this.event.startDate = calculatedStartDate.toISOString(); + console.log(`Start Date after calculation: ${this.event.startDate}`); + + console.log(`End Date before calculation: ${this.event.endDate}`); + const calcualtedEndDate = new Date(this.event.endDate); + calcualtedEndDate.setHours(new Date(this.event.timeFrom).getHours()); + calcualtedEndDate.setMinutes(new Date(this.event.timeFrom).getMinutes()); + calcualtedEndDate.setSeconds(0); + calcualtedEndDate.setMilliseconds(0); + this.event.endDate = calcualtedEndDate.toISOString(); + console.log(`End Date after calculation: ${this.event.endDate}`); + + const calculatedTimeFrom = new Date(this.event.timeFrom); + calculatedTimeFrom.setDate(new Date(this.event.startDate).getDate()); + calculatedTimeFrom.setMonth(new Date(this.event.startDate).getMonth()); + calculatedTimeFrom.setFullYear(new Date(this.event.startDate).getFullYear()); + calculatedTimeFrom.setSeconds(0); + calculatedTimeFrom.setMilliseconds(0); + this.event.timeFrom = calculatedTimeFrom.toISOString(); + + const calculatedTimeTo = new Date(this.event.timeTo); + calculatedTimeTo.setDate(new Date(this.event.startDate).getDate()); + calculatedTimeTo.setMonth(new Date(this.event.startDate).getMonth()); + calculatedTimeTo.setFullYear(new Date(this.event.startDate).getFullYear()); + calculatedTimeTo.setSeconds(0); + calculatedTimeTo.setMilliseconds(0); + this.event.timeTo = calculatedTimeTo.toISOString(); + + delete this.event.attendees; + + this.eventService.setCreateTeamEvent(this.event, this.user); + return this.modalCtrl.dismiss({}, "confirm"); + } + async createClubEvent() { + //Set Hours/Minutes of endDate to TimeFrom of training + console.log(`Start Date before calculation: ${this.event.startDate}`); + const calculatedStartDate = new Date(this.event.startDate); + calculatedStartDate.setHours(new Date(this.event.timeFrom).getHours()); + calculatedStartDate.setMinutes(new Date(this.event.timeFrom).getMinutes()); + calculatedStartDate.setSeconds(0); + calculatedStartDate.setMilliseconds(0); + this.event.startDate = calculatedStartDate.toISOString(); + console.log(`Start Date after calculation: ${this.event.startDate}`); + + console.log(`End Date before calculation: ${this.event.endDate}`); + const calcualtedEndDate = new Date(this.event.endDate); + calcualtedEndDate.setHours(new Date(this.event.timeFrom).getHours()); + calcualtedEndDate.setMinutes(new Date(this.event.timeFrom).getMinutes()); + calcualtedEndDate.setSeconds(0); + calcualtedEndDate.setMilliseconds(0); + this.event.endDate = calcualtedEndDate.toISOString(); + console.log(`End Date after calculation: ${this.event.endDate}`); + + const calculatedTimeFrom = new Date(this.event.timeFrom); + calculatedTimeFrom.setDate(new Date(this.event.startDate).getDate()); + calculatedTimeFrom.setMonth(new Date(this.event.startDate).getMonth()); + calculatedTimeFrom.setFullYear(new Date(this.event.startDate).getFullYear()); + calculatedTimeFrom.setSeconds(0); + calculatedTimeFrom.setMilliseconds(0); + this.event.timeFrom = calculatedTimeFrom.toISOString(); + + const calculatedTimeTo = new Date(this.event.timeTo); + calculatedTimeTo.setDate(new Date(this.event.startDate).getDate()); + calculatedTimeTo.setMonth(new Date(this.event.startDate).getMonth()); + calculatedTimeTo.setFullYear(new Date(this.event.startDate).getFullYear()); + calculatedTimeTo.setSeconds(0); + calculatedTimeTo.setMilliseconds(0); + this.event.timeTo = calculatedTimeTo.toISOString(); + + delete this.event.attendees; + + this.eventService.setCreateClubEvent(this.event, this.user); + return this.modalCtrl.dismiss({}, "confirm"); + } } diff --git a/src/app/pages/event/events/events.page.html b/src/app/pages/event/events/events.page.html index cc7c1ce3..67216634 100644 --- a/src/app/pages/event/events/events.page.html +++ b/src/app/pages/event/events/events.page.html @@ -61,8 +61,8 @@

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

- {{event.date}} - {{event.time}} + {{event.startDate}} + {{event.timeFrom}}

@@ -144,8 +144,8 @@

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

- {{event.date}} - {{event.time}} + {{event.startDate}} + {{event.timeFrom}}

diff --git a/src/app/pages/event/events/events.page.ts b/src/app/pages/event/events/events.page.ts index a792164c..3b8f41b7 100644 --- a/src/app/pages/event/events/events.page.ts +++ b/src/app/pages/event/events/events.page.ts @@ -157,7 +157,8 @@ export class EventsPage implements OnInit { this.subscription = combineLatest([teamEvent$]).subscribe({ next: () => { this.eventsList = [...teamEventList].sort((a, b):any => { - return a.date.getTime() > b.date.getTime(); + // return a.date.getTime() > b.date.getTime(); + return a.date.seconds < b.date.seconds ; }); this.eventsList = this.eventsList.filter((Event, index, self) => index === self.findIndex((t) => (t.id === Event.id)) @@ -171,7 +172,8 @@ export class EventsPage implements OnInit { this.subscriptionPast = combineLatest([teamEventPast$]).subscribe({ next: () => { this.eventsListPast = [...teamEventPastList].sort((a, b):any => { - return a.date.getTime() > b.date.getTime(); + // 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)) diff --git a/src/app/pages/training/training-create/training-create.page.ts b/src/app/pages/training/training-create/training-create.page.ts index ea67ad2f..91eb2ea3 100644 --- a/src/app/pages/training/training-create/training-create.page.ts +++ b/src/app/pages/training/training-create/training-create.page.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from "@angular/core"; import { ModalController, NavParams } from "@ionic/angular"; import { User } from "firebase/auth"; +import { Timestamp } from "firebase/firestore"; import { Observable, Subscription, catchError, concatMap, defaultIfEmpty, finalize, forkJoin, from, map, of, switchMap, take, tap } from "rxjs"; import { Team } from "src/app/models/team"; import { Training } from "src/app/models/training"; @@ -36,7 +37,7 @@ export class TrainingCreatePage implements OnInit { postalCode: "", city: "", - date: new Date(), + date: Timestamp.fromDate(new Date()), timeFrom: new Date().toISOString(), timeTo: new Date().toISOString(), diff --git a/src/app/pages/training/trainings/trainings.page.html b/src/app/pages/training/trainings/trainings.page.html index 825eacb2..5e8c3296 100644 --- a/src/app/pages/training/trainings/trainings.page.html +++ b/src/app/pages/training/trainings/trainings.page.html @@ -65,7 +65,7 @@

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

diff --git a/src/app/services/firebase.service.ts b/src/app/services/firebase.service.ts index aebbcf70..51551a28 100644 --- a/src/app/services/firebase.service.ts +++ b/src/app/services/firebase.service.ts @@ -147,6 +147,16 @@ export class FirebaseService { }) as Observable; } + getAdminClubRefs(user: User): Observable { + const clubRefList = collection( + this.firestore, + `userProfile/${user.uid}/clubAdmin` + ); + return collectionData(clubRefList, { + idField: "id", + }) as Observable; + } + getUserClubRequestRefs(user: User): Observable { const requestRefList = collection( this.firestore, diff --git a/src/app/services/firebase/event.service.ts b/src/app/services/firebase/event.service.ts index 04f40739..492e5a8f 100644 --- a/src/app/services/firebase/event.service.ts +++ b/src/app/services/firebase/event.service.ts @@ -17,6 +17,7 @@ import { } from "@angular/fire/firestore"; import { Observable, Observer } from "rxjs"; import { Event } from "src/app/models/event"; +import { User } from "firebase/auth"; @Injectable({ providedIn: "root", @@ -82,6 +83,23 @@ export class EventService { }) as unknown as Observable; } + async setCreateTeamEvent(event: Event, user: User) { + console.log("event"); + console.log(event); + return addDoc( + collection(this.firestore, `userProfile/${user.uid}/teamEvent`), + event + ); + } + async setCreateClubEvent(event: Event, user: User) { + console.log("event"); + console.log(event); + return addDoc( + collection(this.firestore, `userProfile/${user.uid}/clubEvent`), + event + ); + } + /* TEAM EventS ATTENDEE Status */ async setTeamEventAttendeeStatus( userId: string,