Skip to content

Commit

Permalink
1.查询表单展开收起按钮在查询条件数量较少无需展开时将自动隐藏.
Browse files Browse the repository at this point in the history
2. NgZorro配置 Util.Ui.NgZorro.NgZorroOptions 新增属性 EnableTableRowCheckedClass ,用于勾选表格复选框时,为表格行添加 table-row-checked 样式类.
3. NgZorro配置 Util.Ui.NgZorro.NgZorroOptions 新增属性 RazorRootDirectory ,用于设置Razor文件根路径,并将默认值修改为: /ClientApp.
4. NgZorro配置 Util.Ui.NgZorro.NgZorroOptions 新增属性 GenerateHtmlVersion, 控制Razor页面生成html文件路径的方式,使用传统方式需要设置为 v1 .
5. 内置Razor生成Html控制器 Util.Ui.NgZorro.Controllers.GenerateHtmlController.
6. 修复文件监视操作类 Util.Helpers.FileWatcher 多次触发同一个监视事件的问题.
  • Loading branch information
UtilCore committed Mar 30, 2024
1 parent 139753d commit 41a673e
Show file tree
Hide file tree
Showing 23 changed files with 304 additions and 136 deletions.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor>8</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionPatch>9</VersionPatch>
<VersionPatch>10</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
Expand Down
95 changes: 86 additions & 9 deletions src/Util.Core/Helpers/FileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,34 @@ public class FileWatcher : IDisposable {
/// 文件系统监视器
/// </summary>
private readonly FileSystemWatcher _watcher;
/// <summary>
/// 防抖间隔
/// </summary>
private int _debounceInterval;
/// <summary>
/// 文件监视事件过滤器
/// </summary>
private readonly FileWatcherEventFilter _fileWatcherEventFilter;

/// <summary>
/// 初始化文件监视器
/// </summary>
public FileWatcher() {
_watcher = new FileSystemWatcher();
_watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
_watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite
| NotifyFilters.CreationTime | NotifyFilters.LastAccess
| NotifyFilters.Attributes | NotifyFilters.Size | NotifyFilters.Security;
_debounceInterval = 200;
_fileWatcherEventFilter = new FileWatcherEventFilter();
}

/// <summary>
/// 设置防抖间隔,默认值: 200 毫秒
/// </summary>
/// <param name="interval">防抖间隔, 单位: 毫秒</param>
public FileWatcher Debounce( int interval ) {
_debounceInterval = interval;
return this;
}

/// <summary>
Expand Down Expand Up @@ -52,7 +73,8 @@ public FileWatcher Filter( string filter ) {
/// <param name="action">文件创建监听事件处理器</param>
public FileWatcher OnCreated( Action<object, FileSystemEventArgs> action ) {
_watcher.Created += ( source, e ) => {
action( source, e );
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
action( source, e );
};
return this;
}
Expand All @@ -63,7 +85,8 @@ public FileWatcher OnCreated( Action<object, FileSystemEventArgs> action ) {
/// <param name="action">文件创建监听事件处理器</param>
public FileWatcher OnCreatedAsync( Func<object, FileSystemEventArgs, Task> action ) {
_watcher.Created += async ( source, e ) => {
await action( source, e );
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
await action( source, e );
};
return this;
}
Expand All @@ -74,7 +97,8 @@ public FileWatcher OnCreatedAsync( Func<object, FileSystemEventArgs, Task> actio
/// <param name="action">文件变更监听事件处理器</param>
public FileWatcher OnChanged( Action<object, FileSystemEventArgs> action ) {
_watcher.Changed += ( source, e ) => {
action( source, e );
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
action( source, e );
};
return this;
}
Expand All @@ -85,7 +109,8 @@ public FileWatcher OnChanged( Action<object, FileSystemEventArgs> action ) {
/// <param name="action">文件变更监听事件处理器</param>
public FileWatcher OnChangedAsync( Func<object, FileSystemEventArgs, Task> action ) {
_watcher.Changed += async ( source, e ) => {
await action( source, e );
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
await action( source, e );
};
return this;
}
Expand All @@ -96,7 +121,8 @@ public FileWatcher OnChangedAsync( Func<object, FileSystemEventArgs, Task> actio
/// <param name="action">文件删除监听事件处理器</param>
public FileWatcher OnDeleted( Action<object, FileSystemEventArgs> action ) {
_watcher.Deleted += ( source, e ) => {
action( source, e );
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
action( source, e );
};
return this;
}
Expand All @@ -107,7 +133,8 @@ public FileWatcher OnDeleted( Action<object, FileSystemEventArgs> action ) {
/// <param name="action">文件删除监听事件处理器</param>
public FileWatcher OnDeletedAsync( Func<object, FileSystemEventArgs, Task> action ) {
_watcher.Deleted += async ( source, e ) => {
await action( source, e );
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
await action( source, e );
};
return this;
}
Expand All @@ -118,7 +145,8 @@ public FileWatcher OnDeletedAsync( Func<object, FileSystemEventArgs, Task> actio
/// <param name="action">文件重命名监听事件处理器</param>
public FileWatcher OnRenamed( Action<object, RenamedEventArgs> action ) {
_watcher.Renamed += ( source, e ) => {
action( source, e );
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
action( source, e );
};
return this;
}
Expand All @@ -129,7 +157,8 @@ public FileWatcher OnRenamed( Action<object, RenamedEventArgs> action ) {
/// <param name="action">文件重命名监听事件处理器</param>
public FileWatcher OnRenamedAsync( Func<object, RenamedEventArgs, Task> action ) {
_watcher.Renamed += async ( source, e ) => {
await action( source, e );
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
await action( source, e );
};
return this;
}
Expand Down Expand Up @@ -200,4 +229,52 @@ public FileWatcher Stop() {
public void Dispose() {
_watcher?.Dispose();
}
}

/// <summary>
/// 文件监视事件过滤器
/// </summary>
internal class FileWatcherEventFilter {
/// <summary>
/// 最后一个文件
/// </summary>
private WatchFile _file;

/// <summary>
/// 监视事件是否有效
/// </summary>
/// <param name="path">文件路径</param>
/// <param name="debounceInterval">防抖间隔</param>
internal bool IsValid( string path, int debounceInterval ) {
if ( _file != null && path == _file.Path && DateTime.Now - _file.Time < TimeSpan.FromMilliseconds( debounceInterval ) ) {
_file = new WatchFile( path );
return false;
}
_file = new WatchFile( path );
return true;
}
}

/// <summary>
/// 监视文件
/// </summary>
internal class WatchFile {
/// <summary>
/// 初始化监视文件
/// </summary>
/// <param name="path">文件路径</param>
public WatchFile( string path ) {
Path = path;
Time = DateTime.Now;
}

/// <summary>
/// 文件路径
/// </summary>
public string Path { get; }

/// <summary>
/// 处理时间
/// </summary>
public DateTime Time { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Exceptionless.Extensions.Hosting" Version="6.0.3" />
<PackageReference Include="Exceptionless.Extensions.Logging" Version="6.0.3" />
<PackageReference Include="Exceptionless.Extensions.Hosting" Version="6.0.4" />
<PackageReference Include="Exceptionless.Extensions.Logging" Version="6.0.4" />
<PackageReference Include="Serilog.Sinks.Exceptionless" Version="4.0.0" />
</ItemGroup>

Expand Down
16 changes: 5 additions & 11 deletions src/Util.Ui.NgZorro/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public static IAppBuilder AddNgZorro( this IAppBuilder builder, Action<NgZorroOp
builder.Host.ConfigureServices( ( context, services ) => {
var options = new NgZorroOptions();
setupAction?.Invoke( options );
services.AddRazorPages().AddRazorRuntimeCompilation().AddConventions();
services.AddRazorPages( razorPageOptions => {
razorPageOptions.RootDirectory = options.RazorRootDirectory;
} ).AddRazorRuntimeCompilation().AddConventions();
services.TryAddSingleton<IRazorWatchService, RazorWatchService>();
services.TryAddSingleton<IPartViewPathResolver, PartViewPathResolver>();
services.TryAddSingleton<IPartViewPathFinder, PartViewPathFinder>();
Expand All @@ -53,16 +55,8 @@ private static void ConfigSpaStaticFiles( IServiceCollection services, NgZorroOp
/// 配置Razor
/// </summary>
private static void ConfigRazorOptions( IServiceCollection services, NgZorroOptions options ) {
void Action( RazorOptions t ) {
t.IsGenerateHtml = options.IsGenerateHtml;
t.GenerateHtmlBasePath = options.GenerateHtmlBasePath;
t.GenerateHtmlFolder = options.GenerateHtmlFolder;
t.GenerateHtmlSuffix = options.GenerateHtmlSuffix;
t.EnableWatchRazor = options.EnableWatchRazor;
t.StartInitDelay = options.StartInitDelay;
t.HtmlRenderDelayOnRazorChange = options.HtmlRenderDelayOnRazorChange;
t.EnablePreheat = options.EnablePreheat;
t.EnableOverrideHtml = options.EnableOverrideHtml;
void Action( RazorOptions razorOptions ) {
options.MapTo( razorOptions );
}
services.Configure( (Action<RazorOptions>)Action );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Util.Ui.Angular.TagHelpers;
using Util.Ui.Configs;
using Util.Ui.NgZorro.Components.Descriptions.Renders;
using Util.Ui.NgZorro.Components.Display.Helpers;
using Util.Ui.Renders;
Expand Down
23 changes: 22 additions & 1 deletion src/Util.Ui.NgZorro/Components/Links/Renders/ARender.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Util.Ui.Builders;
using Util.Ui.NgZorro.Components.Forms.Configs;
using Util.Ui.NgZorro.Components.Links.Builders;
using Util.Ui.Renders;

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

/// <summary>
/// 链接渲染器
Expand All @@ -25,11 +26,31 @@ public ARender( Config config ) {
/// 获取标签生成器
/// </summary>
protected override TagBuilder GetTagBuilder() {
if ( IsHide() )
return new EmptyTagBuilder();
var builder = new ABuilder( _config );
builder.Config();
return builder;
}

/// <summary>
/// 是否隐藏标签
/// </summary>
private bool IsHide() {
var isSearch = _config.GetValue<bool?>( UiConst.IsSearch );
if ( isSearch != true )
return false;
var formShareConfig = GetFormShareConfig();
return formShareConfig.GetConditionCount() <= formShareConfig.SearchFormShowNumber;
}

/// <summary>
/// 获取表单共享配置
/// </summary>
public FormShareConfig GetFormShareConfig() {
return _config.GetValueFromItems<FormShareConfig>() ?? new FormShareConfig();
}

/// <inheritdoc />
public override IHtmlContent Clone() {
return new ARender( _config.Copy() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public override void Config() {
base.Config();
ConfigTableExtend();
ConfigEdit();
ConfigTableRowCheckedClass();
ConfigContent();
}

Expand Down Expand Up @@ -88,6 +89,16 @@ protected void ConfigEdit() {
Attribute( "(dblclick)", $"{EditId}.dblClickEdit(row.id)", append: true );
}

/// <summary>
/// 配置勾选样式
/// </summary>
protected void ConfigTableRowCheckedClass() {
var options = NgZorroOptionsService.GetOptions();
if ( options.EnableTableRowCheckedClass == false )
return;
Attribute( "[class.table-row-checked]", $"{TableShareConfig.TableExtendId}.isChecked(row)" );
}

/// <summary>
/// 配置内容
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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
28 changes: 28 additions & 0 deletions src/Util.Ui.NgZorro/Controllers/GenerateHtmlController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Util.Ui.Razor;

namespace Util.Ui.NgZorro.Controllers;

/// <summary>
/// Razor生成Html控制器
/// </summary>
[ApiController]
[Route( "api/html" )]
public class GenerateHtmlController : ControllerBase {
/// <summary>
/// 生成所有Razor页面的Html
/// </summary>
[HttpGet]
public async Task<string> GenerateAsync() {
var message = new StringBuilder();
var result = await HtmlGenerator.GenerateAsync();
message.AppendLine( "======================= 欢迎使用 Util 应用框架 - 开始生成全部Razor页面html =======================" );
message.AppendLine();
message.AppendLine();
foreach ( var path in result )
message.AppendLine( path );
message.AppendLine();
message.AppendLine();
message.Append( "======================================== html文件生成完成 ========================================" );
return message.ToString();
}
}
Loading

0 comments on commit 41a673e

Please sign in to comment.