|
|
|
@ -7,8 +7,8 @@ public partial class DatePicker
|
|
|
|
|
private bool loaded = false;
|
|
|
|
|
|
|
|
|
|
private Selecting Selecting = Selecting.Days;
|
|
|
|
|
public DateTime calendarStart { get; set; }
|
|
|
|
|
public DateTime calendarEnd { get; set; }
|
|
|
|
|
private DateTime CalendarStart { get; set; } = DateTime.Today;
|
|
|
|
|
private DateTime CalendarEnd { get; set; } = DateTime.Today;
|
|
|
|
|
|
|
|
|
|
//private DateTime Today = DateTime.Today;
|
|
|
|
|
|
|
|
|
@ -16,12 +16,21 @@ public partial class DatePicker
|
|
|
|
|
public bool CloseOnDateSelect { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public DateTime Date { get; set; } = DateTime.Today;
|
|
|
|
|
public DateTime SelectedDate { get; set; } = DateTime.Today;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<DateTime> DateChanged { get; set; }
|
|
|
|
|
public DateTime? SelectedEndDate { get; set; } = null;
|
|
|
|
|
|
|
|
|
|
private List<DateTime> Dates = new List<DateTime>();
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<DateTime> SelectedDateChanged { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<DateTime?> SelectedEndDateChanged { get; set; }
|
|
|
|
|
|
|
|
|
|
private List<DateTime> ShowingDates = new List<DateTime>();
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool UseDateRange { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Format { get; set; } = "dd.MM.yyyy";
|
|
|
|
@ -43,29 +52,29 @@ public partial class DatePicker
|
|
|
|
|
|
|
|
|
|
public async Task SetDate(DateTime Date)
|
|
|
|
|
{
|
|
|
|
|
this.Date = Date;
|
|
|
|
|
SelectedDate = Date;
|
|
|
|
|
SetStartStop();
|
|
|
|
|
if (CloseOnDateSelect)
|
|
|
|
|
Shown = false;
|
|
|
|
|
await DateChanged.InvokeAsync(this.Date);
|
|
|
|
|
await SelectedDateChanged.InvokeAsync(SelectedDate);
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SetMonth(int month)
|
|
|
|
|
{
|
|
|
|
|
Date = new DateTime(Date.Year, month, Date.Day);
|
|
|
|
|
SelectedDate = new DateTime(SelectedDate.Year, month, SelectedDate.Day);
|
|
|
|
|
Selecting = Selecting.Days;
|
|
|
|
|
SetStartStop();
|
|
|
|
|
await DateChanged.InvokeAsync(this.Date);
|
|
|
|
|
await SelectedDateChanged.InvokeAsync(SelectedDate);
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SetYear(int year)
|
|
|
|
|
{
|
|
|
|
|
Date = new DateTime(year, Date.Month, Date.Day);
|
|
|
|
|
SelectedDate = new DateTime(year, SelectedDate.Month, SelectedDate.Day);
|
|
|
|
|
Selecting = Selecting.Months;
|
|
|
|
|
SetStartStop();
|
|
|
|
|
await DateChanged.InvokeAsync(this.Date);
|
|
|
|
|
await SelectedDateChanged.InvokeAsync(SelectedDate);
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -113,30 +122,30 @@ public partial class DatePicker
|
|
|
|
|
|
|
|
|
|
public void SetStartStop()
|
|
|
|
|
{
|
|
|
|
|
calendarStart = Date;
|
|
|
|
|
while (calendarStart.Day != 1)
|
|
|
|
|
CalendarStart = SelectedDate;
|
|
|
|
|
while (CalendarStart.Day != 1)
|
|
|
|
|
{
|
|
|
|
|
calendarStart = calendarStart.AddDays(-1);
|
|
|
|
|
CalendarStart = CalendarStart.AddDays(-1);
|
|
|
|
|
}
|
|
|
|
|
while (!calendarStart.DayOfWeek.Equals(DayOfWeek.Monday))
|
|
|
|
|
while (!CalendarStart.DayOfWeek.Equals(DayOfWeek.Monday))
|
|
|
|
|
{
|
|
|
|
|
calendarStart = calendarStart.AddDays(-1);
|
|
|
|
|
CalendarStart = CalendarStart.AddDays(-1);
|
|
|
|
|
}
|
|
|
|
|
calendarEnd = Date;
|
|
|
|
|
while (calendarEnd.Month == Date.Month)
|
|
|
|
|
CalendarEnd = SelectedDate;
|
|
|
|
|
while (CalendarEnd.Month == SelectedDate.Month)
|
|
|
|
|
{
|
|
|
|
|
calendarEnd = calendarEnd.AddDays(1);
|
|
|
|
|
CalendarEnd = CalendarEnd.AddDays(1);
|
|
|
|
|
}
|
|
|
|
|
while (!calendarEnd.DayOfWeek.Equals(DayOfWeek.Monday))
|
|
|
|
|
while (!CalendarEnd.DayOfWeek.Equals(DayOfWeek.Monday))
|
|
|
|
|
{
|
|
|
|
|
calendarEnd = calendarEnd.AddDays(1);
|
|
|
|
|
CalendarEnd = CalendarEnd.AddDays(1);
|
|
|
|
|
}
|
|
|
|
|
DateTime start = calendarStart;
|
|
|
|
|
if (Dates is null) Dates = new();
|
|
|
|
|
Dates.Clear();
|
|
|
|
|
while (start.CompareTo(calendarEnd) < 0)
|
|
|
|
|
DateTime start = CalendarStart;
|
|
|
|
|
if (ShowingDates is null) ShowingDates = new();
|
|
|
|
|
ShowingDates.Clear();
|
|
|
|
|
while (start.CompareTo(CalendarEnd) < 0)
|
|
|
|
|
{
|
|
|
|
|
Dates.Add(start);
|
|
|
|
|
ShowingDates.Add(start);
|
|
|
|
|
start = start.AddDays(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -144,11 +153,11 @@ public partial class DatePicker
|
|
|
|
|
public string DateChipStyle(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
string result = "";
|
|
|
|
|
if (date.Month.CompareTo(Date.Month) < 0 || date.Month.CompareTo(Date.Month) > 0) return "bg-core text-light";
|
|
|
|
|
if (date.Month.CompareTo(SelectedDate.Month) < 0 || date.Month.CompareTo(SelectedDate.Month) > 0) return "bg-core text-light";
|
|
|
|
|
if (date.CompareTo(DateTime.Today) == 0) result = "b-1 b-c-info";
|
|
|
|
|
if (date.Month.CompareTo(Date.Month) == 0)
|
|
|
|
|
if (date.Month.CompareTo(SelectedDate.Month) == 0)
|
|
|
|
|
{
|
|
|
|
|
if (date.Date.CompareTo(Date.Date) == 0)
|
|
|
|
|
if (date.Date.CompareTo(SelectedDate.Date) == 0)
|
|
|
|
|
return result+" bg-info text-light";
|
|
|
|
|
else
|
|
|
|
|
return result+" bg-core text-dark";
|
|
|
|
@ -158,7 +167,7 @@ public partial class DatePicker
|
|
|
|
|
|
|
|
|
|
public string MonthChipClass(int month)
|
|
|
|
|
{
|
|
|
|
|
if (month.CompareTo(Date.Month) == 0)
|
|
|
|
|
if (month.CompareTo(SelectedDate.Month) == 0)
|
|
|
|
|
return "bg-info text-light";
|
|
|
|
|
else
|
|
|
|
|
return "bg-core text-dark";
|
|
|
|
@ -166,7 +175,7 @@ public partial class DatePicker
|
|
|
|
|
|
|
|
|
|
public string YearChipClass(int year)
|
|
|
|
|
{
|
|
|
|
|
if (year.CompareTo(Date.Year) == 0)
|
|
|
|
|
if (year.CompareTo(SelectedDate.Year) == 0)
|
|
|
|
|
return "bg-info text-light";
|
|
|
|
|
else
|
|
|
|
|
return "bg-core text-dark";
|
|
|
|
@ -174,7 +183,7 @@ public partial class DatePicker
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
Date = DateTime.Today;
|
|
|
|
|
SelectedDate = DateTime.Today;
|
|
|
|
|
SetStartStop();
|
|
|
|
|
loaded = true;
|
|
|
|
|
await base.OnInitializedAsync();
|
|
|
|
|