Create AbpText and AbpDynamicText#25469
Open
blackWins wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds new Bootstrap UI form tag helpers to render read-only “text” fields (single field and model-driven dynamic rendering) in ABP’s ASP.NET Core MVC UI layer.
Changes:
- Introduces
abp-textto render a label/value row for a singleasp-formodel expression. - Introduces
abp-dynamic-textto render multipleabp-textblocks by traversing a provided model (abp-model). - Adds an
[AbpText]attribute intended to control formatting/label behavior from model metadata.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpTextTagHelperService.cs | Implements HTML generation and type-specific rendering for abp-text. |
| framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpTextTagHelper.cs | Defines the abp-text tag helper attributes (asp-for, label-width, format, etc.). |
| framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpText.cs | Adds [AbpText] attribute for property-level configuration. |
| framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpDynamicTextTagHelperService.cs | Implements model traversal and rendering multiple abp-text instances. |
| framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpDynamicTextTagHelper.cs | Defines the abp-dynamic-text tag helper (abp-model, column-size, label-width). |
Comment on lines
+171
to
+180
| var modelType = value.GetType(); | ||
| var enumType = modelType.IsEnum ? modelType : Nullable.GetUnderlyingType(modelType); | ||
| var containerLocalizer = _tagHelperLocalizer.GetLocalizerOrNull(TagHelper.AspFor.ModelExplorer.Container.ModelType.Assembly); | ||
| var localizedMemberName = value == null ? "-" : _abpEnumLocalizer.GetString(enumType!, (int)value, | ||
| new[] | ||
| { | ||
| containerLocalizer, | ||
| _stringLocalizerFactory.CreateDefaultOrNull() | ||
| }!); | ||
| return HtmlEncoder.Encode(localizedMemberName ?? string.Empty); |
Comment on lines
+86
to
+92
| if (!TagHelper.SuppressLabel) | ||
| { | ||
| var labelWidth = $"col-{(int)TagHelper.LabelWidth}"; | ||
| contentBuilder.AppendLine($"<div class=\"{labelWidth}\">"); | ||
| contentBuilder.AppendLine(labelHtml); | ||
| contentBuilder.AppendLine("</div>"); | ||
| } |
Comment on lines
+186
to
+201
|
|
||
| var format = TagHelper.Format ?? TagHelper.AspFor.ModelExplorer.GetAttribute<AbpText>()?.Format; | ||
|
|
||
| if (value is DateTime dateTime) | ||
| { | ||
| return dateTime.ToString(format); | ||
| } | ||
|
|
||
| if (value is DateTimeOffset dateTimeOffset) | ||
| { | ||
| return dateTimeOffset.ToString(format); | ||
| } | ||
|
|
||
| return value.ToString() ?? string.Empty; | ||
| } | ||
|
|
|
|
||
| protected virtual string GetFileValue() | ||
| { | ||
| return "<span class=\"text-info\"><i class=\"bi bi-file\"></i> File</span>"; |
Comment on lines
+221
to
+235
| protected virtual string GetCollectionValue() | ||
| { | ||
| var value = TagHelper.AspFor.Model; | ||
|
|
||
| //todo Consider supporting collection render. | ||
| if (value is System.Collections.IEnumerable enumerable) | ||
| { | ||
| var count = 0; | ||
| foreach (var item in enumerable) | ||
| { | ||
| count++; | ||
| } | ||
|
|
||
| return count.ToString(); | ||
| } |
| @@ -0,0 +1,278 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Reflection.Emit; | |||
| @@ -0,0 +1,21 @@ | |||
| using System; | |||
| using Microsoft.AspNetCore.Razor.TagHelpers; | |||
Comment on lines
+23
to
+39
| protected HtmlEncoder HtmlEncoder { get; } | ||
| protected IServiceProvider ServiceProvider { get; } | ||
| protected List<ModelExpression> Models = new(); | ||
| protected readonly IAbpEnumLocalizer AbpEnumLocalizer; | ||
| protected readonly IStringLocalizerFactory StringLocalizerFactory; | ||
|
|
||
| public AbpDynamicTextTagHelperService( | ||
| HtmlEncoder htmlEncoder, | ||
| IServiceProvider serviceProvider, | ||
| IAbpEnumLocalizer abpEnumLocalizer, | ||
| IStringLocalizerFactory stringLocalizerFactory | ||
| ) | ||
| { | ||
| HtmlEncoder = htmlEncoder; | ||
| ServiceProvider = serviceProvider; | ||
| AbpEnumLocalizer = abpEnumLocalizer; | ||
| StringLocalizerFactory = stringLocalizerFactory; |
Comment on lines
+36
to
+45
| public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | ||
| { | ||
| var childContent = await output.GetChildContentAsync(); | ||
|
|
||
| NormalizeTagMode(context, output); | ||
| SetAttributes(context, output); | ||
|
|
||
| var html = GetHtml(context, output); | ||
| SetContent(context, output, html, childContent); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New AbpTextTagHelper
New AbpDynamicTextTagHelper
How to test it?
abp-text
Usage:
Tag Attributes
abp-dynamic-text
Usage:
Tag Attributes