From 1bb1c0af5818f0d0c6107166fdddd9daea917361 Mon Sep 17 00:00:00 2001 From: markosteger Date: Mon, 6 Mar 2023 15:18:09 +0100 Subject: [PATCH] DatePicker - Index update binding beacuse of the name changes --- .../Pages/Index.razor | 2 +- .../Components/DatePicker/DatePicker.razor | 79 --------- .../Components/DatePicker/DatePicker.razor.cs | 162 ------------------ 3 files changed, 1 insertion(+), 242 deletions(-) delete mode 100644 src/Connected.Components/Components/DatePicker/DatePicker.razor delete mode 100644 src/Connected.Components/Components/DatePicker/DatePicker.razor.cs diff --git a/src/Connected.Components.Showcase.Runner/Pages/Index.razor b/src/Connected.Components.Showcase.Runner/Pages/Index.razor index 5d62b8a..0e1ec6b 100644 --- a/src/Connected.Components.Showcase.Runner/Pages/Index.razor +++ b/src/Connected.Components.Showcase.Runner/Pages/Index.razor @@ -5,7 +5,7 @@ +@bind-SelectedDate=@date> diff --git a/src/Connected.Components/Components/DatePicker/DatePicker.razor b/src/Connected.Components/Components/DatePicker/DatePicker.razor deleted file mode 100644 index 9f6bb34..0000000 --- a/src/Connected.Components/Components/DatePicker/DatePicker.razor +++ /dev/null @@ -1,79 +0,0 @@ -@using System.Globalization; -@if (loaded) -{ - - @if (Shown) - { -
-
-
- @SelectedDate.Year.ToString() -
-
- @SelectedDate.ToString("ddd, " + Format) -
-
-
- @switch (Selecting) - { - case Selecting.Years: - { -
-
-
Selecting = Selecting.Days)>@SelectedDate.ToString("yyyy")
-
-
- break; - } - case Selecting.Months: - { -
-
-
Selecting = Selecting.Years)>@SelectedDate.ToString("yyyy")
-
-
- @for (int i = 1; i <= @DateTimeFormatInfo.CurrentInfo.MonthNames.Length - 1; i++) - { - int m = i; - - -
-
-
@DateTimeFormatInfo.CurrentInfo.GetMonthName(i).Substring(0,3)
-
-
- -
- if (i%3==0) {
} - } - break; - } - case (Selecting.Days): - { -
-
-
Selecting = Selecting.Months)>@SelectedDate.ToString("MMMM")
-
-
- - @for (int i = 0; i < 7; i++) - { -
@calendarStart.AddDays(i).ToString("ddd").Substring(0,1).ToUpper()
- } - @foreach (var Date in Dates) - { -
@Date.Day.ToString()
- @if (calendarStart.DayOfWeek.Equals(DayOfWeek.Sunday)) - { -
- } - - calendarStart = calendarStart.AddDays(1); - } - break; - } - } -
-
- } -} diff --git a/src/Connected.Components/Components/DatePicker/DatePicker.razor.cs b/src/Connected.Components/Components/DatePicker/DatePicker.razor.cs deleted file mode 100644 index b0b7f7e..0000000 --- a/src/Connected.Components/Components/DatePicker/DatePicker.razor.cs +++ /dev/null @@ -1,162 +0,0 @@ -using Connected.Utilities; -using Microsoft.AspNetCore.Components; - -namespace Connected.Components.DatePicker; -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 Today = DateTime.Today; - - private DateTime SelectedDate = DateTime.Today; - - private List Dates = new List(); - - [Parameter] - public string Format { get; set; } = "dd.MM.yyyy"; - - private bool _readonly = false; - [Parameter] - public bool Editable - { - get - { - return !_readonly; - } - set - { - _readonly = !value; - } - } - - [Parameter] - public bool Shown { get; set; } = false; - - public void SetMonthNavigation() - { - - } - - public void SetDate(DateTime Date) - { - SelectedDate = Date; - SetStartStop(); - StateHasChanged(); - } - - public void SetMonth(int month) - { - SelectedDate = new DateTime(SelectedDate.Year, month, SelectedDate.Day); - SetStartStop(); - StateHasChanged(); - } - - private string ChipFirstRowClass - { - get - { - return new CssBuilder() - .AddClass("chip-leading-icon d-inline-block p-1 bg-danger text-small text-light") - .Build(); - } - } - private string ChipFirstRowStyle - { - get - { - return new StyleBuilder() - .AddStyle("width", "30px") - .AddStyle("height", "30px") - .AddStyle("text-align", "center") - .Build(); - } - } - /* - @for (int i=0;i<7; i++) - { -
@calendarStart.AddDays(i).ToString("ddd").Substring(0,1)
- } - @while (calendarStart.CompareTo(calendarEnd) < 0) - { -
@calendarStart.Day.ToString()
- @if (calendarStart.DayOfWeek.Equals(DayOfWeek.Sunday)) - { -
- } - calendarStart = calendarStart.AddDays(1); - } - - */ - - public void SetStartStop() - { - calendarStart = SelectedDate; - while (calendarStart.Day != 1) - { - calendarStart = calendarStart.AddDays(-1); - } - while (!calendarStart.DayOfWeek.Equals(DayOfWeek.Monday)) - { - calendarStart = calendarStart.AddDays(-1); - } - calendarEnd = SelectedDate; - while (calendarEnd.Month == SelectedDate.Month) - { - calendarEnd = calendarEnd.AddDays(1); - } - while (!calendarEnd.DayOfWeek.Equals(DayOfWeek.Monday)) - { - calendarEnd = calendarEnd.AddDays(1); - } - DateTime start = calendarStart; - if (Dates is null) Dates = new(); - Dates.Clear(); - while (start.CompareTo(calendarEnd) < 0) - { - Dates.Add(start); - start = start.AddDays(1); - } - } - - public string DateChipStyle(DateTime date) - { - string result = ""; - if (date.Month.CompareTo(SelectedDate.Month) < 0 || date.Month.CompareTo(SelectedDate.Month) > 0) return "bg-core text-light"; - if (date.Month.CompareTo(SelectedDate.Month) == 0) - { - if (date.Date.CompareTo(SelectedDate.Date) == 0) - return "bg-info text-light"; - else - return "bg-core text-dark"; - } - return result; - } - - public string MonthChipClass(int month) - { - if (month.CompareTo(SelectedDate.Month) == 0) - return "bg-info text-light"; - else - return "bg-core text-dark"; - } - - protected override async Task OnInitializedAsync() - { - SelectedDate = DateTime.Today; - SetStartStop(); - loaded = true; - await base.OnInitializedAsync(); - } - -} - -public enum Selecting -{ - Days, - Months, - Years -}