From 48f162ce0b27bccf19fd3a7b055b62a6112a11af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 12 Nov 2023 11:12:47 +0100 Subject: [PATCH] Adapt datetime-picker --- .../date-time-picker/date-time-picker.component.ts | 12 ++++++++++-- .../basic-scheduler/basic-scheduler.component.ts | 13 +++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/date-time-picker/date-time-picker.component.ts b/frontend/src/app/date-time-picker/date-time-picker.component.ts index a5ffd9e..d37b992 100644 --- a/frontend/src/app/date-time-picker/date-time-picker.component.ts +++ b/frontend/src/app/date-time-picker/date-time-picker.component.ts @@ -1,4 +1,4 @@ -import {Component, EventEmitter, Output, ViewChild} from "@angular/core"; +import {Component, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild} from "@angular/core"; import {MatDatepicker} from "@angular/material/datepicker"; import {NgxMaterialTimepickerComponent, NgxMaterialTimepickerToggleComponent} from "ngx-material-timepicker"; import {FormControl, Validators} from "@angular/forms"; @@ -8,11 +8,13 @@ import {FormControl, Validators} from "@angular/forms"; templateUrl: './date-time-picker.component.html', styleUrls: ['./date-time-picker.component.css'] }) -export class DateTimePickerComponent { +export class DateTimePickerComponent implements OnInit, OnChanges{ @ViewChild('picker') picker?: MatDatepicker; @ViewChild('toggleTimepicker') toggleTimepicker?: NgxMaterialTimepickerComponent @Output('onTimeSet') timeSet: EventEmitter = new EventEmitter(); + @Input('date') date: Date | undefined + dateControl: FormControl = new FormControl('', [Validators.required]) timeControl: FormControl = new FormControl('', [Validators.required]) constructor() { } @@ -21,6 +23,12 @@ export class DateTimePickerComponent { } + ngOnChanges() { + if(this.date != undefined) { + this.setDateTime(this.date); + } + } + setDateTime(date: Date) { console.log(date) this.dateControl.setValue(date); diff --git a/frontend/src/app/schedules/basic-scheduler/basic-scheduler.component.ts b/frontend/src/app/schedules/basic-scheduler/basic-scheduler.component.ts index e13bef8..f3c81e7 100644 --- a/frontend/src/app/schedules/basic-scheduler/basic-scheduler.component.ts +++ b/frontend/src/app/schedules/basic-scheduler/basic-scheduler.component.ts @@ -2,7 +2,7 @@ import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges import {FormControl, Validators} from "@angular/forms"; import { BasicScheduleEntityInfo, - BasicScheduleInfo, + BasicScheduleInfo, ScheduleInfo, ScheduleService, TaskEntityInfo, TaskgroupEntityInfo @@ -20,7 +20,7 @@ export class BasicSchedulerComponent implements OnChanges{ dateCtrl: FormControl = new FormControl('', [Validators.required]) @Input('taskgroup') taskgroup: TaskgroupEntityInfo | undefined @Input('task') task: TaskEntityInfo | undefined - @Input('scheduleInfo') scheduleEntityInfo: BasicScheduleEntityInfo | undefined + @Input('scheduleInfo') scheduleEntityInfo: ScheduleInfo | undefined @Output('onSchedule') scheduleEmitter: EventEmitter = new EventEmitter(); constructor(private scheduleService: ScheduleService, @@ -72,13 +72,10 @@ export class BasicSchedulerComponent implements OnChanges{ ngOnChanges(): void { if(this.scheduleEntityInfo != undefined) { - this.dateCtrl.setValue(this.scheduleEntityInfo!.scheduleID) + const schedule = this.scheduleEntityInfo as BasicScheduleInfo + this.dateCtrl.setValue(schedule.scheduleDate) } } - setEditedBasicSchedule(basicSchedule: BasicScheduleEntityInfo) { - this.dateCtrl.setValue(basicSchedule.scheduleDate) - this.scheduleEntityInfo = basicSchedule; - console.log(this.dateCtrl.value) - } + }