|
|
@@ -1,5 +1,7 @@
|
|
|
import { Component, Input } from '@angular/core';
|
|
|
+import { NgForm } from '@angular/forms';
|
|
|
import { Router } from '@angular/router';
|
|
|
+import { DateTime } from 'src/app/datetime';
|
|
|
import { EventsApiService } from 'src/app/events-api.service';
|
|
|
import { GroupEvent } from '../group-event';
|
|
|
|
|
|
@@ -15,7 +17,7 @@ export class EventEditComponent {
|
|
|
public isCreateMode: boolean = false;
|
|
|
|
|
|
public event: GroupEvent | null = null;
|
|
|
- public startDate: Date | null = null;
|
|
|
+ public startDate: string = '';
|
|
|
public startTime: string = '';
|
|
|
|
|
|
public constructor(
|
|
|
@@ -29,29 +31,32 @@ export class EventEditComponent {
|
|
|
} else {
|
|
|
this.eventsApi.getEvent(this.eventId).then(event => {
|
|
|
this.event = event;
|
|
|
- this.startDate = new Date(this.event.startTime ?? new Date());
|
|
|
- this.startTime =
|
|
|
- (this.event.startTime?.getHours() ?? 0).toString().padStart(2, '0')
|
|
|
- + ':'
|
|
|
- + (this.event.startTime?.getMinutes() ?? 0).toString().padStart(2, '0');
|
|
|
+ const date = this.event.startTime ?? new DateTime();
|
|
|
+ this.startDate = date.toDateString();
|
|
|
+ this.startTime = date.toTimeString();
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public updateEvent(event: SubmitEvent): void {
|
|
|
- const match = this.startTime.match(/(\d{1,2}):(\d{1,2})/);
|
|
|
- if (this.startDate && match) {
|
|
|
- this.startDate.setHours(parseInt(match[1]));
|
|
|
- this.startDate.setMinutes(parseInt(match[2]));
|
|
|
- this.event!.startTime = this.startDate;
|
|
|
+ public updateEvent(form: NgForm, event: SubmitEvent): void {
|
|
|
+ if (!form.valid) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.startDate) {
|
|
|
+ this.event!.startTime = DateTime.fromLocalDateAndTime(this.startDate, this.startTime);
|
|
|
}
|
|
|
|
|
|
if (this.event)
|
|
|
{
|
|
|
if (this.isCreateMode) {
|
|
|
- this.eventsApi.createEvent(this.event);
|
|
|
+ this.eventsApi.createEvent(this.event).then(result => {
|
|
|
+ this.router.navigateByUrl(`events/edit/${result.eventId}`);
|
|
|
+ })
|
|
|
} else {
|
|
|
- this.eventsApi.updateEvent(this.event);
|
|
|
+ this.eventsApi.updateEvent(this.event).then(result => {
|
|
|
+ this.router.navigateByUrl(`events/edit/${result.eventId}`);
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|