improve calendar event creation
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<full-calendar #calendar [options]="calendarOptions"></full-calendar>
|
||||
</div>
|
||||
|
||||
<rs-daisy-modal [isOpen]="isOpen()" (closeClick)="closeDialog()" >
|
||||
<rs-daisy-modal [isOpen]="isOpen()" (closeClick)="closeDialog()" >
|
||||
@if (isOpen()){
|
||||
<app-create-event-form (ready)="closeDialog()" [date]="selectedDate()" [id]="selectedEventId()"></app-create-event-form>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- Generated by the CLI -->
|
||||
<div class="p-4 md:p-8">
|
||||
<div class="card bg-base-100 shadow-xl max-w-2xl mx-auto">
|
||||
<div class="card bg-base-100 shadow-xl mx-auto">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-3xl">
|
||||
Esemény {{ isEditMode ? 'szerkesztése' : 'létrehozása' }}
|
||||
@@ -39,7 +39,7 @@
|
||||
</label></div>
|
||||
|
||||
@if (isRecurring?.value) {
|
||||
<div formGroupName="recurringRule" class="space-y-4 p-4 border border-base-300 rounded-lg">
|
||||
<div formGroupName="recurrenceRule" class="space-y-4 p-4 border border-base-300 rounded-lg">
|
||||
<h3 class="text-lg font-semibold">Ismétlődés</h3>
|
||||
|
||||
<div class="form-control">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, input, OnInit, output, signal } from '@angular/core';
|
||||
import { Component, effect, input, OnInit, output, signal } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { EventService } from '../../../events/services/event.service';
|
||||
@@ -31,10 +31,9 @@ export class CreateEventForm implements OnInit {
|
||||
ready = output<void>();
|
||||
id= input<number | undefined>() ;
|
||||
date = input<Date|undefined>();
|
||||
|
||||
eventTypes = signal<EventType[]>([])
|
||||
|
||||
private numericFields = ["event_type_id"];
|
||||
private numericFields: (keyof EventFormDTO)[] = ["event_type_id"];
|
||||
|
||||
frequencyOptions: FrequencyOption[] = [
|
||||
{
|
||||
@@ -78,9 +77,9 @@ export class CreateEventForm implements OnInit {
|
||||
startTime: [null,Validators.required],
|
||||
endTime: [null,Validators.required],
|
||||
is_recurring: [false],
|
||||
recurringRule: this.fb.group({
|
||||
frequency: [null] ,//'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY';
|
||||
interval: [null] ,//number
|
||||
recurrenceRule: this.fb.group({
|
||||
frequency: ['DAILY'] ,//'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY';
|
||||
interval: [1] ,//number
|
||||
endDate: [null], // Date
|
||||
count: [null], // number
|
||||
byDay: [null], // string
|
||||
@@ -89,11 +88,18 @@ export class CreateEventForm implements OnInit {
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
console.info("effect run")
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
console.info("oninit run")
|
||||
this.isRecurring?.valueChanges.subscribe(isRecurring => {
|
||||
const recurringRule = this.form.get('recurringRule');
|
||||
const recurringRule = this.form.get('recurrenceRule');
|
||||
const frequency = recurringRule?.get('frequency');
|
||||
const interval = recurringRule?.get('interval');
|
||||
|
||||
@@ -183,24 +189,25 @@ export class CreateEventForm implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
const payload: EventFormDTO|any = { ...this.form.value };
|
||||
const payload: EventFormDTO = { ...this.form.value };
|
||||
|
||||
if (!payload.is_recurring) {
|
||||
delete payload.recurringRule;
|
||||
delete payload.recurrenceRule;
|
||||
}
|
||||
|
||||
for (const field of this.numericFields) {
|
||||
if (payload[field] != null && payload[field] !== '') {
|
||||
payload[field] = parseFloat(payload[field]);
|
||||
if ( typeof payload[field] !== 'number'){
|
||||
payload[field] = parseFloat(payload[field] as string) as never;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let action$: Observable<Event>;
|
||||
let action$: Observable<Event|undefined>;
|
||||
|
||||
if (this.isEditMode && this.id()) {
|
||||
console.info("rong branch")
|
||||
// action$ = this.calendarService.update(this.id()!, payload);
|
||||
action$ = of(payload);
|
||||
action$ = this.calendarService.update(this.id()!, payload);
|
||||
// action$ = of(undefined);
|
||||
} else {
|
||||
action$ = this.calendarService.create(payload);
|
||||
}
|
||||
@@ -233,31 +240,31 @@ export class CreateEventForm implements OnInit {
|
||||
}
|
||||
|
||||
get recurringRule(){
|
||||
return this.form.get('recurringRule');
|
||||
return this.form.get('recurrenceRule');
|
||||
}
|
||||
|
||||
get frequency(){
|
||||
return this.form.get('recurringRule')?.get('frequency');
|
||||
return this.form.get('recurrenceRule')?.get('frequency');
|
||||
}
|
||||
|
||||
get interval(){
|
||||
return this.form.get('recurringRule')?.get('interval');
|
||||
return this.form.get('recurrenceRule')?.get('interval');
|
||||
}
|
||||
|
||||
get endDate(){
|
||||
return this.form.get('recurringRule')?.get('endDate');
|
||||
return this.form.get('recurrenceRule')?.get('endDate');
|
||||
}
|
||||
|
||||
get byDay() {
|
||||
return this.form.get('recurringRule')?.get('byDay');
|
||||
return this.form.get('recurrenceRule')?.get('byDay');
|
||||
}
|
||||
|
||||
get byMonthDay() {
|
||||
return this.form.get('recurringRule')?.get('byMonthDay');
|
||||
return this.form.get('recurrenceRule')?.get('byMonthDay');
|
||||
}
|
||||
|
||||
get byMonth() {
|
||||
return this.form.get('recurringRule')?.get('byMonth');
|
||||
return this.form.get('recurrenceRule')?.get('byMonth');
|
||||
}
|
||||
|
||||
doReady(){
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
// dvbooking-cli/src/templates/angular/model.ts.tpl
|
||||
|
||||
|
||||
export interface RecurrenceRuleDto {
|
||||
frequency: 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY';
|
||||
|
||||
interval: number;
|
||||
|
||||
byDay?: string; // e.g., 'MO,TU,WE,TH,FR'
|
||||
|
||||
endDate?: Date;
|
||||
|
||||
count?: number;
|
||||
}
|
||||
|
||||
|
||||
// Generated by the CLI
|
||||
export interface EventFormDTO {
|
||||
id?: number;
|
||||
@@ -9,4 +23,7 @@ export interface EventFormDTO {
|
||||
start_time?: Date;
|
||||
end_time?: Date;
|
||||
is_recurring: boolean;
|
||||
recurrenceRule?: RecurrenceRuleDto;
|
||||
}
|
||||
|
||||
export interface UpdateEventFormDTO extends Partial<EventFormDTO>{}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ConfigurationService } from '../../../services/configuration.service';
|
||||
import { EventFormDTO } from '../models/event-form-dto.model';
|
||||
import { EventFormDTO, UpdateEventFormDTO } from '../models/event-form-dto.model';
|
||||
import { Event } from '../../events/models/event.model';
|
||||
import { CalendarEventDto, EventsInRangeDTO } from '../models/events-in-range-dto.model';
|
||||
|
||||
@@ -36,4 +36,8 @@ export class CalendarService {
|
||||
return this.http.post<Event>(this.apiUrl+'/events', data);
|
||||
}
|
||||
|
||||
public update(id: number,data: UpdateEventFormDTO): Observable<Event> {
|
||||
return this.http.put<Event>(this.apiUrl+'/events', data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user