ant-design-blazor/components/date-picker/internal/DatePickerDatetimePanel.razor

169 lines
6.7 KiB
C#
Raw Normal View History

@namespace AntDesign.Internal
@typeparam TValue
@inherits DatePickerPanelBase<TValue>
@{
feat(module: date-picker): support localization (#803) * start trying to add a different first day of the week based on localization. * add first day of week parameter and get weekday local from .net * fix some issues * extend demo * remove no longed needed Locale parameter * fix range for selection * add german localization * add entry for API section * remove obsolet things from the react ant documentation * add description to chart documentation * translate general configuration to english. * code cleanup * use LocalProvider to get first day of week. * use localeprovider instead of date picker localization * remove no longer used parameter * delete no longer used interface * change from enum to string due to parsing issue. * add missing formats and use culture info from localprovider * correct locales * us Sunday as a default * remove no longer used culture info parameter * adjust locales * add parameter for Locale instead of directly accessing it. * add inheritance to access locale * typo * readd culture info parameter * fixes for locale jsons * adjust demo and api * small adjustments on docs, set monday in chinese as first day of the week. * use locale in calendar as well. * adjust docs * use enum * adjust demo * adjust for different starting date. * add defaults for DatePickerLocale * add short week days to locale files * use days from locale file * code cleanup use consts instead of magic numbers, add code comment and use dayOfWeek As param instead of the whole locale object. Remove no longed used method. * not sure about the chinese translation so I remove them * Revert "not sure about the chinese translation so I remove them" This reverts commit 54017513c7b684494cf06184b4051a4dcfc43850.
2020-11-25 11:08:12 +08:00
var calendar = CultureInfo.Calendar;
DateTime monthFirstDayDate = new DateTime(PickerValue.Year, PickerValue.Month, 1, 0, 0, 0);
int monthFirstDayOfWeek = (int)calendar.GetDayOfWeek(monthFirstDayDate);
// sunday should be 7
if (monthFirstDayOfWeek == 0)
{
monthFirstDayOfWeek = DayOfWeekHelper.GetDiffForDayOfWeek(Locale.FirstDayOfWeek);
Console.WriteLine($"{DateTime.Now} DatePickerDatePanel.razor monthFirstDayOfWeek: {monthFirstDayOfWeek}");
}
int diffDay = (int)Locale.FirstDayOfWeek - monthFirstDayOfWeek;
DateTime startDate = monthFirstDayDate.AddDays(diffDay);
}
feat(module: overlay): OverlayTrigger not bound to a div (#937) * feat(module:overlay): OverlayTrigger not bound to a div * feat(module:overlay): OverlayTrigger not bound to a div * feat(module:overlay): Logic transfer to single Overlay * feat(module:overlay): remove obsolete duplication * feat(module:Tooltip): Add for unbounded oncontextmenu event handler * feat(module:tooltip): unbound js event listeners remove * docs(module:tooltip): unbound explanation * fix(module:button): attach Ref to top level html element @ref * feat(module:dropdown&tooltip&popconfirm&popover): Overlay not bound to a div * docs(module:dropdown&tooltip&popconfirm&popover): unbound explanation * feat(module:OverlayTrigger): common logic relocation * feat(module:overlaytrigger): Overlay not bound to a div * feat(module:DatePicker): Overlay not bound to a div * feat(module:select): Overlay not boud to div * fix(module:select): onclickarrow event relocation * fix(module:select): rename Show to OnArrowClick * feat(module:avatar): Overlay not bound to a div * docs(module:avatar): demo switch to unbound version * feat(module:autocomplete): partial OverlayTrigger not bound to a div * feat(module:slider): tooltip * docs(module:slider): tooltip * fix(module:overlay): add SetVisible method * feat: set Ref where missing, performance components register Ref when missing IsFixed flag for CascadeValue changed hard-code sequence numbers when using RenderTreeBuilder Rate component use Tooltip Unbound version Tabs test fix * fix: revert changes (accidental) * feat(module:upload): tooltip with unbound usage * feat(module:table): column use of unbound tooltip * feat(module:autocomplete):overlay unbound from div * fix(module:upload): missing div restore Co-authored-by: James Yeung <shunjiey@hotmail.com>
2021-01-21 17:20:10 +08:00
<div class='@($"{PrefixCls}-datetime-panel")' @ref="Ref">
@if (IsShowTime)
{
feat(module: date-picker): support localization (#803) * start trying to add a different first day of the week based on localization. * add first day of week parameter and get weekday local from .net * fix some issues * extend demo * remove no longed needed Locale parameter * fix range for selection * add german localization * add entry for API section * remove obsolet things from the react ant documentation * add description to chart documentation * translate general configuration to english. * code cleanup * use LocalProvider to get first day of week. * use localeprovider instead of date picker localization * remove no longer used parameter * delete no longer used interface * change from enum to string due to parsing issue. * add missing formats and use culture info from localprovider * correct locales * us Sunday as a default * remove no longer used culture info parameter * adjust locales * add parameter for Locale instead of directly accessing it. * add inheritance to access locale * typo * readd culture info parameter * fixes for locale jsons * adjust demo and api * small adjustments on docs, set monday in chinese as first day of the week. * use locale in calendar as well. * adjust docs * use enum * adjust demo * adjust for different starting date. * add defaults for DatePickerLocale * add short week days to locale files * use days from locale file * code cleanup use consts instead of magic numbers, add code comment and use dayOfWeek As param instead of the whole locale object. Remove no longed used method. * not sure about the chinese translation so I remove them * Revert "not sure about the chinese translation so I remove them" This reverts commit 54017513c7b684494cf06184b4051a4dcfc43850.
2020-11-25 11:08:12 +08:00
<DatePickerTemplate TValue="TValue"
@attributes="GetAttritubes()"
MaxRow="6"
MaxCol="7"
ViewStartDate="startDate"
ShowFooter="@ShowToday"
IsInView="date => DateHelper.IsSameMonth(date, PickerValue)"
IsToday="date => DateHelper.IsSameDay(date, DatePicker.CurrentDate)"
IsSelected="date => DateHelper.IsSameDay(date, Value)"
feat(module: date-picker): support localization (#803) * start trying to add a different first day of the week based on localization. * add first day of week parameter and get weekday local from .net * fix some issues * extend demo * remove no longed needed Locale parameter * fix range for selection * add german localization * add entry for API section * remove obsolet things from the react ant documentation * add description to chart documentation * translate general configuration to english. * code cleanup * use LocalProvider to get first day of week. * use localeprovider instead of date picker localization * remove no longer used parameter * delete no longer used interface * change from enum to string due to parsing issue. * add missing formats and use culture info from localprovider * correct locales * us Sunday as a default * remove no longer used culture info parameter * adjust locales * add parameter for Locale instead of directly accessing it. * add inheritance to access locale * typo * readd culture info parameter * fixes for locale jsons * adjust demo and api * small adjustments on docs, set monday in chinese as first day of the week. * use locale in calendar as well. * adjust docs * use enum * adjust demo * adjust for different starting date. * add defaults for DatePickerLocale * add short week days to locale files * use days from locale file * code cleanup use consts instead of magic numbers, add code comment and use dayOfWeek As param instead of the whole locale object. Remove no longed used method. * not sure about the chinese translation so I remove them * Revert "not sure about the chinese translation so I remove them" This reverts commit 54017513c7b684494cf06184b4051a4dcfc43850.
2020-11-25 11:08:12 +08:00
GetColTitle='date => date.ToString(Locale.Lang.DateFormat, CultureInfo)'
OnValueSelect="OnSelectDate"
GetNextColValue="date => DateHelper.AddDaysSafely(date, 1)">
<RenderPickerHeader>
<DatePickerHeader TValue="TValue"
@attributes="GetAttritubes()" />
</RenderPickerHeader>
<RenderTableHeader>
<tr>
feat(module: date-picker): support localization (#803) * start trying to add a different first day of the week based on localization. * add first day of week parameter and get weekday local from .net * fix some issues * extend demo * remove no longed needed Locale parameter * fix range for selection * add german localization * add entry for API section * remove obsolet things from the react ant documentation * add description to chart documentation * translate general configuration to english. * code cleanup * use LocalProvider to get first day of week. * use localeprovider instead of date picker localization * remove no longer used parameter * delete no longer used interface * change from enum to string due to parsing issue. * add missing formats and use culture info from localprovider * correct locales * us Sunday as a default * remove no longer used culture info parameter * adjust locales * add parameter for Locale instead of directly accessing it. * add inheritance to access locale * typo * readd culture info parameter * fixes for locale jsons * adjust demo and api * small adjustments on docs, set monday in chinese as first day of the week. * use locale in calendar as well. * adjust docs * use enum * adjust demo * adjust for different starting date. * add defaults for DatePickerLocale * add short week days to locale files * use days from locale file * code cleanup use consts instead of magic numbers, add code comment and use dayOfWeek As param instead of the whole locale object. Remove no longed used method. * not sure about the chinese translation so I remove them * Revert "not sure about the chinese translation so I remove them" This reverts commit 54017513c7b684494cf06184b4051a4dcfc43850.
2020-11-25 11:08:12 +08:00
@foreach(string weekDay in Locale.Lang.ShortWeekDays)
{
<th>@weekDay</th>
}
</tr>
</RenderTableHeader>
<RenderColValue Context="currentColDate">
@currentColDate.Day
</RenderColValue>
</DatePickerTemplate>
}
@{
var startTime = new DateTime(2020, 1, 1, 0, 0, 0);
var timeFormat = ShowTimeFormat;
if (Picker == DatePickerType.Time && !string.IsNullOrEmpty(Format))
{
timeFormat = Format;
}
DatePickerDisabledTime disabledTime = GetDisabledTime();
}
<div class="@(PrefixCls)-time-panel">
@if(Picker == DatePickerType.Date)
{
<div class="@(PrefixCls)-header">
<div class="@(PrefixCls)-header-view">
@Value.ToString(timeFormat) <br />
</div>
</div>
}
feat(module: date-picker): support localization (#803) * start trying to add a different first day of the week based on localization. * add first day of week parameter and get weekday local from .net * fix some issues * extend demo * remove no longed needed Locale parameter * fix range for selection * add german localization * add entry for API section * remove obsolet things from the react ant documentation * add description to chart documentation * translate general configuration to english. * code cleanup * use LocalProvider to get first day of week. * use localeprovider instead of date picker localization * remove no longer used parameter * delete no longer used interface * change from enum to string due to parsing issue. * add missing formats and use culture info from localprovider * correct locales * us Sunday as a default * remove no longer used culture info parameter * adjust locales * add parameter for Locale instead of directly accessing it. * add inheritance to access locale * typo * readd culture info parameter * fixes for locale jsons * adjust demo and api * small adjustments on docs, set monday in chinese as first day of the week. * use locale in calendar as well. * adjust docs * use enum * adjust demo * adjust for different starting date. * add defaults for DatePickerLocale * add short week days to locale files * use days from locale file * code cleanup use consts instead of magic numbers, add code comment and use dayOfWeek As param instead of the whole locale object. Remove no longed used method. * not sure about the chinese translation so I remove them * Revert "not sure about the chinese translation so I remove them" This reverts commit 54017513c7b684494cf06184b4051a4dcfc43850.
2020-11-25 11:08:12 +08:00
<div class="@(PrefixCls)-content">
@if (timeFormat.ToLower().Contains("hh"))
{
<ul class="@(PrefixCls)-time-panel-column" style="position: relative;">
@for (int hour = 0; hour < 24; hour++)
{
var viewTime = startTime;
bool disabled = disabledTime._disabledHours.Contains(hour);
string isSelectedCls = viewTime.Hour == Value.Hour ? $"{PrefixCls}-time-panel-cell-selected" : "";
string disabledCls = disabled ? $"{PrefixCls}-time-panel-cell-disabled" : "";
<li class="@(PrefixCls)-time-panel-cell @isSelectedCls @disabledCls">
<div class="@(PrefixCls)-time-panel-cell-inner"
@onclick="e => { if (!disabled) OnSelectHour(viewTime); }">
@hour
</div>
</li>
startTime = startTime.AddHours(1);
}
</ul>
}
@if (timeFormat.ToLower().Contains("mm"))
{
<ul class="@(PrefixCls)-time-panel-column" style="position: relative;">
@for (int minute = 0; minute < 60; minute++)
{
var viewTime = startTime;
bool disabled = disabledTime._disabledMinutes.Contains(minute);
string isSelectedCls = viewTime.Minute == Value.Minute ? $"{PrefixCls}-time-panel-cell-selected" : "";
string disabledCls = disabled ? $"{PrefixCls}-time-panel-cell-disabled" : "";
<li class="@(PrefixCls)-time-panel-cell @isSelectedCls @disabledCls">
<div class="@(PrefixCls)-time-panel-cell-inner"
@onclick="e => { if (!disabled) OnSelectMinute(viewTime); }">
@minute
</div>
</li>
startTime = startTime.AddMinutes(1);
}
</ul>
}
@if (timeFormat.ToLower().Contains("ss"))
{
<ul class="@(PrefixCls)-time-panel-column" style="position: relative;">
@for (int second = 0; second < 60; second++)
{
var viewTime = startTime;
bool disabled = disabledTime._disabledSeconds.Contains(second);
string isSelectedCls = viewTime.Second == Value.Second ? $"{PrefixCls}-time-panel-cell-selected" : "";
string disabledCls = disabled ? $"{PrefixCls}-time-panel-cell-disabled" : "";
<li class="@(PrefixCls)-time-panel-cell @isSelectedCls @disabledCls">
<div class="@(PrefixCls)-time-panel-cell-inner"
@onclick="e => { if (!disabled) OnSelectSecond(viewTime); }">
@second
</div>
</li>
startTime = startTime.AddSeconds(1);
}
</ul>
}
</div>
</div>
</div>
@if (RenderExtraFooter != null)
{
<div class="@(PrefixCls)-footer">
<div class="@(PrefixCls)-footer-extra">
@RenderExtraFooter
</div>
</div>
}
<div class="@(PrefixCls)-footer">
<ul class="@(PrefixCls)-ranges">
<li class="@(PrefixCls)-now">
<a class="@(PrefixCls)-now-btn"
@onclick="e => { OnSelectTime(DateTime.Now); Close(); }">
feat(module: date-picker): support localization (#803) * start trying to add a different first day of the week based on localization. * add first day of week parameter and get weekday local from .net * fix some issues * extend demo * remove no longed needed Locale parameter * fix range for selection * add german localization * add entry for API section * remove obsolet things from the react ant documentation * add description to chart documentation * translate general configuration to english. * code cleanup * use LocalProvider to get first day of week. * use localeprovider instead of date picker localization * remove no longer used parameter * delete no longer used interface * change from enum to string due to parsing issue. * add missing formats and use culture info from localprovider * correct locales * us Sunday as a default * remove no longer used culture info parameter * adjust locales * add parameter for Locale instead of directly accessing it. * add inheritance to access locale * typo * readd culture info parameter * fixes for locale jsons * adjust demo and api * small adjustments on docs, set monday in chinese as first day of the week. * use locale in calendar as well. * adjust docs * use enum * adjust demo * adjust for different starting date. * add defaults for DatePickerLocale * add short week days to locale files * use days from locale file * code cleanup use consts instead of magic numbers, add code comment and use dayOfWeek As param instead of the whole locale object. Remove no longed used method. * not sure about the chinese translation so I remove them * Revert "not sure about the chinese translation so I remove them" This reverts commit 54017513c7b684494cf06184b4051a4dcfc43850.
2020-11-25 11:08:12 +08:00
@Locale.Lang.Now
</a>
</li>
<li class="@(PrefixCls)-ok">
<Button Type="@ButtonType.Primary"
OnClick="e => DatePicker.Close()">
feat(module: date-picker): support localization (#803) * start trying to add a different first day of the week based on localization. * add first day of week parameter and get weekday local from .net * fix some issues * extend demo * remove no longed needed Locale parameter * fix range for selection * add german localization * add entry for API section * remove obsolet things from the react ant documentation * add description to chart documentation * translate general configuration to english. * code cleanup * use LocalProvider to get first day of week. * use localeprovider instead of date picker localization * remove no longer used parameter * delete no longer used interface * change from enum to string due to parsing issue. * add missing formats and use culture info from localprovider * correct locales * us Sunday as a default * remove no longer used culture info parameter * adjust locales * add parameter for Locale instead of directly accessing it. * add inheritance to access locale * typo * readd culture info parameter * fixes for locale jsons * adjust demo and api * small adjustments on docs, set monday in chinese as first day of the week. * use locale in calendar as well. * adjust docs * use enum * adjust demo * adjust for different starting date. * add defaults for DatePickerLocale * add short week days to locale files * use days from locale file * code cleanup use consts instead of magic numbers, add code comment and use dayOfWeek As param instead of the whole locale object. Remove no longed used method. * not sure about the chinese translation so I remove them * Revert "not sure about the chinese translation so I remove them" This reverts commit 54017513c7b684494cf06184b4051a4dcfc43850.
2020-11-25 11:08:12 +08:00
@Locale.Lang.Ok
</Button>
</li>
</ul>
</div>