mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-07-08 18:16:08 +00:00
Read all parameters from ParameterView before calling Scheduler.Reload() to prevent reading an expired ParameterView after an async yield. This also fixes LoadData receiving stale date ranges based on the old StartMonth value.
109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
using System;
|
|
using Radzen;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Radzen.Blazor
|
|
{
|
|
/// <summary>
|
|
/// A base class for <see cref="RadzenScheduler{TItem}" /> views.
|
|
/// </summary>
|
|
public abstract class SchedulerViewBase : ComponentBase, ISchedulerView, IDisposable
|
|
{
|
|
/// <summary>
|
|
/// Gets the title of the view. It is displayed in the RadzenScheduler title area.
|
|
/// </summary>
|
|
/// <value>The title.</value>
|
|
public abstract string Title { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the icon of the view. It is displayed in the view switching UI.
|
|
/// </summary>
|
|
public abstract string Icon { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the text of the view. It is displayed in the view switching UI.
|
|
/// </summary>
|
|
/// <value>The text.</value>
|
|
public abstract string Text { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the scheduler instance.
|
|
/// </summary>
|
|
/// <value>The scheduler.</value>
|
|
[CascadingParameter]
|
|
public IScheduler? Scheduler { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// Disposes this instance.
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
Scheduler?.RemoveView(this);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called by the Blazor runtime when parameters are set.
|
|
/// </summary>
|
|
/// <param name="parameters">The parameters.</param>
|
|
public override async Task SetParametersAsync(ParameterView parameters)
|
|
{
|
|
var textChanged = parameters.DidParameterChange(nameof(Text), Text);
|
|
|
|
await base.SetParametersAsync(parameters);
|
|
|
|
if (textChanged && Scheduler != null)
|
|
{
|
|
await Scheduler.Reload();
|
|
}
|
|
|
|
if (Scheduler != null)
|
|
{
|
|
await Scheduler.AddView(this);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a new date when the user clicks the next button of RadzenScheduler.
|
|
/// </summary>
|
|
/// <returns>The next date. For example a day view will return the next day, a week view will return the next week.</returns>
|
|
public abstract DateTime Next();
|
|
|
|
/// <summary>
|
|
/// Returns a new date when the user clicks the previous button of RadzenScheduler.
|
|
/// </summary>
|
|
/// <returns>The previous date. For example a day view will return the previous day, a week view will return the previous week.</returns>
|
|
public abstract DateTime Prev();
|
|
|
|
/// <summary>
|
|
/// Renders this instance.
|
|
/// </summary>
|
|
public abstract RenderFragment Render();
|
|
|
|
/// <summary>
|
|
/// Gets the start date.
|
|
/// </summary>
|
|
/// <value>The start date.</value>
|
|
public abstract DateTime StartDate { get; }
|
|
/// <summary>
|
|
/// Gets the end date.
|
|
/// </summary>
|
|
/// <value>The end date.</value>
|
|
public abstract DateTime EndDate { get; }
|
|
|
|
/// <summary>
|
|
/// Handles appointent move event.
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public async Task OnAppointmentMove(SchedulerAppointmentMoveEventArgs data)
|
|
{
|
|
if (Scheduler != null)
|
|
{
|
|
await Scheduler.AppointmentMove.InvokeAsync(data);
|
|
}
|
|
}
|
|
}
|
|
} |