Skip to content

Commit

Permalink
feat update training status
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Nov 23, 2023
1 parent 12cad85 commit 93d57d6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 45 deletions.
9 changes: 4 additions & 5 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
6068B69F868D1149E79B8A79 /* Pods-App.debug.xcconfig */,
E55BD740173AD78B07A75E55 /* Pods-App.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -367,12 +366,12 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = U7DQUX87VS;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = app.myclub.default;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -388,12 +387,12 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = U7DQUX87VS;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = app.myclub.default;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
Expand Down
2 changes: 0 additions & 2 deletions src/app/pages/club/club.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export class ClubPage implements OnInit {
console.log(">> Club Data" );
console.log( data);
this.cdr.detectChanges();


},
error: (err) => console.error("Club Error in subscription:", err),
complete: () => console.log("Club Observable completed")
Expand Down
16 changes: 9 additions & 7 deletions src/app/pages/training/training-detail/training-detail.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</ion-toolbar>
</ion-header>
<!-- class="ion-padding" -->


<ion-content>
<ion-list [inset]="true">
<ion-list-header>
Expand Down Expand Up @@ -87,11 +89,11 @@ <h2>
<ion-accordion-group [multiple]="true" [value]="['yes']">
<ion-accordion value="yes">
<ion-item slot="header" color="light">
<ion-label>Anwesend: {{attendeeListTrue.length}}</ion-label>
<ion-label>Anwesend: {{training['attendeeListTrue'].length}}</ion-label>
</ion-item>
<div slot="content"> <!-- class="ion-padding"-->
<ion-list>
<ion-item *ngFor="let member of attendeeListTrue" detail="true">
<ion-item *ngFor="let member of training['attendeeListTrue']" detail="true">
<ion-icon color="success" slot="start" name="checkmark-circle">
</ion-icon>

Expand All @@ -102,11 +104,11 @@ <h2>
</ion-accordion>
<ion-accordion value="no">
<ion-item slot="header" color="light">
<ion-label>Abwesend: {{attendeeListFalse.length}}</ion-label>
<ion-label>Abwesend: {{training['attendeeListFalse'].length}}</ion-label>
</ion-item>
<div slot="content"> <!-- class="ion-padding"-->
<ion-list>
<ion-item *ngFor="let member of attendeeListFalse" detail="true">
<ion-item *ngFor="let member of training['attendeeListFalse']" detail="true">

<ion-icon color="danger" slot="start" name="close-circle">
</ion-icon>
Expand All @@ -117,11 +119,11 @@ <h2>
</ion-list>
</div>
</ion-accordion>
<ion-accordion value="unknown">
<!-- <ion-accordion value="unknown">
<ion-item slot="header" color="light">
<ion-label>Keine Antwort: {{attendeeListUndefined.length}}</ion-label>
</ion-item>
<div slot="content"> <!-- class="ion-padding"-->
<div slot="content">
<ion-list>
<ion-item *ngFor="let member of attendeeListUndefined" detail="true">
<ion-icon color="warning" slot="start" name="help-circle">
Expand All @@ -130,7 +132,7 @@ <h2>
</ion-item>
</ion-list>
</div>
</ion-accordion>
</ion-accordion>-->
</ion-accordion-group>
</ion-list>

Expand Down
60 changes: 29 additions & 31 deletions src/app/pages/training/training-detail/training-detail.page.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
import { ModalController, NavParams, ToastController } from '@ionic/angular';
import { User } from 'firebase/auth';
import { Observable, catchError, map, of, switchMap, take, tap } from 'rxjs';
import { Observable, catchError, forkJoin, map, of, switchMap, take, tap } from 'rxjs';
import { Training } from 'src/app/models/training';
import { AuthService } from 'src/app/services/auth.service';
import { TrainingService } from 'src/app/services/firebase/training.service';
import { UserProfileService } from 'src/app/services/firebase/user-profile.service';

@Component({
selector: 'app-training-detail',
Expand All @@ -14,7 +15,7 @@ import { TrainingService } from 'src/app/services/firebase/training.service';
export class TrainingDetailPage implements OnInit {
@Input("data") training: Training;

training$: Observable<Training>;
training$: Observable<any>;

mode = "yes";

Expand All @@ -27,6 +28,7 @@ export class TrainingDetailPage implements OnInit {
constructor (
private readonly modalCtrl: ModalController,
public navParams: NavParams,
private readonly userProfileService: UserProfileService,
private readonly trainingService: TrainingService,
private readonly toastController: ToastController,
private readonly authService: AuthService,
Expand All @@ -45,6 +47,7 @@ export class TrainingDetailPage implements OnInit {
this.training$.subscribe({
next: (data) => {
console.log("TRAINING Data received");
console.log(data);
this.training = {
...this.training, ...data
};
Expand All @@ -62,45 +65,40 @@ export class TrainingDetailPage implements OnInit {
take(1),
tap(user => {
this.user = user;
if (!user) {
console.log("No user found");
throw new Error("User not found");
}
if (!user) throw new Error("User not found");
}),
switchMap(() => this.trainingService.getTeamTrainingRef(teamId, trainingId)),
switchMap(game => {
if (!game) return of(null); // If no game is found, return null
switchMap(training => {
if (!training) return of(null);
return this.trainingService.getTeamTrainingsAttendeesRef(teamId, trainingId).pipe(
map(attendees => {

// get firstName & lastName from userProfile Method call for each attendees element
// this.userProfileService.getUserProfileById(attendee.id)

const userAttendee = attendees.find(att => att.id == this.user.uid);
const status = userAttendee ? userAttendee.status : null;

//this.attendeeListUndefined

this.attendeeListTrue = attendees.filter(att => att.status == true) || [];
this.attendeeListFalse = attendees.filter(att => att.status == false) || [];
this.attendeeListUndefined = [];

return {
...game,
attendees,
status,
};
switchMap(attendees => {
const attendeeProfiles$ = attendees.map(attendee =>
this.userProfileService.getUserProfileById(attendee.id).pipe(
take(1),
map(profile => ({ ...profile, ...attendee })), // Combine attendee object with profile
catchError(() => of({ ...attendee, firstName: 'Unknown', lastName: 'Unknown' }))
)
);
return forkJoin(attendeeProfiles$).pipe(
map(attendeesWithDetails => ({
...training,
attendees: attendeesWithDetails,
attendeeListTrue: attendeesWithDetails.filter(e=>e.status==true),
attendeeListFalse: attendeesWithDetails.filter(e=>e.status==false),
status: attendeesWithDetails.find(att => att.id == this.user.uid)?.status
}))
);
}),
catchError(() => of({
...game,
...training,
attendees: [],
status: null,
})) // If error in fetching attendees, return game with empty attendees
}))
);
}),
catchError(err => {
console.error("Error in getSingleGameWithAttendees:", err);
return of(null); // Return null on error
console.error("Error in getTrainingWithAttendees:", err);
return of(null);
})
);
}
Expand Down

0 comments on commit 93d57d6

Please sign in to comment.