mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-02-04 05:35:44 +00:00
* Supply Appointment data to SchedulerSlotRenderEventArgs * Get appointments on demand * Revert YearView SlotRender code to remove breaking change. Update demo
This commit is contained in:
@@ -100,8 +100,9 @@ namespace Radzen.Blazor
|
||||
/// </summary>
|
||||
/// <param name="start">The start of the slot.</param>
|
||||
/// <param name="end">The end of the slot.</param>
|
||||
/// <param name="getAppointments">Function to return appointments for this range.</param>
|
||||
/// <returns>A dictionary containing the HTML attributes for the specified slot.</returns>
|
||||
IDictionary<string, object> GetSlotAttributes(DateTime start, DateTime end);
|
||||
IDictionary<string, object> GetSlotAttributes(DateTime start, DateTime end, Func<IEnumerable<AppointmentData>> getAppointments);
|
||||
/// <summary>
|
||||
/// Renders the appointment.
|
||||
/// </summary>
|
||||
|
||||
@@ -370,9 +370,9 @@ namespace Radzen.Blazor
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IDictionary<string, object> GetSlotAttributes(DateTime start, DateTime end)
|
||||
public IDictionary<string, object> GetSlotAttributes(DateTime start, DateTime end, Func<IEnumerable<AppointmentData>> getAppointments)
|
||||
{
|
||||
var args = new SchedulerSlotRenderEventArgs { Start = start, End = end, View = SelectedView };
|
||||
var args = new SchedulerSlotRenderEventArgs { Start = start, End = end, getAppointments = getAppointments, View = SelectedView };
|
||||
|
||||
SlotRender?.Invoke(args);
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
|
||||
IDictionary<string, object> Attributes(DateTime date)
|
||||
{
|
||||
var attributes = Scheduler.GetSlotAttributes(date, date.AddMinutes(MinutesPerSlot));
|
||||
var attributes = Scheduler.GetSlotAttributes(date, date.AddMinutes(MinutesPerSlot), () => AppointmentsInSlot(date, date.AddMinutes(MinutesPerSlot)));
|
||||
attributes["class"] = ClassList.Create("rz-slot").Add("rz-slot-minor", (date.Minute / MinutesPerSlot) % 2 == 1).Add(attributes).ToString();
|
||||
attributes["dropzone"] = "move";
|
||||
return attributes;
|
||||
|
||||
@@ -207,7 +207,7 @@
|
||||
|
||||
IDictionary<string, object> Attributes(DateTime start)
|
||||
{
|
||||
var attributes = Scheduler.GetSlotAttributes(start, start.AddDays(1));
|
||||
var attributes = Scheduler.GetSlotAttributes(start, start.AddDays(1), () => AppointmentsInSlot(start, start.AddDays(1)));
|
||||
attributes["class"] = ClassList.Create("rz-slot").Add(attributes).ToString();
|
||||
attributes["dropzone"] = "move";
|
||||
return attributes;
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
|
||||
IDictionary<string, object> Attributes(DateTime date)
|
||||
{
|
||||
var attributes = Scheduler.GetSlotAttributes(date, date.AddMinutes(MinutesPerSlot));
|
||||
var attributes = Scheduler.GetSlotAttributes(date, date.AddMinutes(MinutesPerSlot), () => AppointmentsInSlot(date, date.AddMinutes(MinutesPerSlot)));
|
||||
attributes["class"] = ClassList.Create("rz-slot").Add("rz-slot-minor", (date.Minute / MinutesPerSlot) % 2 == 1).Add(attributes).ToString();
|
||||
attributes["dropzone"] = "move";
|
||||
return attributes;
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
|
||||
IDictionary<string, object> Attributes(DateTime start, string className, bool slotInMonth)
|
||||
{
|
||||
var attributes = Scheduler.GetSlotAttributes(start, start.AddDays(1));
|
||||
var attributes = Scheduler.GetSlotAttributes(start, start.AddDays(1), () => AppointmentsInRange(start, start.AddDays(1)));
|
||||
attributes["class"] = ClassList.Create(className).Add(attributes).ToString();
|
||||
attributes["dropzone"] = "move";
|
||||
if (!slotInMonth)
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
|
||||
IDictionary<string, object> Attributes(DateTime start, string className, bool slotInMonth)
|
||||
{
|
||||
var attributes = Scheduler.GetSlotAttributes(start, start.AddDays(1));
|
||||
var attributes = Scheduler.GetSlotAttributes(start, start.AddDays(1), () => AppointmentsInRange(start, start.AddDays(1)));
|
||||
attributes["class"] = ClassList.Create(className).Add(attributes).ToString();
|
||||
attributes["dropzone"] = "move";
|
||||
if (!slotInMonth)
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
|
||||
IDictionary<string, object> Attributes(DateTime start, string className)
|
||||
{
|
||||
var attributes = Scheduler.GetSlotAttributes(start, start.AddDays(1));
|
||||
var attributes = Scheduler.GetSlotAttributes(start, start.AddDays(1), () => AppointmentsInRange(start, start.AddDays(1)));
|
||||
attributes["class"] = ClassList.Create(className).Add(attributes).ToString();
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,13 @@ namespace Radzen
|
||||
/// The end of the slot.
|
||||
/// </summary>
|
||||
public DateTime End { get; set; }
|
||||
// used to pass a function to get appointments on demand.
|
||||
internal Func<IEnumerable<AppointmentData>> getAppointments;
|
||||
private IEnumerable<AppointmentData> appointments;
|
||||
/// <summary>
|
||||
/// List of appointments.
|
||||
/// </summary>
|
||||
public IEnumerable<AppointmentData> Appointments => appointments ??= getAppointments();
|
||||
/// <summary>
|
||||
/// HTML attributes to apply to the slot element.
|
||||
/// </summary>
|
||||
@@ -25,5 +32,6 @@ namespace Radzen
|
||||
/// The current view.
|
||||
/// </summary>
|
||||
public ISchedulerView View { get; set;}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenScheduler @ref=@scheduler SlotRender=@OnSlotRender style="height: 768px;" TItem="Appointment" Data=@appointments StartProperty="Start" EndProperty="End"
|
||||
TextProperty="Text" SelectedIndex="1"
|
||||
SlotSelect=@OnSlotSelect AppointmentSelect=@OnAppointmentSelect AppointmentRender=@OnAppointmentRender MonthSelect=@OnMonthSelect>
|
||||
TextProperty="Text" SelectedIndex="1"
|
||||
SlotSelect=@OnSlotSelect AppointmentSelect=@OnAppointmentSelect AppointmentRender=@OnAppointmentRender MonthSelect=@OnMonthSelect>
|
||||
<RadzenMonthView />
|
||||
<RadzenYearPlannerView StartMonth="@startMonth" />
|
||||
<RadzenYearTimelineView StartMonth="@startMonth" />
|
||||
@@ -30,7 +30,33 @@
|
||||
new Appointment { Start = DateTime.Today.AddHours(10), End = DateTime.Today.AddHours(12), Text = "Online meeting" },
|
||||
new Appointment { Start = DateTime.Today.AddHours(10), End = DateTime.Today.AddHours(13), Text = "Skype call" },
|
||||
new Appointment { Start = DateTime.Today.AddHours(14), End = DateTime.Today.AddHours(14).AddMinutes(30), Text = "Dentist appointment" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(1), End = DateTime.Today.AddDays(12), Text = "Vacation" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(1), End = DateTime.Today.AddDays(7), Text = "Vacation" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(21).AddHours(10), End = DateTime.Today.AddDays(21).AddHours(11), Text = "Client #1" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(21).AddHours(11), End = DateTime.Today.AddDays(21).AddHours(12), Text = "Client #2" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(21).AddHours(12), End = DateTime.Today.AddDays(21).AddHours(13), Text = "Client #3" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(21).AddHours(13), End = DateTime.Today.AddDays(21).AddHours(14), Text = "Client #4" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(17).AddHours(10), End = DateTime.Today.AddDays(17).AddHours(11), Text = "Client #1" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(17).AddHours(11), End = DateTime.Today.AddDays(17).AddHours(12), Text = "Client #2" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(18).AddHours(10), End = DateTime.Today.AddDays(18).AddHours(11), Text = "Client #1" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(18).AddHours(11), End = DateTime.Today.AddDays(18).AddHours(12), Text = "Client #2" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(18).AddHours(12), End = DateTime.Today.AddDays(18).AddHours(13), Text = "Client #3" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(18).AddHours(13), End = DateTime.Today.AddDays(18).AddHours(14), Text = "Client #4" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(18).AddHours(14), End = DateTime.Today.AddDays(23).AddHours(15), Text = "Client #5" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(6).AddHours(10), End = DateTime.Today.AddDays(6).AddHours(11), Text = "Client #1" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(6).AddHours(11), End = DateTime.Today.AddDays(6).AddHours(12), Text = "Client #2" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(6).AddHours(12), End = DateTime.Today.AddDays(6).AddHours(13), Text = "Client #3" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(6).AddHours(13), End = DateTime.Today.AddDays(6).AddHours(14), Text = "Client #4" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(7).AddHours(10), End = DateTime.Today.AddDays(7).AddHours(11), Text = "Client #1" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(7).AddHours(11), End = DateTime.Today.AddDays(7).AddHours(12), Text = "Client #2" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(8).AddHours(10), End = DateTime.Today.AddDays(8).AddHours(11), Text = "Client #1" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(8).AddHours(11), End = DateTime.Today.AddDays(8).AddHours(12), Text = "Client #2" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(9).AddHours(10), End = DateTime.Today.AddDays(9).AddHours(11), Text = "Client #1" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(9).AddHours(11), End = DateTime.Today.AddDays(9).AddHours(12), Text = "Client #2" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(13).AddHours(10), End = DateTime.Today.AddDays(16).AddHours(11), Text = "Client #1" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(13).AddHours(11), End = DateTime.Today.AddDays(16).AddHours(12), Text = "Client #2" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(13).AddHours(12), End = DateTime.Today.AddDays(13).AddHours(13), Text = "Client #3" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(13).AddHours(13), End = DateTime.Today.AddDays(16).AddHours(14), Text = "Client #4" },
|
||||
new Appointment { Start = DateTime.Today.AddDays(13).AddHours(14), End = DateTime.Today.AddDays(16).AddHours(15), Text = "Client #5" },
|
||||
};
|
||||
|
||||
void OnSlotRender(SchedulerSlotRenderEventArgs args)
|
||||
@@ -46,6 +72,20 @@
|
||||
{
|
||||
args.Attributes["style"] = "border-bottom: thick double var(--rz-base-600);";
|
||||
}
|
||||
|
||||
// Color the slot depending on number of appointments for that day
|
||||
if (args.Appointments.Count() > 4)
|
||||
{
|
||||
args.Attributes["style"] = "background: #ffabab;";
|
||||
}
|
||||
else if (args.Appointments.Count() > 2)
|
||||
{
|
||||
args.Attributes["style"] = "background: #ffc988;";
|
||||
}
|
||||
else if (args.Appointments.Count() > 0)
|
||||
{
|
||||
args.Attributes["style"] = "background: #c3ffc3;";
|
||||
}
|
||||
}
|
||||
|
||||
async Task OnSlotSelect(SchedulerSlotSelectEventArgs args)
|
||||
|
||||
Reference in New Issue
Block a user