This is my Angular component:
export class SchedulerComponent implements AfterViewInit {
@ViewChild(BryntumCalendarComponent)
calendarComponent!: BryntumCalendarComponent;
http = inject(HttpClient);
service = inject(SchedulersService);
startDate = new Date();
endDate = new Date();
events: ScheduledJob[] = [];
calendarProps: BryntumCalendarProps;
constructor() {
const today = new Date();
const dayOfWeek = today.getDay();
this.startDate.setDate(today.getDate() - dayOfWeek);
this.endDate.setDate(today.getDate() + (7 - dayOfWeek));
this.calendarProps = {
date: new Date(),
eventEditFeature: {
items: {
location: {
type: 'textfield',
name: 'location',
label: 'Location',
dataset: { eventType: 'Meeting' },
},
},
},
eventTooltipFeature: {
align: 'l-r',
} as object,
modes: {
twoWeek: {
type: 'dayview',
range: '2 weeks',
title: '2 weeks',
},
year: null,
week: {
eventRenderer: ({
eventRecord,
}: {
eventRecord: EventModel;
}): string => {
const value = eventRecord.get('value');
const name = eventRecord.get('name');
const id = eventRecord.get('id');
return `
<div>${id}</div>
<div>${name}</div>
<div>${value}</div>`;
},
},
},
};
}
updateData() {
const config: SchedulerConfigurations = {
startDate: this.startDate,
endDate: this.endDate,
};
this.service.getSchedulerData(config).subscribe((result) => {
this.events = result.data;
});
}
ngAfterViewInit() {
this.updateData();
}
onDateRangeChange(event: any): void {
this.startDate = new Date(event.new.startDate);
this.endDate = new Date(event.new.endDate);
this.updateData();
}
}
HTML code:
<bryntum-calendar
[date]="calendarProps.date!"
[events]="events"
[modes]="calendarProps.modes!"
[eventTooltipFeature]="calendarProps.eventTooltipFeature!"
[includeWeekendsButton]="true"
(onDateRangeChange)="onDateRangeChange($event)"
></bryntum-calendar>
Service:
export class SchedulersService {
private httpClient = inject(HttpClient);
get csaUrl(): string {
return sessionStorage.getItem('csa-url') as string;
}
getSchedulerData(schedulerConfiguration: SchedulerConfigurations) {
const params = new HttpParams()
.set('startDateTime', schedulerConfiguration.startDate.toISOString())
.set('endDateTime', schedulerConfiguration.endDate.toISOString());
const url = this.csaUrl + 'api/scheduler/jobs-quotes-orders';
return this.httpClient.get(url, { params }).pipe(
map((result: any) => ({
data: result as ScheduledJob[],
})),
catchError((error) => {
return throwError(() => error);
}),
);
}
}
Interfaces:
export interface ScheduledJob {
id: number;
name: string;
startDate: Date;
endDate: Date;
dateType: string;
unit: string;
value: number;
allDay: boolean;
}
export interface SchedulerConfigurations {
startDate: Date;
endDate: Date;
}