1+ @page " /tests/scheduler"
2+ @using Bogus
3+ <Row >
4+ <Column >
5+ <Card Margin =" Margin.Is4.OnY" >
6+ <CardHeader >
7+ <CardTitle >Scheduler</CardTitle >
8+ </CardHeader >
9+ <CardBody >
10+ <Scheduler TItem =" SchedulerAppointment" @bind-Date =" @selectedDate"
11+ Data =" @Appointments"
12+ @bind-SelectedView =" @selectedView"
13+ Editable
14+ Draggable
15+ ItemStyling =" @OnItemStyling"
16+ SlotSelectionMode =" SchedulerSlotSelectionMode.Mouse" >
17+ <SchedulerToolbar />
18+ <SchedulerViews >
19+ <SchedulerDayView StartTime =" @(new TimeOnly( 7, 0 ))" EndTime =" @(new TimeOnly( 17, 0 ))" WorkDayStart =" @(new TimeOnly( 8, 0 ))" WorkDayEnd =" @(new TimeOnly( 16, 0 ))" />
20+ <SchedulerWeekView StartTime =" @(new TimeOnly( 7, 0 ))" EndTime =" @(new TimeOnly( 17, 0 ))" WorkDayStart =" @(new TimeOnly( 8, 0 ))" WorkDayEnd =" @(new TimeOnly( 16, 0 ))" />
21+ <SchedulerWorkWeekView StartTime =" @(new TimeOnly( 7, 0 ))" EndTime =" @(new TimeOnly( 17, 0 ))" WorkDayStart =" @(new TimeOnly( 8, 0 ))" WorkDayEnd =" @(new TimeOnly( 16, 0 ))" />
22+ <SchedulerMonthView StartTime =" @(new TimeOnly( 7, 0 ))" EndTime =" @(new TimeOnly( 17, 0 ))" WorkDayStart =" @(new TimeOnly( 8, 0 ))" WorkDayEnd =" @(new TimeOnly( 16, 0 ))" />
23+ </SchedulerViews >
24+ </Scheduler >
25+ </CardBody >
26+ </Card >
27+ </Column >
28+ </Row >
29+ <Row >
30+ <Column >
31+ Selected date: @selectedDate
32+ </Column >
33+ </Row >
34+ @code {
35+ [Inject ] IMessageService MessageService { get ; set ; }
36+ private DateOnly selectedDate = DateOnly .FromDateTime ( DateTime .Today );
37+ private SchedulerView selectedView = SchedulerView .Week ;
38+
39+ private static DateTime start = DateTime .Today .AddHours ( 10 );
40+
41+ private Faker <SchedulerAppointment > appointmentFaker = new Faker <SchedulerAppointment >()
42+ .RuleFor ( a => a .Title , f => f .Lorem .Sentence ( 3 ) )
43+ .RuleFor ( a => a .Description , f => f .Lorem .Paragraph () );
44+
45+ private Task OnSlotClicked ( SchedulerSlotClickedEventArgs eventArgs )
46+ {
47+ var start = eventArgs .Start ;
48+ var end = eventArgs .End ;
49+
50+ var fakeAppointment = appointmentFaker .Generate ();
51+ fakeAppointment .Start = start ;
52+ fakeAppointment .End = end ;
53+
54+ Appointments .Add ( fakeAppointment );
55+
56+ return Task .CompletedTask ;
57+ }
58+
59+ private async Task <bool > IsDropAllowed ( SchedulerDragEventArgs < SchedulerAppointment > eventArgs )
60+ {
61+ await MessageService .Warning ( " You cannot drop this appointment here" , " Drop not allowed" );
62+
63+ return false ;
64+ }
65+
66+ private void OnItemStyling ( SchedulerAppointment appointment , SchedulerItemStyling itemStyling )
67+ {
68+ if ( appointment .Title .Contains ( " ceo" , StringComparison .OrdinalIgnoreCase ) )
69+ itemStyling .Background = Background .Danger ;
70+ else if ( appointment .Title .Contains ( " client" , StringComparison .OrdinalIgnoreCase ) )
71+ itemStyling .Background = Background .Success ;
72+ else if ( appointment .Title .Contains ( " lunch" , StringComparison .OrdinalIgnoreCase ) )
73+ itemStyling .Background = Background .Info ;
74+ }
75+
76+ public class SchedulerAppointment
77+ {
78+ public SchedulerAppointment ()
79+ {
80+ }
81+
82+ public SchedulerAppointment ( string title , string description , DateTime start , DateTime end , bool allDay = false )
83+ {
84+ Id = Guid .NewGuid ().ToString ();
85+ Title = title ;
86+ Description = description ;
87+ Start = start ;
88+ End = end ;
89+ AllDay = allDay ;
90+ }
91+
92+ public SchedulerAppointment ( string id , string title , string description , DateTime start , DateTime end , bool allDay = false )
93+ {
94+ Id = id ;
95+ Title = title ;
96+ Description = description ;
97+ Start = start ;
98+ End = end ;
99+ AllDay = allDay ;
100+ }
101+
102+ public string Id { get ; set ; }
103+
104+ public string Title { get ; set ; }
105+
106+ public string Description { get ; set ; }
107+
108+ public DateTime Start { get ; set ; }
109+
110+ public DateTime End { get ; set ; }
111+
112+ public bool AllDay { get ; set ; }
113+
114+ public string RecurrenceRule { get ; set ; }
115+
116+ public string RecurrenceId { get ; set ; }
117+
118+ public List <DateTime > DeletedOccurrences { get ; set ; }
119+
120+ public DateTime ? OriginalStart { get ; set ; }
121+
122+ public List <SchedulerAppointment > RecurrenceExceptions { get ; set ; }
123+ }
124+
125+ List <SchedulerAppointment > Appointments = new List <SchedulerAppointment >
126+ {
127+ new SchedulerAppointment ( " Meeting with the CEO" , " Regarding the new margeting strategy" , start , start .AddHours (1 ) ),
128+ new SchedulerAppointment ( " Some other meeting" , " Regarding the new margeting strategy" , start , start .AddHours (1 ) ),
129+ new SchedulerAppointment ( " Lunch with the team" , " Discussing the new project" , start .AddDays (- 10 ).AddHours (2 ), start .AddDays (- 10 ).AddHours (3 ))
130+ {
131+ RecurrenceRule = " FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;INTERVAL=2;COUNT=3"
132+ // RecurrenceRule = "FREQ=DAILY;INTERVAL=1;COUNT=10;"
133+ // RecurrenceRule = "FREQ=MONTHLY;INTERVAL=2;BYMONTHDAY=1;COUNT=2;"
134+ },
135+ new SchedulerAppointment ( " Meeting with the client" , " Discussing the new project" , start .AddHours (4 ), start .AddHours (5 ) ),
136+ new SchedulerAppointment ( " Test 1" , " Test 1 desc" , DateTime .Today .AddDays (- 2 ), DateTime .Today .AddDays (- 2 ), true ),
137+ new SchedulerAppointment ( " All day event with the team" , " Team building" , DateTime .Today .AddDays (- 2 ), DateTime .Today , true ),
138+ new SchedulerAppointment ( " Games with the team" , " Having fun" , DateTime .Today , DateTime .Today , true ),
139+ };
140+ }
0 commit comments