DatePicker - changes on variable acces level (public -> private), variable names, Added methods for range select (only framework, nothing works yet)

pull/12/head^2
markosteger 2 years ago
parent 2972f931e1
commit 515172ffb6

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

Loading…
Cancel
Save