Skip to content

Commit

Permalink
新增底部工具栏标签<util-footer-toolbar>, 封装 Ng-Alain 底部工具栏 <footer-toolbar> 组件.
Browse files Browse the repository at this point in the history
新增查询表单标签 <util-search-form>,自动设置内部栅格列 span.
<util-table> 标签新增 enable-custom-column 属性,开启自定义列设置.
<util-a> 标签新增 show-table-settings 属性,点击弹出表格自定义列设置界面.
<util-a> 标签新增 is-search 属性, 创建具有展开和收起效果的查询按钮.
修复 Util.Data.EntityFrameworkCore.StoreBase 更新实体验证并发导致的 bug
  • Loading branch information
UtilCore committed Feb 18, 2024
1 parent 87b5e6b commit ec00e69
Show file tree
Hide file tree
Showing 46 changed files with 2,159 additions and 860 deletions.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<VersionMinor>0</VersionMinor>
<VersionPatch>1</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<VersionSuffix>pre-6</VersionSuffix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
16 changes: 9 additions & 7 deletions src/Util.Data.EntityFrameworkCore/StoreBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Util.Exceptions;
using Util.Validation;

namespace Util.Data.EntityFrameworkCore;
namespace Util.Data.EntityFrameworkCore;

/// <summary>
/// 存储器
Expand Down Expand Up @@ -133,7 +133,7 @@ public TEntity FindById( object id ) {
if ( id.SafeString().IsEmpty() )
return null;
var key = GetKey( id );
if( IsTracking )
if ( IsTracking )
return Set.Find( key );
return Single( t => t.Id.Equals( key ) );
}
Expand All @@ -142,7 +142,7 @@ public TEntity FindById( object id ) {
/// 获取标识
/// </summary>
protected object GetKey( object id ) {
if( id is TKey )
if ( id is TKey )
return id;
return Util.Helpers.Convert.To<TKey>( id );
}
Expand All @@ -158,7 +158,7 @@ protected object GetKey( object id ) {
if ( id.SafeString().IsEmpty() )
return null;
var key = GetKey( id );
if( IsTracking )
if ( IsTracking )
return await Set.FindAsync( new[] { key }, cancellationToken );
return await SingleAsync( t => t.Id.Equals( key ), cancellationToken );
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public virtual TEntity Single( Expression<Func<TEntity, bool>> condition ) {
}

/// <inheritdoc />
public virtual TEntity Single( Expression<Func<TEntity, bool>> condition,Func<IQueryable<TEntity>, IQueryable<TEntity>> action ) {
public virtual TEntity Single( Expression<Func<TEntity, bool>> condition, Func<IQueryable<TEntity>, IQueryable<TEntity>> action ) {
if ( action == null )
return Single( condition );
return action( Find() ).FirstOrDefault( condition );
Expand Down Expand Up @@ -328,7 +328,7 @@ public virtual int Count( Expression<Func<TEntity, bool>> condition = null ) {
/// </summary>
protected virtual void Validate( IEnumerable<TEntity> entities ) {
entities.CheckNull( nameof( entities ) );
foreach ( var entity in entities )
foreach ( var entity in entities )
Validate( entity );
}

Expand All @@ -337,7 +337,7 @@ protected virtual void Validate( IEnumerable<TEntity> entities ) {
/// </summary>
protected virtual void Validate( TEntity entity ) {
entity.CheckNull( nameof( entity ) );
if ( entity is IValidation validation )
if ( entity is IValidation validation )
validation.Validate();
}

Expand Down Expand Up @@ -382,6 +382,8 @@ protected void Update( TEntity entity ) {
protected virtual void ValidateVersion( EntityEntry<TEntity> entry, TEntity entity ) {
if ( entity is not IVersion current )
return;
if ( entry.State == EntityState.Added )
return;
if ( current.Version == null || current.Version.Length == 0 ) {
ThrowConcurrencyException( entity );
return;
Expand Down
4 changes: 4 additions & 0 deletions src/Util.Ui.Angular/Configs/AngularConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,4 +1700,8 @@ public static class AngularConst {
/// 自动换行
/// </summary>
public const string BindWrap = "bind-wrap";
/// <summary>
/// 单元格控件
/// </summary>
public const string BindCellControl = "bind-cell-control";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Util.Ui.Angular.Builders;
using Util.Ui.Angular.Configs;
using Util.Ui.Configs;

namespace Util.Ui.NgAlain.Components.FooterToolbars.Builders;

/// <summary>
/// 底部工具栏生成器
/// </summary>
public class FooterToolbarBuilder : AngularTagBuilder {
/// <summary>
/// 配置
/// </summary>
private readonly Config _config;
/// <summary>
/// 初始化底部工具栏生成器
/// </summary>
/// <param name="config">配置</param>
public FooterToolbarBuilder( Config config ) : base( config, "footer-toolbar" ) {
_config = config;
}

/// <summary>
/// 配置错误收集
/// </summary>
public FooterToolbarBuilder ErrorCollect() {
AttributeIfNotEmpty( "[errorCollect]", _config.GetValue( UiConst.ErrorCollect ) );
return this;
}

/// <summary>
/// 配置额外信息
/// </summary>
public FooterToolbarBuilder Extra() {
AttributeIfNotEmpty( "extra", _config.GetValue( UiConst.Extra ) );
AttributeIfNotEmpty( "[extra]", _config.GetValue( AngularConst.BindExtra ) );
return this;
}

/// <summary>
/// 配置
/// </summary>
public override void Config() {
base.Config();
ErrorCollect().Extra();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using Util.Ui.Angular.TagHelpers;
using Util.Ui.Configs;
using Util.Ui.NgAlain.Components.FooterToolbars.Renders;
using Util.Ui.Renders;

namespace Util.Ui.NgAlain.Components.FooterToolbars;

/// <summary>
/// ng-alain 底部工具栏,生成的标签为&lt;footer-toolbar&gt;&lt;/footer-toolbar&gt;
/// </summary>
[HtmlTargetElement( "util-footer-toolbar" )]
public class FooterToolbarTagHelper : AngularTagHelperBase {
/// <summary>
/// [errorCollect],是否收集表单错误,需要放入 form 标签内, 默认值: false
/// </summary>
public string ErrorCollect { get; set; }
/// <summary>
/// extra,额外信息,显示在左边
/// </summary>
public string Extra { get; set; }
/// <summary>
/// [extra],额外信息,显示在左边
/// </summary>
public string BindExtra { get; set; }

/// <inheritdoc />
protected override IRender GetRender( TagHelperContext context, TagHelperOutput output, TagHelperContent content ) {
var config = new Config( context, output, content );
return new FooterToolbarRender( config );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Util.Ui.Angular.Extensions;
using Util.Ui.Builders;
using Util.Ui.Configs;
using Util.Ui.NgAlain.Components.FooterToolbars.Builders;
using Util.Ui.Renders;

namespace Util.Ui.NgAlain.Components.FooterToolbars.Renders;

/// <summary>
/// 底部工具栏渲染器
/// </summary>
public class FooterToolbarRender : RenderBase {
/// <summary>
/// 配置
/// </summary>
private readonly Config _config;

/// <summary>
/// 初始化底部工具栏渲染器
/// </summary>
/// <param name="config">配置</param>
public FooterToolbarRender( Config config ) {
_config = config;
}

/// <summary>
/// 获取标签生成器
/// </summary>
protected override TagBuilder GetTagBuilder() {
var builder = new FooterToolbarBuilder( _config );
builder.Config();
return builder;
}

/// <inheritdoc />
public override IHtmlContent Clone() {
return new FooterToolbarRender( _config.CopyRemoveAttributes() );
}
}
4 changes: 4 additions & 0 deletions src/Util.Ui.NgZorro/Components/Links/ATagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class ATagHelper : ButtonTagHelperBase {
/// 扩展属性,是否查询表单链接,折叠时显示展开文本,展开时显示收起文本
/// </summary>
public bool IsSearch { get; set; }
/// <summary>
/// 扩展属性,显示表格设置,参数值为表格标识
/// </summary>
public string ShowTableSettings { get; set; }

/// <inheritdoc />
protected override IRender GetRender( TagHelperContext context, TagHelperOutput output, TagHelperContent content ) {
Expand Down
26 changes: 23 additions & 3 deletions src/Util.Ui.NgZorro/Components/Links/Builders/ABuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Util.Ui.NgZorro.Components.Base;
using Util.Ui.NgZorro.Components.Icons.Builders;
using Util.Ui.NgZorro.Configs;
using Util.Ui.NgZorro.Directives.Tooltips;
using Util.Ui.NgZorro.Enums;

namespace Util.Ui.NgZorro.Components.Links.Builders;

Expand Down Expand Up @@ -70,8 +72,8 @@ public ABuilder IsSearch() {
return this;
this.OnClick( "expand=!expand" );
var options = NgZorroOptionsService.GetOptions();
if (options.EnableI18n)
AppendContent("{{" + $"expand?('{I18nKeys.Collapse}'|i18n):('{I18nKeys.Expand}'|i18n)" + "}}");
if ( options.EnableI18n )
AppendContent( "{{" + $"expand?('{I18nKeys.Collapse}'|i18n):('{I18nKeys.Expand}'|i18n)" + "}}" );
else
AppendContent( "{{expand?'收起':'展开'}}" );
var icon = new IconBuilder( _config );
Expand All @@ -80,11 +82,29 @@ public ABuilder IsSearch() {
return this;
}

/// <summary>
/// 配置显示表格设置
/// </summary>
public ABuilder ShowTableSettings() {
var tableId = _config.GetValue( UiConst.ShowTableSettings );
if ( tableId.IsEmpty() )
return this;
this.OnClick( $"ts_{tableId}.show()" );
Class( "btn-table-settings" );
var options = NgZorroOptionsService.GetOptions();
this.TooltipTitle( options.EnableI18n ? "util.tableSettings" : "表格设置" );
var icon = new IconBuilder( _config );
icon.Type( AntDesignIcon.Setting );
AppendContent( icon );
return this;
}

/// <summary>
/// 配置
/// </summary>
public override void Config() {
base.Config();
ConfigButton().Href().Target().Rel().RouterLink().DropdownMenu().DropdownMenuPlacement().IsSearch();
ConfigButton().Href().Target().Rel().RouterLink().DropdownMenu()
.DropdownMenuPlacement().IsSearch().ShowTableSettings();
}
}
28 changes: 27 additions & 1 deletion src/Util.Ui.NgZorro/Components/Tables/Builders/TableBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Util.Ui.Angular.Builders;
using Util.Ui.Angular.Configs;
using Util.Ui.Angular.Extensions;
using Util.Ui.Configs;
using Util.Ui.Extensions;
using Util.Ui.NgZorro.Components.Tables.Configs;
using Util.Ui.NgZorro.Components.Tables.Helpers;
Expand Down Expand Up @@ -499,6 +498,32 @@ public TableBuilder ConfigKeys() {
return this;
}

/// <summary>
/// 配置自定义列
/// </summary>
public TableBuilder CustomColumn() {
CustomColumn( _config.GetValue( UiConst.CustomColumn ) );
return this;
}

/// <summary>
/// 配置自定义列
/// </summary>
public TableBuilder CustomColumn( string value ) {
AttributeIfNotEmpty( "[nzCustomColumn]", value );
return this;
}

/// <summary>
/// 配置启用自定义列
/// </summary>
public TableBuilder EnableCustomColumn() {
if (_shareConfig.IsEnableCustomColumn == false)
return this;
CustomColumn( $"{_shareConfig.TableSettingsId}.columns" );
return this;
}

/// <summary>
/// 配置事件
/// </summary>
Expand Down Expand Up @@ -566,6 +591,7 @@ public override void Config() {
.Layout()
.QueryParam().Url().DeleteUrl()
.Sort().AutoLoad().ConfigKeys()
.CustomColumn().EnableCustomColumn()
.Events();
ConfigAutoCreate();
if ( _shareConfig.IsEnableExtend )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Util.Ui.Angular.Builders;
using Util.Ui.Angular.Configs;
using Util.Ui.Builders;
using Util.Ui.Configs;
using Util.Ui.NgZorro.Components.Tables.Builders.Contents;
using Util.Ui.NgZorro.Components.Tables.Configs;
using Util.Ui.NgZorro.Enums;
Expand Down Expand Up @@ -160,6 +159,34 @@ public TableColumnBuilder IndentSize() {
return this;
}

/// <summary>
/// 配置单元格控件
/// </summary>
public virtual TableColumnBuilder CellControl() {
CellControl( _config.GetValue( UiConst.CellControl ) );
AttributeIfNotEmpty( "[nzCellControl]", _config.GetValue( AngularConst.BindCellControl ) );
return this;
}

/// <summary>
/// 配置单元格控件
/// </summary>
/// <param name="value">值</param>
public virtual TableColumnBuilder CellControl( string value ) {
AttributeIfNotEmpty( "nzCellControl", value );
return this;
}

/// <summary>
/// 配置启用自定义列
/// </summary>
public TableColumnBuilder EnableCustomColumn() {
if ( _shareConfig.IsEnableCustomColumn == false )
return this;
CellControl( _shareConfig.CellControl );
return this;
}

/// <summary>
/// 配置事件
/// </summary>
Expand All @@ -177,7 +204,7 @@ public override void Config() {
ShowCheckbox().Disabled().Indeterminate().Checked()
.ShowExpand().Expand()
.Left().Right().Align().BreakWord().Ellipsis()
.IndentSize()
.IndentSize().CellControl().EnableCustomColumn()
.Events();
ConfigContent();
}
Expand Down
Loading

0 comments on commit ec00e69

Please sign in to comment.