From e97cafd1ac799fcf196154249e1c3602c8dad4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Thu, 30 Sep 2021 13:41:46 +0200 Subject: [PATCH] Writing notifying framework to pass selected date to parent component --- Frontend/src/app/app.module.ts | 3 ++- .../app/components/datepicker/datepicker.component.ts | 6 +++--- .../app/pages/landingpage/landingpage.component.html | 2 +- .../src/app/pages/landingpage/landingpage.component.ts | 10 ++++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Frontend/src/app/app.module.ts b/Frontend/src/app/app.module.ts index 0147992..a0385c6 100644 --- a/Frontend/src/app/app.module.ts +++ b/Frontend/src/app/app.module.ts @@ -14,6 +14,7 @@ import {DatepickerComponent} from './components/datepicker/datepicker.component' import {EventDetailComponent} from './components/event-detail/event-detail.component'; import {HttpClientModule} from '@angular/common/http'; import {FormsModule} from '@angular/forms'; +import {ApiService} from './services/api/api.service'; @NgModule({ declarations: [ @@ -34,7 +35,7 @@ import {FormsModule} from '@angular/forms'; NgbModule, FormsModule ], - providers: [], + providers: [ApiService], bootstrap: [AppComponent] }) export class AppModule { diff --git a/Frontend/src/app/components/datepicker/datepicker.component.ts b/Frontend/src/app/components/datepicker/datepicker.component.ts index 2e3d135..804c018 100644 --- a/Frontend/src/app/components/datepicker/datepicker.component.ts +++ b/Frontend/src/app/components/datepicker/datepicker.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, EventEmitter, OnInit, Output} from '@angular/core'; @Component({ selector: 'app-datepicker', @@ -16,7 +16,7 @@ export class DatepickerComponent implements OnInit { itIsWednesday: boolean = false; - selectedMonday: string = ''; + @Output() selectedMonday = new EventEmitter(); constructor() { } @@ -122,7 +122,7 @@ export class DatepickerComponent implements OnInit { */ handleDateChange(): void { let mondayDate = this.findMondayInWeek(this.selectedYear, this.selectedMonth, this.selectedDay); - this.selectedMonday = mondayDate; + this.selectedMonday.emit(mondayDate); } /** diff --git a/Frontend/src/app/pages/landingpage/landingpage.component.html b/Frontend/src/app/pages/landingpage/landingpage.component.html index 1f323c7..baac77d 100644 --- a/Frontend/src/app/pages/landingpage/landingpage.component.html +++ b/Frontend/src/app/pages/landingpage/landingpage.component.html @@ -1,6 +1,6 @@

TINF19B4 RaPla Changes

- +
Events: {{eventCount}} diff --git a/Frontend/src/app/pages/landingpage/landingpage.component.ts b/Frontend/src/app/pages/landingpage/landingpage.component.ts index ce70492..73ea543 100644 --- a/Frontend/src/app/pages/landingpage/landingpage.component.ts +++ b/Frontend/src/app/pages/landingpage/landingpage.component.ts @@ -11,19 +11,25 @@ export class LandingpageComponent implements OnInit { events: Event[] = []; eventCount: number = 0; + selectedDate: string = ''; + constructor( private apiService: ApiService ) { } ngOnInit(): void { - this.getEvents(); } getEvents() { - this.apiService.getEvents('2021-10-04').subscribe(events => { + this.apiService.getEvents(this.selectedDate).subscribe(events => { this.events = events; this.eventCount = events.length; }); } + + dateChangedFromPicker(newDate: string) { + this.selectedDate = newDate; + this.getEvents(); + } }