-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(Tasks): add Bootstrap.Tasks.Dashboard project #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6eeafde
chore: 增加 TaskDashboard 组件
ArgoZhang 6daed50
feat: 实现日志功能
ArgoZhang 0d861cb
feat: 增加日志弹窗逻辑
ArgoZhang 9bc8034
refactor: 调整顺序
ArgoZhang d4c1050
feat: 实现异常明细弹窗功能
ArgoZhang 9a3f70e
refactor: 移除测试代码
ArgoZhang d5bc683
doc: 增加异常 UI 格式化逻辑
ArgoZhang 05915a6
doc: 代码格式化
ArgoZhang 6cc3d6a
doc: 代码注释
ArgoZhang cd1984e
refactor: 支持多播
ArgoZhang a799c38
refactor: 触发器未执行时不显示日志
ArgoZhang 3cd022f
chore(Tasks): bump version 9.0.0
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
src/components/BootstrapBlazor.Tasks.Dashboard/BootstrapBlazor.Tasks.Dashboard.csproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Razor"> | ||
|
|
||
| <PropertyGroup> | ||
| <Version>9.0.0</Version> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <PackageTags>Bootstrap Blazor WebAssembly wasm UI Components Task Dashboard</PackageTags> | ||
| <Description>Bootstrap UI components extensions of Task</Description> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Content Remove="Locales\en-US.json" /> | ||
| <Content Remove="Locales\zh-CN.json" /> | ||
| <EmbeddedResource Include="Locales\en-US.json" /> | ||
| <EmbeddedResource Include="Locales\zh-CN.json" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="BootstrapBlazor" Version="9.0.0" /> | ||
| <PackageReference Include="Longbow.Tasks" Version="9.0.2" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="BootstrapBlazor.Components" /> | ||
| <Using Include="Longbow.Tasks" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
26 changes: 26 additions & 0 deletions
26
src/components/BootstrapBlazor.Tasks.Dashboard/Locales/en-US.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "BootstrapBlazor.Components.Tasks.TaskDashboard": { | ||
| "Name": "Name", | ||
| "Status": "Status", | ||
| "NextRuntime": "NextRuntime", | ||
| "LastRuntime": "LastRuntime", | ||
| "LastRunResult": "LastRunResult", | ||
| "Exception": "Exception", | ||
| "Operation": "Operation", | ||
| "SchedulerStatus.Running": "Running", | ||
| "SchedulerStatus.Ready": "Ready", | ||
| "SchedulerStatus.Disabled": "Disabled", | ||
| "TriggerResult.Running": "Running", | ||
| "TriggerResult.Success": "Success", | ||
| "TriggerResult.Cancelled": "Cancelled", | ||
| "TriggerResult.Timeout": "Timeout", | ||
| "TriggerResult.Error": "Error", | ||
| "ButtonPause": "Pause", | ||
| "ButtonRun": "Run", | ||
| "ButtonLog": "Log", | ||
| "LogDialogTitle": "{0} - Log(Latest 20 Items)", | ||
| "LogDialogConsoleHeaderText": "Action Log", | ||
| "ExceptionDialogTitle": "{0} - Exception Detail", | ||
| "None": "None" | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/components/BootstrapBlazor.Tasks.Dashboard/Locales/zh-CN.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "BootstrapBlazor.Components.Tasks.TaskDashboard": { | ||
| "Name": "名称", | ||
| "Status": "调度状态", | ||
| "NextRuntime": "下次运行时间", | ||
| "LastRuntime": "上次运行时间", | ||
| "LastRunResult": "上次结果", | ||
| "Exception": "异常", | ||
| "Operation": "操作", | ||
| "SchedulerStatus.Running": "运行中", | ||
| "SchedulerStatus.Ready": "已停止", | ||
| "SchedulerStatus.Disabled": "禁用", | ||
| "TriggerResult.Running": "运行", | ||
| "TriggerResult.Success": "成功", | ||
| "TriggerResult.Cancelled": "取消", | ||
| "TriggerResult.Timeout": "超时", | ||
| "TriggerResult.Error": "故障", | ||
| "ButtonPause": "暂停", | ||
| "ButtonRun": "运行", | ||
| "ButtonLog": "日志", | ||
| "LogDialogTitle": "{0} - 日志窗口(最新 20 条)", | ||
| "LogDialogConsoleHeaderText": "执行日志", | ||
| "ExceptionDialogTitle": "{0} - 异常明细", | ||
| "None": "无" | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
src/components/BootstrapBlazor.Tasks.Dashboard/TaskDashboard.razor
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| @namespace BootstrapBlazor.Components.Tasks | ||
| @inherits BootstrapComponentBase | ||
|
|
||
| <div @attributes="AdditionalAttributes" class="@ClassString"> | ||
| <Table TItem="IScheduler" Items="@_schedulers" IsBordered="true" IsStriped="true"> | ||
| <TableColumns> | ||
| <TableTemplateColumn Text="@Localizer["Name"]"> | ||
| <Template Context="v"> | ||
| @v.Row.Name | ||
| </Template> | ||
| </TableTemplateColumn> | ||
| <TableTemplateColumn Text="@Localizer["Status"]"> | ||
| <Template Context="v"> | ||
| <Tag Color="GetStatusColor(v.Row.Status)" Icon="@GetStatusIcon(v.Row.Status)">@FormatStatus(v.Row.Status)</Tag> | ||
| </Template> | ||
| </TableTemplateColumn> | ||
| <TableTemplateColumn Text="@Localizer["LastRuntime"]"> | ||
| <Template Context="v"> | ||
| @FormatDateTime(v.Row.LastRuntime) | ||
| </Template> | ||
| </TableTemplateColumn> | ||
| <TableTemplateColumn Text="@Localizer["NextRuntime"]"> | ||
| <Template Context="v"> | ||
| @FormatDateTime(v.Row.NextRuntime) | ||
| </Template> | ||
| </TableTemplateColumn> | ||
| <TableTemplateColumn Text="@Localizer["LastRunResult"]"> | ||
| <Template Context="v"> | ||
| <Tag Color="GetResultColor(v.Row.LastRunResult)">@FormatResult(v.Row.LastRunResult)</Tag> | ||
| </Template> | ||
| </TableTemplateColumn> | ||
| <TableTemplateColumn Text="@Localizer["Exception"]"> | ||
| <Template Context="v"> | ||
| @if (v.Row.Exception != null) | ||
| { | ||
| <Button Color="Color.Danger" Size="Size.ExtraSmall" Icon="fa-solid fa-exclamation-circle" | ||
| OnClickWithoutRender="() => OnShowException(v.Row, v.Row.Exception)"></Button> | ||
| } | ||
| else | ||
| { | ||
| <Tag Color="Color.Success">@Localizer["None"]</Tag> | ||
| } | ||
| </Template> | ||
| </TableTemplateColumn> | ||
| <TableTemplateColumn Text="@Localizer["Operation"]" Width="170"> | ||
| <Template Context="v"> | ||
| <div class="btn-group"> | ||
| <Button Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa-solid fa-pause-circle" | ||
| Text="@Localizer["ButtonPause"]" OnClick="() => OnPause(v.Row)" IsDisabled="OnCheckPauseTaskStatus(v.Row)"></Button> | ||
| <Button Size="Size.ExtraSmall" Color="Color.Success" Icon="fa-solid fa-play-circle" | ||
| Text="@Localizer["ButtonRun"]" OnClick="() => OnRun(v.Row)" IsDisabled="OnCheckRunTaskStatus(v.Row)"></Button> | ||
| <Button Size="Size.ExtraSmall" Color="Color.Info" Icon="fa-solid fa-info-circle" | ||
| Text="@Localizer["ButtonLog"]" OnClick="() => OnLog(v.Row)"></Button> | ||
| </div> | ||
| </Template> | ||
| </TableTemplateColumn> | ||
| </TableColumns> | ||
| </Table> | ||
| </div> |
122 changes: 122 additions & 0 deletions
122
src/components/BootstrapBlazor.Tasks.Dashboard/TaskDashboard.razor.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // Copyright (c) Argo Zhang (argo@163.com). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.Extensions.Localization; | ||
|
|
||
| namespace BootstrapBlazor.Components.Tasks; | ||
|
|
||
| /// <summary> | ||
| /// Task Dashboard Component | ||
| /// </summary> | ||
| public partial class TaskDashboard | ||
| { | ||
| [Inject, NotNull] | ||
| private IStringLocalizer<TaskDashboard>? Localizer { get; set; } | ||
|
|
||
| [Inject, NotNull] | ||
| private DialogService? DialogService { get; set; } | ||
|
|
||
| private string? ClassString => CssBuilder.Default("bb-tasks-dashboard") | ||
| .AddClassFromAttributes(AdditionalAttributes) | ||
| .Build(); | ||
|
|
||
| private IEnumerable<IScheduler> _schedulers = []; | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| protected override void OnParametersSet() | ||
| { | ||
| base.OnParametersSet(); | ||
|
|
||
| _schedulers = TaskServicesManager.ToList(); | ||
| } | ||
|
|
||
| private static Color GetStatusColor(SchedulerStatus status) => status switch | ||
| { | ||
| SchedulerStatus.Running => Color.Success, | ||
| SchedulerStatus.Ready => Color.Primary, | ||
| _ => Color.Danger | ||
| }; | ||
|
|
||
| private string FormatStatus(SchedulerStatus status) => status switch | ||
| { | ||
| SchedulerStatus.Running => Localizer["SchedulerStatus.Running"], | ||
| SchedulerStatus.Ready => Localizer["SchedulerStatus.Ready"], | ||
| _ => Localizer["SchedulerStatus.Disabled"] | ||
| }; | ||
|
|
||
| private static string GetStatusIcon(SchedulerStatus status) => status switch | ||
| { | ||
| SchedulerStatus.Running => "fa-solid fa-play-circle", | ||
| SchedulerStatus.Ready => "fa-solid fa-stop-circle", | ||
| _ => "fa-solid fa-times-circle" | ||
| }; | ||
|
|
||
| private static Color GetResultColor(TriggerResult result) => result switch | ||
| { | ||
| TriggerResult.Running => Color.Primary, | ||
| TriggerResult.Success => Color.Success, | ||
| TriggerResult.Cancelled => Color.Dark, | ||
| TriggerResult.Timeout => Color.Warning, | ||
| _ => Color.Danger, | ||
| }; | ||
|
|
||
| private string FormatResult(TriggerResult result) => result switch | ||
| { | ||
| TriggerResult.Running => Localizer["TriggerResult.Running"], | ||
| TriggerResult.Success => Localizer["TriggerResult.Success"], | ||
| TriggerResult.Cancelled => Localizer["TriggerResult.Timeout"], | ||
| TriggerResult.Timeout => Localizer["TriggerResult.Timeout"], | ||
| _ => Localizer["TriggerResult.Error"], | ||
| }; | ||
|
|
||
| private static Task OnPause(IScheduler scheduler) | ||
| { | ||
| scheduler.Status = SchedulerStatus.Ready; | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private static Task OnRun(IScheduler scheduler) | ||
| { | ||
| scheduler.Status = SchedulerStatus.Running; | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private async Task OnLog(IScheduler scheduler) | ||
| { | ||
| var option = new DialogOption() | ||
| { | ||
| Class = "modal-dialog-task-log", | ||
| Title = Localizer["LogDialogTitle", scheduler.Name], | ||
| Component = BootstrapDynamicComponent.CreateComponent<TaskInfo>(new Dictionary<string, object?> | ||
| { | ||
| [nameof(TaskInfo.Scheduler)] = scheduler, | ||
| [nameof(TaskInfo.HeaderText)] = Localizer["LogDialogConsoleHeaderText"].Value | ||
| }) | ||
| }; | ||
| await DialogService.Show(option); | ||
| } | ||
|
|
||
| private static bool OnCheckPauseTaskStatus(IScheduler model) => model.Status != SchedulerStatus.Running; | ||
|
|
||
| private static bool OnCheckRunTaskStatus(IScheduler model) => model.Status == SchedulerStatus.Running; | ||
|
|
||
| private static string? FormatDateTime(DateTimeOffset? dateTime) => dateTime?.ToString("yyyy-MM-dd HH:mm:ss"); | ||
|
|
||
| private async Task OnShowException(IScheduler scheduler, Exception ex) | ||
| { | ||
| var option = new DialogOption() | ||
| { | ||
| Class = "modal-dialog-task-ex", | ||
| IsScrolling = true, | ||
| Title = Localizer["ExceptionDialogTitle", scheduler.Name], | ||
| BodyTemplate = RenderException(ex) | ||
| }; | ||
| await DialogService.Show(option); | ||
| } | ||
|
|
||
| private static RenderFragment RenderException(Exception ex) => builder => builder.AddContent(0, ex.FormatMarkupString()); | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
src/components/BootstrapBlazor.Tasks.Dashboard/TaskDashboard.razor.css
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .my-component { | ||
| border: 2px dashed red; | ||
| padding: 1em; | ||
| margin: 1em 0; | ||
| background-image: url('background.png'); | ||
|
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: CSS class .my-component is defined but not used. If the class is not needed, please remove it to keep the stylesheet clean. |
||
| } | ||
3 changes: 3 additions & 0 deletions
3
src/components/BootstrapBlazor.Tasks.Dashboard/TaskInfo.razor
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @namespace BootstrapBlazor.Components.Tasks | ||
|
|
||
| <BootstrapBlazor.Components.Console Items="@Messages" Height="280" ShowAutoScroll="true" HeaderText="@HeaderText" /> |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Cancelled result is mapped to Timeout localization key.
Using the Timeout key for Cancelled may mislead users. Please add a separate localization key for Cancelled.
Suggested implementation:
You must also add the "TriggerResult.Cancelled" key to your localization resource files (e.g., .resx or JSON files) with the appropriate value for each supported language.