Skip to content

Commit

Permalink
feat training
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Sep 13, 2023
1 parent e5f1a4a commit d113ea2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
Expand Down Expand Up @@ -51,6 +52,7 @@ import { TeamPage } from './pages/team/team.page';
FontAwesomeModule,
IonicModule.forRoot(),
AppRoutingModule,
FormsModule,
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: environment.production,
// Register the ServiceWorker as soon as the app is stable
Expand Down
8 changes: 4 additions & 4 deletions src/app/models/training.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export interface Training {
// actual date of training
date: Date;

timeFrom: Date;
timeTo: Date;
timeFrom: string;
timeTo: string;

// Fields for calculation
startDate: Date;
endDate: Date;
startDate: string;
endDate: string;

repeatAmount: string,
repeatFrequency: string,
Expand Down
27 changes: 15 additions & 12 deletions src/app/pages/training/training-create/training-create.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@
<ion-list>

<ion-item>
<ion-select label="Team" label-placement="stacked" value="{{training.teamId}}" >
<ion-select label="Team" label-placement="stacked" [(ngModel)]="training.teamId" value="{{training.teamId}}" >
<ion-select-option *ngFor="let team of teamList" value="{{team.id}}">{{team.name}}</ion-select-option>
</ion-select>
</ion-item>

<ion-item>
<ion-input label="Name" label-placement="stacked" value="{{training.name}}">
<ion-input label="Name" label-placement="stacked" [(ngModel)]="training.name" value="{{training.name}}">
</ion-input>
</ion-item>
<ion-item>

<ion-textarea
label="Beschreibung" label-placement="stacked"
value="{{training.description}}"
value="{{training.description}}" [(ngModel)]="training.description"
>
</ion-textarea>
</ion-item>
<ion-item>

<ion-input
label="Strasse & Hausnummer" label-placement="stacked"
value="{{training.streetAndNumber}}"
value="{{training.streetAndNumber}}" [(ngModel)]="training.streetAndNumber"
>
</ion-input>
</ion-item>
<ion-item>
<ion-input
label="Postleitzahl" label-placement="stacked"
value="{{training.postalCode}}"
value="{{training.postalCode}}" [(ngModel)]="training.postalCode"
>
</ion-input>
</ion-item>
<ion-item>

<ion-input label="Ortschaft" label-placement="stacked" value="{{training.city}}">
<ion-input label="Ortschaft" label-placement="stacked" value="{{training.city}}" [(ngModel)]="training.city">
</ion-input>
</ion-item>

Expand All @@ -58,7 +58,7 @@

<ion-modal [keepContentsMounted]="true">
<ng-template>
<ion-datetime presentation="time" id="timeFrom"></ion-datetime>
<ion-datetime presentation="time" id="timeFrom" value="{{training.timeFrom}}" [(ngModel)]="training.timeFrom"></ion-datetime>
</ng-template>
</ion-modal>
</ion-item>
Expand All @@ -69,19 +69,19 @@

<ion-modal [keepContentsMounted]="true">
<ng-template>
<ion-datetime presentation="time" id="timeTo"></ion-datetime>
<ion-datetime presentation="time" id="timeTo" value="{{training.timeTo}}" [(ngModel)]="training.timeTo"></ion-datetime>
</ng-template>
</ion-modal>
</ion-item>

<ion-list-header>Serien Einstellungen</ion-list-header>
<ion-item>

<ion-select label="Wiederholen" label-placement="stacked" value="{{training.repeatFrequency}}" >
<ion-select label="Wiederholen" label-placement="stacked" value="{{training.repeatFrequency}}" [(ngModel)]="training.repeatFrequency" >
<ion-select-option value="D">Täglich</ion-select-option>
<ion-select-option value="W">Wöchentlich</ion-select-option>
</ion-select>
<ion-select label="Alle" label-placement="stacked" value="{{training.repeatAmount}}" >
<ion-select label="Alle" label-placement="stacked" value="{{training.repeatAmount}}" [(ngModel)]="training.repeatAmount" >
<ion-select-option value="1">1</ion-select-option>
<ion-select-option value="2">2</ion-select-option>
<ion-select-option value="3">3</ion-select-option>
Expand All @@ -94,7 +94,8 @@

<ion-modal [keepContentsMounted]="true">
<ng-template>
<ion-datetime presentation="date" id="startDate"></ion-datetime>
<ion-datetime [firstDayOfWeek]="1" presentation="date" id="startDate"
value="{{training.startDate}}" [(ngModel)]="training.startDate"></ion-datetime>
</ng-template>
</ion-modal>
</ion-item>
Expand All @@ -105,7 +106,9 @@

<ion-modal [keepContentsMounted]="true">
<ng-template>
<ion-datetime presentation="date" id="endDate"></ion-datetime>
<ion-datetime [firstDayOfWeek]="1" presentation="date" id="endDate"
value="{{training.endDate}}" [(ngModel)]="training.endDate">
</ion-datetime>
</ng-template>
</ion-modal>
</ion-item>
Expand Down
16 changes: 12 additions & 4 deletions src/app/pages/training/training-create/training-create.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export class TrainingCreatePage implements OnInit {

date: new Date(),

timeFrom: new Date(),
timeTo: new Date(),
timeFrom: new Date().toISOString(),
timeTo: new Date().toISOString(),

startDate: new Date(),
endDate: new Date(),
startDate: new Date().toISOString(),
endDate: new Date().toISOString(),

repeatFrequency: "W",
repeatAmount: "1",
Expand Down Expand Up @@ -103,6 +103,14 @@ export class TrainingCreatePage implements OnInit {
}

async createTraining() {
//Set Hours/Minutes of endDate to TimeFrom of training
const calculatedDate = new Date(this.training.endDate);
calculatedDate.setHours(new Date(this.training.timeFrom).getHours());
calculatedDate.setMinutes(new Date(this.training.timeFrom).getMinutes());
calculatedDate.setSeconds(0);
calculatedDate.setMilliseconds(0);
this.training.endDate = calculatedDate.toISOString();

this.trainingService.setCreateTraining(this.training, this.user);
return this.modalCtrl.dismiss({}, "confirm");
}
Expand Down
1 change: 1 addition & 0 deletions src/app/services/firebase/training.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class TrainingService {

async setCreateTraining(training: Training, user: User) {
console.log("training");
console.log(training);
return addDoc(
collection(this.firestore, `userProfile/${user.uid}/trainings`),
training
Expand Down

0 comments on commit d113ea2

Please sign in to comment.