|
|
@@ -26,36 +26,41 @@ export class EventEditComponent {
|
|
|
public ngOnInit(): void {
|
|
|
if (this.isCreateMode) {
|
|
|
this.event = new GroupEvent();
|
|
|
+ } 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');
|
|
|
+ });
|
|
|
}
|
|
|
- // this.eventsApi.getTrack(this.trackId).then(track => {
|
|
|
- // this.track = track;
|
|
|
- // });
|
|
|
}
|
|
|
|
|
|
public updateEvent(event: SubmitEvent): void {
|
|
|
- console.log({ date: this.startDate, time: this.startTime});
|
|
|
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;
|
|
|
}
|
|
|
- console.log(this.event);
|
|
|
- if (this.isCreateMode) {
|
|
|
- this.eventsApi.createEvent(this.event!);
|
|
|
+
|
|
|
+ if (this.event)
|
|
|
+ {
|
|
|
+ if (this.isCreateMode) {
|
|
|
+ this.eventsApi.createEvent(this.event);
|
|
|
+ } else {
|
|
|
+ this.eventsApi.updateEvent(this.event);
|
|
|
+ }
|
|
|
}
|
|
|
- // if (this.track) {
|
|
|
- // this.tracksApi.updateTrack(this.track).then(result => {
|
|
|
- // this.track = result;
|
|
|
- // });
|
|
|
- // }
|
|
|
}
|
|
|
|
|
|
public deleteEvent(): void {
|
|
|
- // if (this.track) {
|
|
|
- // this.tracksApi.deleteTrack(this.track).then(() => {
|
|
|
- // this.router.navigateByUrl("/tracks");
|
|
|
- // });
|
|
|
- // }
|
|
|
+ if (this.event) {
|
|
|
+ this.eventsApi.deleteEvent(this.event).then(() => {
|
|
|
+ this.router.navigateByUrl("/events");
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|