|
|
|
@ -16,63 +16,28 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers |
|
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button; |
|
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions; |
|
|
|
using Volo.Abp.Json; |
|
|
|
using Volo.Abp.Timing; |
|
|
|
|
|
|
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form.DatePicker; |
|
|
|
|
|
|
|
public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelperService<TTagHelper> |
|
|
|
where TTagHelper : AbpDatePickerBaseTagHelper<TTagHelper> |
|
|
|
{ |
|
|
|
protected readonly Dictionary<Type, Func<object, string>> SupportedInputTypes = new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
typeof(string), o => |
|
|
|
{ |
|
|
|
if(o is string s && DateTime.TryParse(s, out var dt)) |
|
|
|
{ |
|
|
|
return dt.ToString("O"); |
|
|
|
} |
|
|
|
|
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
typeof(DateTime), o => |
|
|
|
{ |
|
|
|
if(o is DateTime dt && dt != default) |
|
|
|
{ |
|
|
|
return dt.ToString("O"); |
|
|
|
} |
|
|
|
|
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
}, |
|
|
|
{typeof(DateTime?), o => ((DateTime?) o)?.ToString("O")!}, |
|
|
|
{ |
|
|
|
typeof(DateTimeOffset), o => |
|
|
|
{ |
|
|
|
if(o is DateTimeOffset dto && dto != default) |
|
|
|
{ |
|
|
|
return dto.ToString("O"); |
|
|
|
} |
|
|
|
|
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
}, |
|
|
|
{typeof(DateTimeOffset?), o => ((DateTimeOffset?) o)?.ToString("O")!} |
|
|
|
}; |
|
|
|
protected readonly Dictionary<Type, Func<object, string>> SupportedInputTypes; |
|
|
|
|
|
|
|
protected readonly IJsonSerializer JsonSerializer; |
|
|
|
protected readonly IHtmlGenerator Generator; |
|
|
|
protected readonly HtmlEncoder Encoder; |
|
|
|
protected readonly IServiceProvider ServiceProvider; |
|
|
|
protected readonly IAbpTagHelperLocalizer TagHelperLocalizer; |
|
|
|
protected readonly IClock Clock; |
|
|
|
protected virtual string TagName { get; set; } = "abp-date-picker"; |
|
|
|
protected IStringLocalizer<AbpUiResource> L { get; } |
|
|
|
protected abstract TagHelperOutput TagHelperOutput { get; set; } |
|
|
|
|
|
|
|
protected AbpDatePickerBaseTagHelperService(IJsonSerializer jsonSerializer, IHtmlGenerator generator, |
|
|
|
HtmlEncoder encoder, IServiceProvider serviceProvider, IStringLocalizer<AbpUiResource> l, |
|
|
|
IAbpTagHelperLocalizer tagHelperLocalizer) |
|
|
|
IAbpTagHelperLocalizer tagHelperLocalizer, IClock clock) |
|
|
|
{ |
|
|
|
JsonSerializer = jsonSerializer; |
|
|
|
Generator = generator; |
|
|
|
@ -80,6 +45,65 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp |
|
|
|
ServiceProvider = serviceProvider; |
|
|
|
L = l; |
|
|
|
TagHelperLocalizer = tagHelperLocalizer; |
|
|
|
Clock = clock; |
|
|
|
|
|
|
|
SupportedInputTypes = new Dictionary<Type, Func<object, string>> |
|
|
|
{ |
|
|
|
{ |
|
|
|
typeof(string), x => |
|
|
|
{ |
|
|
|
if(x is string s && DateTime.TryParse(s, out var dt)) |
|
|
|
{ |
|
|
|
return Clock.Convert(dt).ToString("O"); |
|
|
|
} |
|
|
|
|
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
typeof(DateTime), x => |
|
|
|
{ |
|
|
|
if(x is DateTime dt && dt != default) |
|
|
|
{ |
|
|
|
return Clock.Convert(dt).ToString("O"); |
|
|
|
} |
|
|
|
|
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
typeof(DateTime?), x => |
|
|
|
{ |
|
|
|
if(x is DateTime dt && dt != default) |
|
|
|
{ |
|
|
|
return Clock.Convert(dt).ToString("O"); |
|
|
|
} |
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
typeof(DateTimeOffset), x => |
|
|
|
{ |
|
|
|
if(x is DateTimeOffset dto && dto != default) |
|
|
|
{ |
|
|
|
return Clock.Convert(dto).ToString("O"); |
|
|
|
} |
|
|
|
|
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
typeof(DateTimeOffset?), x => |
|
|
|
{ |
|
|
|
if(x is DateTimeOffset dto && dto != default) |
|
|
|
{ |
|
|
|
return Clock.Convert(dto).ToString("O"); |
|
|
|
} |
|
|
|
|
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual T? GetAttribute<T>() where T : Attribute |
|
|
|
@ -233,6 +257,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp |
|
|
|
} |
|
|
|
|
|
|
|
protected abstract int GetOrder(); |
|
|
|
|
|
|
|
protected abstract void AddBaseTagAttributes(TagHelperAttributeList attributes); |
|
|
|
|
|
|
|
protected virtual string GetExtraInputHtml(TagHelperContext context, TagHelperOutput output) |
|
|
|
@ -375,7 +400,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp |
|
|
|
{ |
|
|
|
attrList.Add("data-visible-date-format", options.VisibleDateFormat); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!options.InputDateFormat.IsNullOrEmpty()) |
|
|
|
{ |
|
|
|
attrList.Add("data-input-date-format", options.InputDateFormat); |
|
|
|
@ -754,7 +779,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp |
|
|
|
{ |
|
|
|
return Task.FromResult(string.Empty); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return GetValidationAsHtmlByInputAsync(context, output, @for); |
|
|
|
} |
|
|
|
|
|
|
|
@ -766,7 +791,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp |
|
|
|
new ValidationMessageTagHelper(Generator) { For = @for, ViewContext = TagHelper.ViewContext }; |
|
|
|
|
|
|
|
var attributeList = new TagHelperAttributeList { { "class", "text-danger" } }; |
|
|
|
|
|
|
|
|
|
|
|
if(!output.Attributes.TryGetAttribute("name", out var nameAttribute) || nameAttribute == null || nameAttribute.Value == null) |
|
|
|
{ |
|
|
|
if (nameAttribute != null) |
|
|
|
@ -776,7 +801,7 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp |
|
|
|
nameAttribute = new TagHelperAttribute("name", "date_" + Guid.NewGuid().ToString("N")); |
|
|
|
output.Attributes.Add(nameAttribute); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
attributeList.Add("data-valmsg-for", nameAttribute.Value); |
|
|
|
|
|
|
|
return await validationMessageTagHelper.RenderAsync(attributeList, context, Encoder, "span", |
|
|
|
|