Browse Source

Allow Setting Extended Property as ReadOnly for Blazor UI

pull/16823/head
Engincan VESKE 3 years ago
parent
commit
139f45de14
  1. 2
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor
  2. 1
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor
  3. 1
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor
  4. 4
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor.cs
  5. 5
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionPropertyComponentBase.cs
  6. 3
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor
  7. 2
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor
  8. 2
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor
  9. 2
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor
  10. 18
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs

2
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor

@ -8,7 +8,7 @@
{ {
<Validation Validator="@Validate" MessageLocalizer="@LH.Localize"> <Validation Validator="@Validate" MessageLocalizer="@LH.Localize">
<Field> <Field>
<Check TValue="bool" @bind-Checked="@Value"> <Check TValue="bool" @bind-Checked="@Value" Disabled="IsReadonlyField">
<ChildContent> <ChildContent>
@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)
</ChildContent> </ChildContent>

1
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor

@ -13,6 +13,7 @@
<DateEdit TValue="DateTime?" <DateEdit TValue="DateTime?"
InputMode="@(PropertyInfo.IsDate() ? DateInputMode.Date : DateInputMode.DateTime)" InputMode="@(PropertyInfo.IsDate() ? DateInputMode.Date : DateInputMode.DateTime)"
Pattern="@PropertyInfo.GetDateEditInputFormatOrNull()" Pattern="@PropertyInfo.GetDateEditInputFormatOrNull()"
Disabled="IsReadonlyField"
@bind-Date="@Value"> @bind-Date="@Value">
<Feedback> <Feedback>
<ValidationError/> <ValidationError/>

1
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor

@ -25,6 +25,7 @@
__builder.AddAttribute(1, "PropertyInfo", propertyInfo); __builder.AddAttribute(1, "PropertyInfo", propertyInfo);
__builder.AddAttribute(2, "Entity", Entity); __builder.AddAttribute(2, "Entity", Entity);
__builder.AddAttribute(3, "LH", LH); __builder.AddAttribute(3, "LH", LH);
__builder.AddAttribute(4, "EditForm", EditForm);
__builder.CloseComponent(); __builder.CloseComponent();
} }
} }

4
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor.cs

@ -2,6 +2,7 @@
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Volo.Abp.AspNetCore.Components.Web; using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending; namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending;
@ -16,4 +17,7 @@ public partial class ExtensionProperties<TEntityType, TResourceType> : Component
[Parameter] [Parameter]
public TEntityType Entity { get; set; } public TEntityType Entity { get; set; }
[Parameter]
public bool? EditForm { get; set; }
} }

5
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionPropertyComponentBase.cs

@ -33,6 +33,9 @@ public abstract class ExtensionPropertyComponentBase<TEntity, TResourceType> : O
[Parameter] [Parameter]
public AbpBlazorMessageLocalizerHelper<TResourceType> LH { get; set; } public AbpBlazorMessageLocalizerHelper<TResourceType> LH { get; set; }
[Parameter]
public bool? EditForm { get; set; }
protected virtual void Validate(ValidatorEventArgs e) protected virtual void Validate(ValidatorEventArgs e)
{ {
e.Status = ValidationStatus.Success; e.Status = ValidationStatus.Success;
@ -71,6 +74,8 @@ public abstract class ExtensionPropertyComponentBase<TEntity, TResourceType> : O
} }
} }
protected bool IsReadonlyField => EditForm.HasValue && EditForm.Value && PropertyInfo.UI.EditModal.IsReadOnly;
private static string GetDefaultErrorMessage(ValidationAttribute validationAttribute) private static string GetDefaultErrorMessage(ValidationAttribute validationAttribute)
{ {
if (validationAttribute is StringLengthAttribute stringLengthAttribute && stringLengthAttribute.MinimumLength != 0) if (validationAttribute is StringLengthAttribute stringLengthAttribute && stringLengthAttribute.MinimumLength != 0)

3
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor

@ -15,6 +15,7 @@
SelectedValueChanged="@SelectedValueChanged" SelectedValueChanged="@SelectedValueChanged"
SearchChanged="@SearchFilterChangedAsync" SearchChanged="@SearchFilterChangedAsync"
Validator="@Validate" Validator="@Validate"
MinLength="0"> MinLength="0"
Disabled="IsReadonlyField">
</Autocomplete> </Autocomplete>
</Field> </Field>

2
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor

@ -10,7 +10,7 @@
<ChildContent> <ChildContent>
@foreach (var item in SelectItems) @foreach (var item in SelectItems)
{ {
<SelectItem Value="@item.Value">@item.Text</SelectItem> <SelectItem Value="@item.Value" Disabled="IsReadonlyField">@item.Text</SelectItem>
} }
</ChildContent> </ChildContent>
<Feedback> <Feedback>

2
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor

@ -9,7 +9,7 @@
<Validation Validator="@Validate" MessageLocalizer="@LH.Localize"> <Validation Validator="@Validate" MessageLocalizer="@LH.Localize">
<Field> <Field>
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel> <FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel>
<TextEdit @bind-Text="@Value" Role="@PropertyInfo.GetTextRole()" InputMode="@PropertyInfo.GetTextInputMode()"> <TextEdit @bind-Text="@Value" Role="@PropertyInfo.GetTextRole()" InputMode="@PropertyInfo.GetTextInputMode()" Disabled="IsReadonlyField">
<Feedback> <Feedback>
<ValidationError/> <ValidationError/>
</Feedback> </Feedback>

2
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor

@ -9,7 +9,7 @@
<Validation Validator="@Validate" MessageLocalizer="@LH.Localize"> <Validation Validator="@Validate" MessageLocalizer="@LH.Localize">
<Field> <Field>
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel>--> <FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel>-->
<TimeEdit TValue="TimeSpan?" @bind-Time="@Value"> <TimeEdit TValue="TimeSpan?" @bind-Time="@Value" Disabled="IsReadonlyField">
<Feedback> <Feedback>
<ValidationError/> <ValidationError/>
</Feedback> </Feedback>

18
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs

@ -60,6 +60,8 @@ public class ObjectExtensionPropertyInfo : IHasNameWithLocalizableDisplayName, I
[NotNull] [NotNull]
public ExtensionPropertyLookupConfiguration Lookup { get; set; } public ExtensionPropertyLookupConfiguration Lookup { get; set; }
public ExtensionPropertyUI UI { get; set; }
public ObjectExtensionPropertyInfo( public ObjectExtensionPropertyInfo(
[NotNull] ObjectExtensionInfo objectExtension, [NotNull] ObjectExtensionInfo objectExtension,
[NotNull] Type type, [NotNull] Type type,
@ -76,10 +78,26 @@ public class ObjectExtensionPropertyInfo : IHasNameWithLocalizableDisplayName, I
Attributes.AddRange(ExtensionPropertyHelper.GetDefaultAttributes(Type)); Attributes.AddRange(ExtensionPropertyHelper.GetDefaultAttributes(Type));
DefaultValue = TypeHelper.GetDefaultValue(Type); DefaultValue = TypeHelper.GetDefaultValue(Type);
Lookup = new ExtensionPropertyLookupConfiguration(); Lookup = new ExtensionPropertyLookupConfiguration();
UI = new ExtensionPropertyUI();
} }
public object GetDefaultValue() public object GetDefaultValue()
{ {
return ExtensionPropertyHelper.GetDefaultValue(Type, DefaultValueFactory, DefaultValue); return ExtensionPropertyHelper.GetDefaultValue(Type, DefaultValueFactory, DefaultValue);
} }
public class ExtensionPropertyUI
{
public ExtensionPropertyUIEditModal EditModal { get; set; }
public ExtensionPropertyUI()
{
EditModal = new ExtensionPropertyUIEditModal();
}
}
public class ExtensionPropertyUIEditModal
{
public bool IsReadOnly { get; set; }
}
} }

Loading…
Cancel
Save