Skip to content

Commit

Permalink
feat update schichten
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Dec 15, 2023
1 parent f5d01dd commit 5a4baf9
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 113 deletions.
5 changes: 0 additions & 5 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ const routes: Routes = [
(m) => m.NotFoundPageModule
),
},
{
path: "member",
loadChildren: () =>
import("./pages/member/member.module").then((m) => m.MemberPageModule),
},
];

@NgModule({
Expand Down
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { provideMessaging, getMessaging } from "@angular/fire/messaging";
// MODALs
import { OnboardingPage } from "./pages/onboarding/onboarding.page";
import { NewsDetailPage } from "./pages/news/news-detail/news-detail.page";
import { MemberPage } from "./pages/member/member.page";
import { HelferPunktePage } from "./pages/helfer/helfer-punkte/helfer-punkte.page";
import { ChampionshipDetailPage } from "./pages/championship/championship-detail/championship-detail.page";
import { TrainingDetailPage } from "./pages/training/training-detail/training-detail.page";
import { TrainingCreatePage } from "./pages/training/training-create/training-create.page";
Expand All @@ -51,6 +53,8 @@ import { TranslateHttpLoader } from "@ngx-translate/http-loader";
declarations: [
AppComponent,
NewsDetailPage,
MemberPage,
HelferPunktePage,
// ChampionshipDetailPage,
TrainingExercisesPage,
TrainingDetailPage,
Expand Down
82 changes: 54 additions & 28 deletions src/app/pages/helfer/helfer-detail/helfer-detail.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,66 @@ <h2>{{event.description}}</h2>
<ion-list lines="full" [inset]="true" *ngIf="schichten.length > 0">
<ion-list-header>
<ion-label> {{"helper.schichten" | translate}} </ion-label>
<ion-button (click)="confirmSchichten()">
bestätigen
</ion-button>
<ion-button (click)="confirmSchichten()"> bestätigen </ion-button>
</ion-list-header>
<ion-item *ngFor="let schicht of schichten">
<ion-icon
*ngIf="schicht.status === null"
slot="icon-only"
color="warning"
slot="start"
name="help-circle"
(click)="toggleSchicht(true, schicht)"
></ion-icon>
<ion-icon
*ngIf="schicht.status === false"
slot="icon-only"
color="danger"
slot="start"
name="close-circle"
(click)="toggleSchicht( true, schicht)"
></ion-icon>
<ion-icon
*ngIf="schicht.status === true"
slot="icon-only"
color="success"
slot="start"
name="checkmark-circle"
(click)="toggleSchicht(false, schicht)"
></ion-icon>
<ng-container *ngIf="schicht.confirmed !== true">
<ion-icon
*ngIf="schicht.status === null"
slot="icon-only"
color="warning"
slot="start"
name="help-circle"
(click)="toggleSchicht(true, schicht)"
></ion-icon>
<ion-icon
*ngIf="schicht.status === false"
slot="icon-only"
color="danger"
slot="start"
name="close-circle"
(click)="toggleSchicht( true, schicht)"
></ion-icon>
<ion-icon
*ngIf="schicht.status === true"
slot="icon-only"
color="success"
slot="start"
name="checkmark-circle"
(click)="toggleSchicht(false, schicht)"
></ion-icon>
</ng-container>
<ng-container *ngIf="schicht.confirmed">
<ion-icon
*ngIf="schicht.status === null"
slot="icon-only"
color="warning"
slot="start"
name="help-circle"
></ion-icon>
<ion-icon
*ngIf="schicht.status === false"
slot="icon-only"
color="danger"
slot="start"
name="close-circle"
></ion-icon>
<ion-icon
*ngIf="schicht.status === true"
slot="icon-only"
color="success"
slot="start"
name="checkmark-circle"
></ion-icon>
</ng-container>
<ion-label>
<h3>{{schicht.name}}</h3>
<h2>{{schicht.timeFrom}} {{schicht.timeTo}}</h2>
</ion-label>
<ion-badge>{{schicht.attendeeListTrue.length}} / {{schicht.countNeeded}}</ion-badge>
<ion-badge
>{{schicht.attendeeListTrue.length}} /
{{schicht.countNeeded}}</ion-badge
>
</ion-item>
</ion-list>

Expand Down
176 changes: 110 additions & 66 deletions src/app/pages/helfer/helfer-detail/helfer-detail.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { ChangeDetectorRef, Component, Input, OnInit } from "@angular/core";
import { AlertController, AlertInput, AlertOptions, ModalController, NavParams, ToastController } from "@ionic/angular";
import {
AlertController,
AlertInput,
AlertOptions,
ModalController,
NavParams,
ToastController,
} from "@ionic/angular";
import { TranslateService } from "@ngx-translate/core";
import { User } from "firebase/auth";
import {
Expand Down Expand Up @@ -50,7 +57,7 @@ export class HelferDetailPage implements OnInit {
private readonly authService: AuthService,
private cdr: ChangeDetectorRef,
private translate: TranslateService
) { }
) {}

ngOnInit() {
this.event = this.navParams.get("data");
Expand All @@ -63,9 +70,6 @@ export class HelferDetailPage implements OnInit {
this.event.clubId,
this.event.id
);
/*this.schichten$.subscribe(data=>{
console.log(data);
})*/
}

getHelferEvent(clubId: string, eventId: string) {
Expand Down Expand Up @@ -122,6 +126,9 @@ export class HelferDetailPage implements OnInit {
status: attendeesWithDetails.find(
(att) => att.id == this.user.uid
)?.status,
confirmed: attendeesWithDetails.find(
(att) => att.id == this.user.uid
)?.confirmed,
}))
);
}),
Expand All @@ -130,6 +137,7 @@ export class HelferDetailPage implements OnInit {
...event,
attendees: [],
status: null,
confirmed: null,
})
)
);
Expand All @@ -141,8 +149,6 @@ export class HelferDetailPage implements OnInit {
);
}



getHelferEventSchichtenWithAttendees(clubId: string, eventId: string) {
return this.eventService
.getClubHelferEventSchichtenRef(clubId, eventId)
Expand All @@ -152,8 +158,10 @@ export class HelferDetailPage implements OnInit {
return of([]); // Return an empty array if no schichten are found
}
// Sort schichten by ID in ascending order
const sortedSchichten = schichten.sort((a, b) => a.timeFrom.localeCompare(b.timeFrom));
console.log(schichten)
const sortedSchichten = schichten.sort((a, b) =>
a.timeFrom.localeCompare(b.timeFrom)
);
console.log(schichten);
console.log(sortedSchichten);
// Fetch attendees for each schicht
const schichtenWithAttendees$ = sortedSchichten.map((schicht) =>
Expand All @@ -165,14 +173,15 @@ export class HelferDetailPage implements OnInit {
)
.pipe(
switchMap((attendees) => {
console.log(attendees) // <- this line is never called
console.log(attendees); // <- this line is never called
if (attendees.length === 0) {
return of({
...schicht,
attendees: [],
attendeeListTrue: [],
attendeeListFalse: [],
status: null
status: null,
confirmed: null,
}); // Return schicht with empty attendees array
}

Expand All @@ -184,7 +193,7 @@ export class HelferDetailPage implements OnInit {
take(1),
map((profile) => ({
...profile,
...attendee
...attendee,
})), // Combine attendee object with profile
catchError(() =>
of({
Expand All @@ -209,13 +218,20 @@ export class HelferDetailPage implements OnInit {
status: attendeesWithDetails.find(
(att) => att.id == this.user.uid
)?.status,
})),

confirmed: attendeesWithDetails.find(
(att) => att.id == this.user.uid
)?.confirmed,
}))
);
}),
catchError((err) => {
console.log(err);
return of({ ...schicht, attendees: [], status: null })
return of({
...schicht,
attendees: [],
status: null,
confirmed: null,
});
}) // Fallback for error in fetching attendees
)
);
Expand All @@ -230,61 +246,90 @@ export class HelferDetailPage implements OnInit {
}

async confirmSchichten() {

this.getHelferEventSchichtenWithAttendees(
this.event.clubId,
this.event.id
).pipe(
take(1),
map(schichten=>{
let alertInputs = [];

schichten.map(schicht => {
schicht.attendeeListTrue.map(member => {
alertInputs.push({
name: member.id,
type: "checkbox",
checked: true,
value: { "memberId": member.id, "schichtId": schicht.id, "eventId": this.event.id },
label: member.firstName + " " + member.lastName + " - " + schicht.name
this.getHelferEventSchichtenWithAttendees(this.event.clubId, this.event.id)
.pipe(
take(1),
map((schichten) => {
let alertInputs = [];

schichten.map((schicht) => {
schicht.attendeeListTrue.map((member) => {
if (!member.confirmed && member.status) {
alertInputs.push({
name: member.id,
type: "checkbox",
checked: true,
value: {
memberId: member.id,
schichtId: schicht.id,
eventId: this.event.id,
},
label:
member.firstName +
" " +
member.lastName +
" - " +
schicht.name,
});
}
});
})
});

if (alertInputs.length > 0){


this.alertController.create({
header: "Helfereinsätze bestätigen",
message: "Bitte wählen Sie die Mitglieder aus:",
inputs: alertInputs,
buttons: [{
text: "Abbrechen",
handler: () => {
console.log("abbrechen");
}
}, {
text: "bestätigen",
handler: (event) => {
console.log(event);
}
}]
}).then(alert => {
alert.present();
});

if (alertInputs.length > 0) {
this.alertController
.create({
header: "Helfereinsätze bestätigen",
message: "Bitte wählen Sie die Mitglieder aus:",
inputs: alertInputs,
buttons: [
{
text: "Abbrechen",
handler: () => {
console.log("abbrechen");
},
},
{
text: "bestätigen",
handler: async (event) => {
// console.log(event);

for (const index in event) {
const el = event[index];
console.log(el);
await this.eventService.setClubHelferEventSchichtAttendeeStatusConfirm(
this.event.clubId,
el.eventId,
el.schichtId,
el.memberId
);
}
},
},
],
})
.then((alert) => {
alert.present();
});
} else {
this.toastController
.create({
message: "Keine Einsätze zum bestätigen verfügbar",
position: "top",
color: "primary",
duration: 1500,
})
.then((toast) => {
toast.present();
});
}
})
} else {
alert("keine mitglieder")
}
})
).subscribe(data=>{
console.log(data)
});


)
.subscribe((data) => {
console.log(data);
});
}

async toggleSchicht(status: boolean, schicht) {

console.log(`Set Status ${status}`);
await this.eventService.setClubHelferEventSchichtAttendeeStatus(
status,
Expand All @@ -295,7 +340,6 @@ export class HelferDetailPage implements OnInit {
this.presentToast();

this.toggle(status, this.event);

}

async openMember(member: Profile) {
Expand Down
Loading

0 comments on commit 5a4baf9

Please sign in to comment.