-
-
Notifications
You must be signed in to change notification settings - Fork 363
doc(OnlineSheet): add OnlineSheet sample code #5510
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
5 commits
Select commit
Hold shift + click to select a range
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
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
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
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
6 changes: 6 additions & 0 deletions
6
src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet.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,6 @@ | ||
| @page "/OnlineSheet" | ||
| <h3>OnlineSheet</h3> | ||
|
|
||
| @code { | ||
|
|
||
| } |
8 changes: 8 additions & 0 deletions
8
src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet.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,8 @@ | ||
| using Microsoft.AspNetCore.Components; | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Samples.Tutorials; | ||
|
|
||
| public partial class OnlineSheet : ComponentBase | ||
| { | ||
| } | ||
|
|
1 change: 1 addition & 0 deletions
1
src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet.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 @@ | ||
| |
16 changes: 16 additions & 0 deletions
16
src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineContributor.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,16 @@ | ||
| @namespace BootstrapBlazor.Server.Components.Samples.Tutorials | ||
|
|
||
| <div class="bb-contributor"> | ||
| <img src="@Contributor.Avatar" /> | ||
| <div class="bb-contributor-main"> | ||
| <div class="bb-contributor-item"> | ||
| <label>姓名:</label> | ||
| <span>@Contributor.Name</span> | ||
| </div> | ||
| <div class="bb-contributor-item"> | ||
| <label>姓名:</label> | ||
| <span>@Contributor.Description</span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
19 changes: 19 additions & 0 deletions
19
...ootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineContributor.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,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Samples.Tutorials; | ||
|
|
||
| /// <summary> | ||
| /// Online sheet sample code | ||
| /// </summary> | ||
| public partial class OnlineContributor | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets Contributor | ||
| /// </summary> | ||
| [Parameter] | ||
| [NotNull] | ||
| public Contributor? Contributor { get; set; } | ||
| } |
10 changes: 10 additions & 0 deletions
10
...otstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineContributor.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,10 @@ | ||
| .bb-contributor { | ||
| display: flex; | ||
| flex-direction: row; | ||
| } | ||
|
|
||
| .bb-contributor img { | ||
| border-radius: 50%; | ||
| width: 56px; | ||
| margin-right: .5rem; | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineSheet.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,6 @@ | ||
| @namespace BootstrapBlazor.Server.Components.Samples.Tutorials | ||
| @page "/tutorials/online-sheet" | ||
|
|
||
| <div class="bb-online-sheet-demo"> | ||
| <UniverSheet @ref="_sheetExcel" Data="@_data" OnReadyAsync="OnReadyAsync"></UniverSheet> | ||
| </div> |
103 changes: 103 additions & 0 deletions
103
src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineSheet.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,103 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Samples.Tutorials; | ||
|
|
||
| /// <summary> | ||
| /// Online sheet sample code | ||
| /// </summary> | ||
| public partial class OnlineSheet : ComponentBase, IDisposable | ||
| { | ||
| [Inject, NotNull] | ||
| private IWebHostEnvironment? WebHost { get; set; } | ||
|
|
||
| [Inject, NotNull] | ||
| private ToastService? ToastService { get; set; } | ||
|
|
||
| [Inject, NotNull] | ||
| private IStringLocalizer<OnlineSheet>? Localizer { get; set; } | ||
|
|
||
| [Inject] | ||
| [NotNull] | ||
| private IDispatchService<Contributor>? DispatchService { get; set; } | ||
|
|
||
| [NotNull] | ||
| private UniverSheet? _sheetExcel = null; | ||
|
|
||
| private UniverSheetData? _data = null; | ||
|
|
||
| private bool _inited = false; | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| protected override void OnInitialized() | ||
| { | ||
| base.OnInitialized(); | ||
|
|
||
| var reportFile = Path.Combine(WebHost.WebRootPath, "univer-sheet", "report.json"); | ||
| if (File.Exists(reportFile)) | ||
| { | ||
| var sheetData = File.ReadAllText(reportFile); | ||
|
|
||
| _data = new UniverSheetData() | ||
| { | ||
| Data = sheetData | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| private async Task OnReadyAsync() | ||
| { | ||
| _inited = true; | ||
| await ToastService.Information(Localizer["ToastOnReadyTitle"], Localizer["ToastOnReadyContent"]); | ||
| DispatchService.Subscribe(Dispatch); | ||
| } | ||
|
|
||
| private async Task Dispatch(DispatchEntry<Contributor> entry) | ||
| { | ||
| if (!_inited) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (entry.Entry != null) | ||
| { | ||
| await ToastService.Show(new ToastOption() | ||
| { | ||
| Title = "Dispatch 服务测试", | ||
| ChildContent = BootstrapDynamicComponent.CreateComponent<OnlineContributor>(new Dictionary<string, object?>() | ||
| { | ||
| { "Contributor", entry.Entry } | ||
| }).Render(), | ||
| Category = ToastCategory.Information, | ||
| Delay = 3000, | ||
| ForceDelay = true | ||
| }); | ||
|
|
||
| DispatchService.UnSubscribe(Dispatch); | ||
|
|
||
| await _sheetExcel.PushDataAsync(entry.Entry.Data); | ||
| } | ||
| } | ||
|
|
||
| private void Dispose(bool disposing) | ||
| { | ||
| if (disposing) | ||
| { | ||
| DispatchService.UnSubscribe(Dispatch); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| public void Dispose() | ||
| { | ||
| Dispose(true); | ||
| GC.SuppressFinalize(this); | ||
| } | ||
| } | ||
|
|
||
4 changes: 4 additions & 0 deletions
4
src/BootstrapBlazor.Server/Components/Samples/Tutorials/OnlineSheet/OnlineSheet.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,4 @@ | ||
| .bb-online-sheet-demo { | ||
| margin: -1rem; | ||
| height: calc(100vh - var(--bs-header-height)); | ||
| } |
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
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
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
71 changes: 71 additions & 0 deletions
71
src/BootstrapBlazor.Server/Services/MockOnlineContributor.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,71 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| using Longbow.Tasks; | ||
|
|
||
| namespace BootstrapBlazor.Server.Services; | ||
|
|
||
| class MockOnlineContributor(IDispatchService<Contributor> dispatchService) : BackgroundService | ||
ArgoZhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| /// <summary> | ||
| /// 运行任务 | ||
| /// </summary> | ||
| /// <param name="stoppingToken"></param> | ||
| /// <returns></returns> | ||
| protected override Task ExecuteAsync(CancellationToken stoppingToken) | ||
| { | ||
| TaskServicesManager.GetOrAdd("OnlineSheet", (provider, token) => | ||
| { | ||
| dispatchService.Dispatch(new DispatchEntry<Contributor>() | ||
| { | ||
| Name = "OnlineSheet-Demo", | ||
| Entry = new Contributor() | ||
| { | ||
| Name = "Argo Zhang", | ||
| Avatar = "/images/Argo-C.png", | ||
| Description = "正在更新单元格 A8", | ||
| Data = new UniverSheetData() | ||
| { | ||
| CommandName = "UpdateRange", | ||
| Data = new | ||
| { | ||
| Range = "A8", | ||
| Value = $"{DateTime.Now: yyyy-MM-dd HH:mm:ss} Argo 更新此单元格" | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| return Task.CompletedTask; | ||
| }, TriggerBuilder.Build(Cron.Secondly(5))); | ||
|
|
||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Contributor | ||
| /// </summary> | ||
| public class Contributor | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets Name | ||
| /// </summary> | ||
| public string? Name { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets Avatar | ||
| /// </summary> | ||
| public string? Avatar { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets Description | ||
| /// </summary> | ||
| public string? Description { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets Sheet data | ||
| /// </summary> | ||
| public UniverSheetData? Data { get; set; } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.