mirror of https://github.com/abpframework/abp.git
committed by
GitHub
28 changed files with 1030 additions and 53 deletions
@ -1,28 +1,25 @@ |
|||
using JetBrains.Annotations; |
|||
using Microsoft.AspNetCore.Components; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Components.Extensibility.EntityActions; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Extensibility.TableColumns |
|||
{ |
|||
public class TableColumn : IEquatable<TableColumn> |
|||
public class TableColumn |
|||
{ |
|||
public string Title { get; set; } |
|||
public string Data { get; set; } |
|||
[CanBeNull] |
|||
public string DisplayFormat { get; set; } |
|||
[CanBeNull] |
|||
public Type Component { get; set; } |
|||
public List<EntityAction> Actions { get; set; } |
|||
[CanBeNull] |
|||
public Func<object,string> ValueConverter { get; set; } |
|||
|
|||
public TableColumn() |
|||
{ |
|||
Actions = new List<EntityAction>(); |
|||
} |
|||
|
|||
public bool Equals(TableColumn other) |
|||
{ |
|||
return string.Equals(Title, other?.Title, StringComparison.OrdinalIgnoreCase) && |
|||
string.Equals(Data, other?.Data, StringComparison.OrdinalIgnoreCase); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,261 @@ |
|||
using Blazorise; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Linq; |
|||
using Volo.Abp.BlazoriseUI.Components.ObjectExtending; |
|||
using Volo.Abp.ObjectExtending; |
|||
using Volo.Abp.Reflection; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI |
|||
{ |
|||
public static class BlazoriseUiObjectExtensionPropertyInfoExtensions |
|||
{ |
|||
private static readonly HashSet<Type> NumberTypes = new HashSet<Type> { |
|||
typeof(int), |
|||
typeof(long), |
|||
typeof(byte), |
|||
typeof(sbyte), |
|||
typeof(short), |
|||
typeof(ushort), |
|||
typeof(uint), |
|||
typeof(long), |
|||
typeof(ulong), |
|||
typeof(float), |
|||
typeof(double), |
|||
typeof(decimal), |
|||
typeof(int?), |
|||
typeof(long?), |
|||
typeof(byte?), |
|||
typeof(sbyte?), |
|||
typeof(short?), |
|||
typeof(ushort?), |
|||
typeof(uint?), |
|||
typeof(long?), |
|||
typeof(ulong?), |
|||
typeof(float?), |
|||
typeof(double?), |
|||
typeof(decimal?) |
|||
}; |
|||
|
|||
private static readonly HashSet<Type> TextEditSupportedAttributeTypes = new HashSet<Type> { |
|||
typeof(EmailAddressAttribute), |
|||
typeof(UrlAttribute), |
|||
typeof(PhoneAttribute) |
|||
}; |
|||
|
|||
public static string GetDateEditInputFormatOrNull(this IBasicObjectExtensionPropertyInfo property) |
|||
{ |
|||
if (property.IsDate()) |
|||
{ |
|||
return "{0:yyyy-MM-dd}"; |
|||
} |
|||
|
|||
if (property.IsDateTime()) |
|||
{ |
|||
return "{0:yyyy-MM-ddTHH:mm}"; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static string GetTextInputValueOrNull(this IBasicObjectExtensionPropertyInfo property, object value) |
|||
{ |
|||
if (value == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
if (TypeHelper.IsFloatingType(property.Type)) |
|||
{ |
|||
return value.ToString()?.Replace(',', '.'); |
|||
} |
|||
|
|||
return value.ToString(); |
|||
} |
|||
|
|||
public static T GetInputValueOrDefault<T>(this IBasicObjectExtensionPropertyInfo property, object value) |
|||
{ |
|||
if (value == null) |
|||
{ |
|||
return default; |
|||
} |
|||
|
|||
return (T)value; |
|||
} |
|||
|
|||
public static TextInputMode GetTextInputMode(this ObjectExtensionPropertyInfo propertyInfo) |
|||
{ |
|||
foreach (var attribute in propertyInfo.Attributes) |
|||
{ |
|||
var textRoleByAttribute = GetTextInputModeFromAttributeOrNull(attribute); |
|||
if (textRoleByAttribute != null) |
|||
{ |
|||
return textRoleByAttribute.Value; |
|||
} |
|||
} |
|||
|
|||
return GetTextInputModeFromTypeOrNull(propertyInfo.Type) |
|||
?? TextInputMode.None; //default
|
|||
} |
|||
|
|||
private static TextInputMode? GetTextInputModeFromTypeOrNull(Type type) |
|||
{ |
|||
if (TypeHelper.IsFloatingType(type)) |
|||
{ |
|||
return TextInputMode.Decimal; |
|||
} |
|||
|
|||
if (NumberTypes.Contains(type)) |
|||
{ |
|||
return TextInputMode.Numeric; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private static TextInputMode? GetTextInputModeFromAttributeOrNull(Attribute attribute) |
|||
{ |
|||
if (attribute is EmailAddressAttribute) |
|||
{ |
|||
return TextInputMode.Email; |
|||
} |
|||
|
|||
if (attribute is UrlAttribute) |
|||
{ |
|||
return TextInputMode.Url; |
|||
} |
|||
|
|||
|
|||
if (attribute is PhoneAttribute) |
|||
{ |
|||
return TextInputMode.Tel; |
|||
} |
|||
|
|||
if (attribute is DataTypeAttribute dataTypeAttribute) |
|||
{ |
|||
switch (dataTypeAttribute.DataType) |
|||
{ |
|||
case DataType.EmailAddress: |
|||
return TextInputMode.Email; |
|||
case DataType.Url: |
|||
return TextInputMode.Url; |
|||
case DataType.PhoneNumber: |
|||
return TextInputMode.Tel; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static TextRole GetTextRole(this ObjectExtensionPropertyInfo propertyInfo) |
|||
{ |
|||
foreach (var attribute in propertyInfo.Attributes) |
|||
{ |
|||
var textRoleByAttribute = GetTextRoleFromAttributeOrNull(attribute); |
|||
if (textRoleByAttribute != null) |
|||
{ |
|||
return textRoleByAttribute.Value; |
|||
} |
|||
} |
|||
|
|||
return TextRole.Text; //default
|
|||
} |
|||
|
|||
private static TextRole? GetTextRoleFromAttributeOrNull(Attribute attribute) |
|||
{ |
|||
if (attribute is EmailAddressAttribute) |
|||
{ |
|||
return TextRole.Email; |
|||
} |
|||
|
|||
if (attribute is UrlAttribute) |
|||
{ |
|||
return TextRole.Url; |
|||
} |
|||
|
|||
if (attribute is DataTypeAttribute dataTypeAttribute) |
|||
{ |
|||
switch (dataTypeAttribute.DataType) |
|||
{ |
|||
case DataType.Password: |
|||
return TextRole.Password; |
|||
case DataType.EmailAddress: |
|||
return TextRole.Email; |
|||
case DataType.Url: |
|||
return TextRole.Url; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static Type GetInputType(this ObjectExtensionPropertyInfo propertyInfo) |
|||
{ |
|||
foreach (var attribute in propertyInfo.Attributes) |
|||
{ |
|||
var inputTypeByAttribute = GetInputTypeFromAttributeOrNull(attribute); |
|||
if (inputTypeByAttribute != null) |
|||
{ |
|||
return inputTypeByAttribute; |
|||
} |
|||
} |
|||
return GetInputTypeFromTypeOrNull(propertyInfo.Type) |
|||
?? typeof(TextExtensionProperty<,>); //default
|
|||
} |
|||
|
|||
private static Type GetInputTypeFromAttributeOrNull(Attribute attribute) |
|||
{ |
|||
var hasTextEditSupport = TextEditSupportedAttributeTypes.Any(t => t == attribute.GetType()); |
|||
|
|||
if (hasTextEditSupport) |
|||
{ |
|||
return typeof(TextExtensionProperty<,>); |
|||
} |
|||
|
|||
|
|||
if (attribute is DataTypeAttribute dataTypeAttribute) |
|||
{ |
|||
switch (dataTypeAttribute.DataType) |
|||
{ |
|||
case DataType.Password: |
|||
return typeof(TextExtensionProperty<,>); |
|||
case DataType.Date: |
|||
return typeof(DateTimeExtensionProperty<,>); |
|||
case DataType.Time: |
|||
return typeof(TimeExtensionProperty<,>); |
|||
case DataType.EmailAddress: |
|||
return typeof(TextExtensionProperty<,>); |
|||
case DataType.Url: |
|||
return typeof(TextExtensionProperty<,>); |
|||
case DataType.PhoneNumber: |
|||
return typeof(TextExtensionProperty<,>); |
|||
case DataType.DateTime: |
|||
return typeof(DateTimeExtensionProperty<,>); |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private static Type GetInputTypeFromTypeOrNull(Type type) |
|||
{ |
|||
if (type == typeof(bool)) |
|||
{ |
|||
return typeof(CheckExtensionProperty<,>); |
|||
} |
|||
|
|||
if (type == typeof(DateTime)) |
|||
{ |
|||
return typeof(DateTimeExtensionProperty<,>); |
|||
} |
|||
|
|||
if (NumberTypes.Contains(type)) |
|||
{ |
|||
return typeof(TextExtensionProperty<,>); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
@typeparam TEntity |
|||
@typeparam TResourceType |
|||
@using Volo.Abp.BlazoriseUI |
|||
@using Volo.Abp.Localization |
|||
|
|||
@if (PropertyInfo != null && Entity != null) |
|||
{ |
|||
<Field> |
|||
<Check TValue="bool" @bind-Checked="@Value">@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</Check> |
|||
</Field> |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.Extensions.Localization; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.ObjectExtending; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending |
|||
{ |
|||
public partial class CheckExtensionProperty<TEntity, TResourceType> : ComponentBase |
|||
where TEntity : IHasExtraProperties |
|||
{ |
|||
[Inject] |
|||
public IStringLocalizerFactory StringLocalizerFactory { get; set; } |
|||
|
|||
[Parameter] |
|||
public TEntity Entity { get; set; } |
|||
|
|||
[Parameter] |
|||
public ObjectExtensionPropertyInfo PropertyInfo { get; set; } |
|||
|
|||
protected bool Value |
|||
{ |
|||
get |
|||
{ |
|||
return PropertyInfo.GetInputValueOrDefault<bool>(Entity.GetProperty(PropertyInfo.Name)); |
|||
} |
|||
set |
|||
{ |
|||
Entity.SetProperty(PropertyInfo.Name, value, false); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
@typeparam TEntity |
|||
@typeparam TResourceType |
|||
@using Volo.Abp.BlazoriseUI |
|||
@using Volo.Abp.Localization |
|||
@using Volo.Abp.ObjectExtending |
|||
|
|||
@if (PropertyInfo != null && Entity != null) |
|||
{ |
|||
<Field> |
|||
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel> |
|||
<DateEdit TValue="DateTime?" |
|||
InputMode="@(PropertyInfo.IsDate() ? DateInputMode.Date : DateInputMode.DateTime)" |
|||
Pattern="@PropertyInfo.GetDateEditInputFormatOrNull()" |
|||
@bind-Date="@Value"> |
|||
</DateEdit> |
|||
</Field> |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.Extensions.Localization; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.ObjectExtending; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending |
|||
{ |
|||
public partial class DateTimeExtensionProperty<TEntity, TResourceType> : ComponentBase |
|||
where TEntity : IHasExtraProperties |
|||
{ |
|||
[Inject] |
|||
public IStringLocalizerFactory StringLocalizerFactory { get; set; } |
|||
|
|||
[Parameter] |
|||
public TEntity Entity { get; set; } |
|||
|
|||
[Parameter] |
|||
public ObjectExtensionPropertyInfo PropertyInfo { get; set; } |
|||
|
|||
protected DateTime? Value |
|||
{ |
|||
get |
|||
{ |
|||
return PropertyInfo.GetInputValueOrDefault<DateTime?>(Entity.GetProperty(PropertyInfo.Name)); |
|||
} |
|||
set |
|||
{ |
|||
Entity.SetProperty(PropertyInfo.Name, value, false); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using Microsoft.Extensions.Localization; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending |
|||
{ |
|||
public static class EnumHelper |
|||
{ |
|||
public static string GetLocalizedMemberName(Type enumType, object value, IStringLocalizerFactory stringLocalizerFactory) |
|||
{ |
|||
var memberName = enumType.GetEnumName(value); |
|||
var localizedMemberName = AbpInternalLocalizationHelper.LocalizeWithFallback( |
|||
new[] |
|||
{ |
|||
stringLocalizerFactory.CreateDefaultOrNull() |
|||
}, |
|||
new[] |
|||
{ |
|||
$"Enum:{enumType.Name}.{memberName}", |
|||
$"{enumType.Name}.{memberName}", |
|||
memberName |
|||
}, |
|||
memberName |
|||
); |
|||
|
|||
return localizedMemberName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
@typeparam TEntityType |
|||
@typeparam TResourceType |
|||
@using Volo.Abp.ObjectExtending |
|||
@using Volo.Abp.Localization |
|||
@using Volo.Abp.Data |
|||
|
|||
@foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<TEntityType>()) |
|||
{ |
|||
if (!propertyInfo.Name.EndsWith("_Text")) |
|||
{ |
|||
if (propertyInfo.Type.IsEnum) |
|||
{ |
|||
<SelectExtensionProperty PropertyInfo="@propertyInfo" Entity="@Entity" TEntity="TEntityType" TResourceType="TResourceType" /> |
|||
} |
|||
else if (!propertyInfo.Lookup.Url.IsNullOrEmpty()) |
|||
{ |
|||
<LookupExtensionProperty PropertyInfo="@propertyInfo" Entity="@Entity" TEntity="TEntityType" TResourceType="TResourceType" /> |
|||
} |
|||
else |
|||
{ |
|||
var inputType = propertyInfo.GetInputType(); |
|||
|
|||
__builder.OpenComponent(0, inputType.MakeGenericType(new[] { typeof(TEntityType), typeof(TResourceType) })); |
|||
__builder.AddAttribute(1, "PropertyInfo", propertyInfo); |
|||
__builder.AddAttribute(2, "Entity", Entity); |
|||
__builder.CloseComponent(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.Extensions.Localization; |
|||
using System; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
using Volo.Abp.Data; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending |
|||
{ |
|||
public partial class ExtensionProperties<TEntityType, TResourceType> : ComponentBase |
|||
where TEntityType : IHasExtraProperties |
|||
{ |
|||
[Inject] |
|||
public IStringLocalizerFactory StringLocalizerFactory { get; set; } |
|||
|
|||
[Parameter] |
|||
public AbpBlazorMessageLocalizerHelper<TResourceType> LH { get; set; } |
|||
|
|||
[Parameter] |
|||
public TEntityType Entity { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
@typeparam TEntity |
|||
@typeparam TResourceType |
|||
@using Abp.Localization |
|||
@using Blazorise.Components |
|||
|
|||
<Field> |
|||
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel> |
|||
<Autocomplete Data="@lookupItems" |
|||
TItem="SelectItem<object>" |
|||
TValue="object" |
|||
TextField="item=>item.Text" |
|||
ValueField="item=>item.Value" |
|||
SelectedValue="@SelectedValue" |
|||
SelectedValueChanged="@SelectedValueChanged" |
|||
SearchChanged="@SearchFilterChangedAsync"> |
|||
</Autocomplete> |
|||
</Field> |
|||
|
|||
@ -0,0 +1,149 @@ |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.Extensions.Localization; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Globalization; |
|||
using System.Linq; |
|||
using System.Net.Http; |
|||
using System.Net.Http.Headers; |
|||
using System.Text.Json; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Http; |
|||
using Volo.Abp.Http.Client; |
|||
using Volo.Abp.Http.Client.Authentication; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.ObjectExtending; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending |
|||
{ |
|||
public partial class LookupExtensionProperty<TEntity, TResourceType> : ComponentBase |
|||
where TEntity : IHasExtraProperties |
|||
{ |
|||
protected List<SelectItem<object>> lookupItems; |
|||
|
|||
[Inject] |
|||
public IStringLocalizerFactory StringLocalizerFactory { get; set; } |
|||
|
|||
[Parameter] |
|||
public TEntity Entity { get; set; } |
|||
|
|||
[Parameter] |
|||
public ObjectExtensionPropertyInfo PropertyInfo { get; set; } |
|||
|
|||
[Inject] |
|||
public IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; set; } |
|||
|
|||
[Inject] |
|||
public IHttpClientFactory HttpClientFactory { get; set; } |
|||
|
|||
[Inject] |
|||
public ICurrentTenant CurrentTenant { get; set; } |
|||
|
|||
[Inject] |
|||
public IOptions<AbpRemoteServiceOptions> RemoteServiceOptions { get; set; } |
|||
|
|||
public string TextPropertyName => PropertyInfo.Name + "_Text"; |
|||
|
|||
public object SelectedValue |
|||
{ |
|||
get |
|||
{ |
|||
return Entity.GetProperty(PropertyInfo.Name); |
|||
} |
|||
set |
|||
{ |
|||
Entity.SetProperty(PropertyInfo.Name, value); |
|||
UpdateLookupTextProperty(value); |
|||
} |
|||
} |
|||
|
|||
public LookupExtensionProperty() |
|||
{ |
|||
lookupItems = new List<SelectItem<object>>(); |
|||
} |
|||
|
|||
protected override void OnParametersSet() |
|||
{ |
|||
var value = Entity.GetProperty(PropertyInfo.Name); |
|||
if (value != null) |
|||
{ |
|||
lookupItems.Add(new SelectItem<object> |
|||
{ |
|||
Text = Entity.GetProperty(TextPropertyName).ToString(), |
|||
Value = value |
|||
}); |
|||
} |
|||
} |
|||
|
|||
protected virtual void UpdateLookupTextProperty(object value) |
|||
{ |
|||
var selectedItemText = lookupItems.SingleOrDefault(t => t.Value.Equals(value)).Text; |
|||
Entity.SetProperty(TextPropertyName, selectedItemText); |
|||
} |
|||
|
|||
protected virtual async Task<List<SelectItem<object>>> GetLookupItemsAsync(string filter) |
|||
{ |
|||
var selectItems = new List<SelectItem<object>>(); |
|||
|
|||
var url = PropertyInfo.Lookup.Url; |
|||
var uri = new Uri(url, UriKind.RelativeOrAbsolute); |
|||
if (!filter.IsNullOrEmpty()) |
|||
{ |
|||
url += $"?{PropertyInfo.Lookup.FilterParamName}={filter.Trim()}"; |
|||
} |
|||
|
|||
var client = HttpClientFactory.CreateClient(); |
|||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, url); |
|||
AddHeaders(requestMessage); |
|||
|
|||
if (!uri.IsAbsoluteUri) |
|||
{ |
|||
var remoteServiceConfig = RemoteServiceOptions.Value.RemoteServices.GetConfigurationOrDefault("Default"); |
|||
client.BaseAddress = new Uri(remoteServiceConfig.BaseUrl); |
|||
await ClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, requestMessage, new RemoteServiceConfiguration(remoteServiceConfig.BaseUrl), string.Empty)); |
|||
} |
|||
|
|||
var response = await client.SendAsync(requestMessage); |
|||
var document = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync()); |
|||
var itemsArrayProp = document.RootElement.GetProperty(PropertyInfo.Lookup.ResultListPropertyName); |
|||
foreach (var item in itemsArrayProp.EnumerateArray()) |
|||
{ |
|||
selectItems.Add(new SelectItem<object> |
|||
{ |
|||
Text = item.GetProperty(PropertyInfo.Lookup.DisplayPropertyName).GetString(), |
|||
Value = JsonSerializer.Deserialize(item.GetProperty(PropertyInfo.Lookup.ValuePropertyName).GetRawText(), PropertyInfo.Type) |
|||
}); |
|||
} |
|||
|
|||
return selectItems; |
|||
} |
|||
|
|||
protected virtual void SelectedValueChanged(object selectedItem) |
|||
{ |
|||
SelectedValue = selectedItem; |
|||
} |
|||
|
|||
protected async Task SearchFilterChangedAsync(string filter) |
|||
{ |
|||
lookupItems = await GetLookupItemsAsync(filter); |
|||
} |
|||
|
|||
protected virtual void AddHeaders(HttpRequestMessage requestMessage) |
|||
{ |
|||
if (CurrentTenant.Id.HasValue) |
|||
{ |
|||
requestMessage.Headers.Add(TenantResolverConsts.DefaultTenantKey, CurrentTenant.Id.Value.ToString()); |
|||
} |
|||
|
|||
var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name; |
|||
if (!currentCulture.IsNullOrEmpty()) |
|||
{ |
|||
requestMessage.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(currentCulture)); |
|||
} |
|||
|
|||
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(MimeTypes.Application.Json)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
@typeparam TEntity |
|||
@typeparam TResourceType |
|||
@using Abp.Localization |
|||
|
|||
<Field> |
|||
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel> |
|||
<Select @bind-SelectedValue="@SelectedValue" > |
|||
@foreach (var item in SelectItems) |
|||
{ |
|||
<SelectItem Value="@item.Value">@item.Text</SelectItem> |
|||
} |
|||
</Select> |
|||
</Field> |
|||
@ -0,0 +1,61 @@ |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.Extensions.Localization; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.ObjectExtending; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending |
|||
{ |
|||
public partial class SelectExtensionProperty<TEntity, TResourceType> : ComponentBase |
|||
where TEntity : IHasExtraProperties |
|||
{ |
|||
protected List<SelectItem<int>> SelectItems = new (); |
|||
|
|||
[Inject] public IStringLocalizerFactory StringLocalizerFactory { get; set; } |
|||
|
|||
[Parameter] public TEntity Entity { get; set; } |
|||
|
|||
[Parameter] public ObjectExtensionPropertyInfo PropertyInfo { get; set; } |
|||
|
|||
public int SelectedValue |
|||
{ |
|||
get { return Entity.GetProperty<int>(PropertyInfo.Name); } |
|||
set { Entity.SetProperty(PropertyInfo.Name, value, false); } |
|||
} |
|||
|
|||
protected virtual List<SelectItem<int>> GetSelectItemsFromEnum() |
|||
{ |
|||
var selectItems = new List<SelectItem<int>>(); |
|||
|
|||
foreach (var enumValue in PropertyInfo.Type.GetEnumValues()) |
|||
{ |
|||
selectItems.Add( new SelectItem<int> |
|||
{ |
|||
Value = (int) enumValue, |
|||
Text = EnumHelper.GetLocalizedMemberName(PropertyInfo.Type, enumValue, StringLocalizerFactory) |
|||
}); |
|||
} |
|||
|
|||
return selectItems; |
|||
} |
|||
|
|||
protected override void OnParametersSet() |
|||
{ |
|||
SelectItems = GetSelectItemsFromEnum(); |
|||
StateHasChanged(); |
|||
|
|||
if (!Entity.HasProperty(PropertyInfo.Name)) |
|||
{ |
|||
SelectedValue = (int)PropertyInfo.Type.GetEnumValues().GetValue(0); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class SelectItem<TValue> |
|||
{ |
|||
public string Text { get; set; } |
|||
public TValue Value { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
@typeparam TEntity |
|||
@typeparam TResourceType |
|||
@using Volo.Abp.BlazoriseUI |
|||
@using Volo.Abp.Localization |
|||
|
|||
@if (PropertyInfo != null && Entity != null) |
|||
{ |
|||
<Field> |
|||
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel> |
|||
<TextEdit @bind-Text="@Value" Role="@PropertyInfo.GetTextRole()" InputMode="@PropertyInfo.GetTextInputMode()"> |
|||
|
|||
</TextEdit> |
|||
</Field> |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.Extensions.Localization; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.ObjectExtending; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending |
|||
{ |
|||
public partial class TextExtensionProperty<TEntity, TResourceType> : ComponentBase |
|||
where TEntity : IHasExtraProperties |
|||
{ |
|||
[Inject] |
|||
public IStringLocalizerFactory StringLocalizerFactory { get; set; } |
|||
|
|||
[Parameter] |
|||
public TEntity Entity { get; set; } |
|||
|
|||
[Parameter] |
|||
public ObjectExtensionPropertyInfo PropertyInfo { get; set; } |
|||
|
|||
|
|||
protected string Value |
|||
{ |
|||
get |
|||
{ |
|||
return PropertyInfo.GetTextInputValueOrNull(Entity.GetProperty(PropertyInfo.Name)); |
|||
} |
|||
set |
|||
{ |
|||
Entity.SetProperty(PropertyInfo.Name, value); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
@typeparam TEntity |
|||
@typeparam TResourceType |
|||
@using Volo.Abp.BlazoriseUI |
|||
@using Volo.Abp.Localization |
|||
|
|||
@if (PropertyInfo != null && Entity != null) |
|||
{ |
|||
<Field> |
|||
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel>--> |
|||
<TimeEdit TValue="TimeSpan?" @bind-Time="@Value"> |
|||
</TimeEdit> |
|||
</Field> |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.Extensions.Localization; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.ObjectExtending; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending |
|||
{ |
|||
public partial class TimeExtensionProperty<TEntity, TResourceType> : ComponentBase |
|||
where TEntity : IHasExtraProperties |
|||
{ |
|||
[Inject] |
|||
public IStringLocalizerFactory StringLocalizerFactory { get; set; } |
|||
|
|||
[Parameter] |
|||
public TEntity Entity { get; set; } |
|||
|
|||
[Parameter] |
|||
public ObjectExtensionPropertyInfo PropertyInfo { get; set; } |
|||
|
|||
protected TimeSpan? Value |
|||
{ |
|||
get |
|||
{ |
|||
return PropertyInfo.GetInputValueOrDefault<TimeSpan?>(Entity.GetProperty(PropertyInfo.Name)); |
|||
} |
|||
set |
|||
{ |
|||
Entity.SetProperty(PropertyInfo.Name, value, false); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.ObjectExtending |
|||
{ |
|||
public static class ObjectExtensionPropertyInfoBlazorExtensions |
|||
{ |
|||
private static readonly Type[] DateTimeTypes = |
|||
{ |
|||
typeof(DateTime), |
|||
typeof(DateTime?), |
|||
typeof(DateTimeOffset), |
|||
typeof(DateTimeOffset?) |
|||
}; |
|||
|
|||
public static bool IsDate(this IBasicObjectExtensionPropertyInfo property) |
|||
{ |
|||
return DateTimeTypes.Contains(property.Type) && |
|||
property.GetDataTypeOrNull() == DataType.Date; |
|||
} |
|||
|
|||
public static bool IsDateTime(this IBasicObjectExtensionPropertyInfo property) |
|||
{ |
|||
return DateTimeTypes.Contains(property.Type) && |
|||
!property.IsDate(); |
|||
} |
|||
|
|||
public static DataType? GetDataTypeOrNull(this IBasicObjectExtensionPropertyInfo property) |
|||
{ |
|||
return property |
|||
.Attributes |
|||
.OfType<DataTypeAttribute>() |
|||
.FirstOrDefault()?.DataType; |
|||
} |
|||
} |
|||
} |
|||
@ -1,20 +1,20 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
|||
|
|||
<Import Project="..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\common.props" /> |
|||
<Import Project="..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net5.0</TargetFramework> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<TargetFramework>net5.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.AspNetCore.Components.WebAssembly\Volo.Abp.AspNetCore.Components.WebAssembly.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Blazorise" Version="0.9.3-preview8" /> |
|||
<PackageReference Include="Blazorise.DataGrid" Version="0.9.3-preview8" /> |
|||
<PackageReference Include="Blazorise.Snackbar" Version="0.9.3-preview8" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.AspNetCore.Components.WebAssembly\Volo.Abp.AspNetCore.Components.WebAssembly.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Blazorise" Version="0.9.3-preview8" /> |
|||
<PackageReference Include="Blazorise.DataGrid" Version="0.9.3-preview8" /> |
|||
<PackageReference Include="Blazorise.Snackbar" Version="0.9.3-preview8" /> |
|||
<PackageReference Include="Blazorise.Components" Version="0.9.3-preview8" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue