Browse Source

Merge pull request #19453 from abpframework/IBlockUiService

Add `IBlockUiService` for blazor.
pull/19455/head
Enis Necipoglu 2 years ago
committed by GitHub
parent
commit
ce49746c7c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 38
      docs/en/UI/Blazor/Block-Busy.md
  2. 4
      docs/en/docs-nav.json
  3. 2
      framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Theming/ComponentsComponentsBundleContributor.cs
  4. 1
      framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalStyleContributor.cs
  5. 27
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/BlockUi/AbpBlockUiService.cs
  6. 56
      framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/css/abp.css
  7. 48
      framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js
  8. 1
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ComponentsComponentsBundleContributor.cs
  9. 10
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/BlockUi/IBlockUiService.cs
  10. 17
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/BlockUi/NullBlockUiService.cs
  11. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Client/wwwroot/global.css
  12. 2
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Client/wwwroot/global.js
  13. 4
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/Components/App.razor
  14. 1
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/wwwroot/global.css
  15. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/wwwroot/global.js
  16. 1
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Client/wwwroot/global.css
  17. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Client/wwwroot/global.js
  18. 1
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Tiered.Client/wwwroot/global.css
  19. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Tiered.Client/wwwroot/global.js
  20. 4
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/App.razor
  21. 1
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host.Client/wwwroot/global.css
  22. 2
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host.Client/wwwroot/global.js
  23. 4
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/App.razor

38
docs/en/UI/Blazor/Block-Busy.md

@ -0,0 +1,38 @@
# Blazor UI: Block/Busy Service
UI Block disables (blocks) the page or a part of the page.
## Quick Example
Simply [inject](../../Dependency-Injection.md) `IBlockUiService` to your page or component and call the `Block/UnBlock` method to disables (blocks) the element.
```csharp
namespace MyProject.Blazor.Pages
{
public partial class Index
{
private readonly IBlockUiService _blockUiService;
public Index(IBlockUiService _blockUiService)
{
_blockUiService = blockUiService;
}
public async Task BlockForm()
{
/*
Parameters of Block method:
selectors: A string containing one or more selectors to match. https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector#selectors
busy : Set to true to show a progress indicator on the blocked area.
*/
await _blockUiService.Block(selectors: "#MySelectors", busy: true);
}
}
}
```
The resulting UI will look like below:
![ui-busy](../../images/ui-busy.png)
Then you can use `_blockUiService.UnBlock()` to re-enable the busy area/page.

4
docs/en/docs-nav.json

@ -958,6 +958,10 @@
{
"text": "Page Progress",
"path": "UI/Blazor/Page-Progress.md"
},
{
"text": "Block/Busy",
"path": "UI/Blazor/Block-Busy.md"
}
]
},

2
framework/src/Volo.Abp.AspNetCore.Components.MauiBlazor.Theming/ComponentsComponentsBundleContributor.cs

@ -23,7 +23,7 @@ public class ComponentsComponentsBundleContributor : IBundleContributor
Source = "_content/Volo.Abp.AspNetCore.Components.MauiBlazor.Theming/libs/fontawesome/css/all.css"
});
}
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/css/abp.css");
context.Add("_content/Volo.Abp.AspNetCore.Components.MauiBlazor.Theming/libs/flag-icon/css/flag-icon.css");
context.Add("_content/Blazorise/blazorise.css");
context.Add("_content/Blazorise.Bootstrap5/blazorise.bootstrap5.css");

1
framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalStyleContributor.cs

@ -14,6 +14,7 @@ public class BlazorGlobalStyleContributor : BundleContributor
{
public override void ConfigureBundle(BundleConfigurationContext context)
{
context.Files.AddIfNotContains("/_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/css/abp.css");
context.Files.AddIfNotContains("/_content/Blazorise/blazorise.css");
context.Files.AddIfNotContains("/_content/Blazorise.Bootstrap5/blazorise.bootstrap5.css");
context.Files.AddIfNotContains("/_content/Blazorise.Snackbar/blazorise.snackbar.css");

27
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/BlockUi/AbpBlockUiService.cs

@ -0,0 +1,27 @@
using System.Threading.Tasks;
using Microsoft.JSInterop;
using Volo.Abp.AspNetCore.Components.BlockUi;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.BlockUi;
[Dependency(ReplaceServices = true)]
public class AbpBlockUiService : IBlockUiService, IScopedDependency
{
public IJSRuntime JsRuntime { get; }
public AbpBlockUiService(IJSRuntime jsRuntime)
{
JsRuntime = jsRuntime;
}
public async Task Block(string? selectors, bool busy = false)
{
await JsRuntime.InvokeVoidAsync("abp.ui.block", selectors, busy);
}
public async Task UnBlock()
{
await JsRuntime.InvokeVoidAsync("abp.ui.unblock");
}
}

56
framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/css/abp.css

@ -0,0 +1,56 @@
@keyframes spin {
0% {
transform: translateZ(0) rotate(0deg);
}
100% {
transform: translateZ(0) rotate(360deg);
}
}
.abp-block-area {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 102;
background-color: #fff !important;
opacity: .8;
transition: opacity .25s;
}
.abp-block-area.abp-block-area-disappearing {
opacity: 0;
}
.abp-block-area.abp-block-area-busy:after {
content: attr(data-text);
display: block;
max-width: 125px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 20px;
font-family: sans-serif;
color: #343a40;
text-align: center;
text-transform: uppercase;
}
.abp-block-area.abp-block-area-busy:before {
content: "";
display: block;
width: 150px;
height: 150px;
border-radius: 50%;
border-width: 2px;
border-style: solid;
border-color: transparent #228ae6 #228ae6 #228ae6;
position: absolute;
top: calc(50% - 75px);
left: calc(50% - 75px);
will-change: transform;
animation: spin .75s infinite ease-in-out;
}

48
framework/src/Volo.Abp.AspNetCore.Components.Web/wwwroot/libs/abp/js/abp.js

@ -182,4 +182,52 @@ var abp = abp || {};
}
}
}
/* UI *******************************************************/
abp.ui = abp.ui || {};
/* UI BLOCK */
//Defines UI Block API and implements basically
var $abpBlockArea = document.createElement('div');
$abpBlockArea.classList.add('abp-block-area');
/* opts: { //Can be an object with options or a string for query a selector
* elm: a query selector (optional - default: document.body)
* busy: boolean (optional - default: false)
* }
*/
abp.ui.block = function (elm, busy) {
var $elm = document.querySelector(elm) || document.body;
if (busy) {
$abpBlockArea.classList.add('abp-block-area-busy');
} else {
$abpBlockArea.classList.remove('abp-block-area-busy');
}
if (document.querySelector(elm)) {
$abpBlockArea.style.position = 'absolute';
} else {
$abpBlockArea.style.position = 'fixed';
}
$elm.appendChild($abpBlockArea);
};
abp.ui.unblock = function () {
var element = document.querySelector('.abp-block-area');
if (element) {
element.classList.add('abp-block-area-disappearing');
setTimeout(function () {
if (element) {
element.classList.remove('abp-block-area-disappearing');
if (element.parentElement) {
element.parentElement.removeChild(element);
}
}
}, 250);
}
};
})();

1
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ComponentsComponentsBundleContributor.cs

@ -25,6 +25,7 @@ public class ComponentsComponentsBundleContributor : IBundleContributor
});
}
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/css/abp.css");
context.Add("_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/flag-icon/css/flag-icon.css");
context.Add("_content/Blazorise/blazorise.css");
context.Add("_content/Blazorise.Bootstrap5/blazorise.bootstrap5.css");

10
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/BlockUi/IBlockUiService.cs

@ -0,0 +1,10 @@
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.BlockUi;
public interface IBlockUiService
{
Task Block(string? selectors, bool busy = false);
Task UnBlock();
}

17
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/BlockUi/NullBlockUiService.cs

@ -0,0 +1,17 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.BlockUi;
public class NullBlockUiService : IBlockUiService, ISingletonDependency
{
public Task Block(string? selectors, bool busy = false)
{
return Task.CompletedTask;
}
public Task UnBlock()
{
return Task.CompletedTask;
}
}

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Client/wwwroot/global.css

File diff suppressed because one or more lines are too long

2
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Client/wwwroot/global.js

File diff suppressed because one or more lines are too long

4
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/Components/App.razor

@ -9,7 +9,7 @@
<base href="/" />
<!--ABP:Styles-->
<link href="global.css?_v=638472371837228870" rel="stylesheet"/>
<link href="global.css?_v=638473198173942238" rel="stylesheet"/>
<link href="main.css" rel="stylesheet"/>
<!--/ABP:Styles-->
<link href="MyCompanyName.MyProjectName.Blazor.styles.css" rel="stylesheet"/>
@ -37,7 +37,7 @@
</div>
<!--ABP:Scripts-->
<script src="global.js?_v=638472371838439398"></script>
<script src="global.js?_v=638473198175165417"></script>
<!--/ABP:Scripts-->
</body>

1
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/wwwroot/global.css

File diff suppressed because one or more lines are too long

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/wwwroot/global.js

File diff suppressed because one or more lines are too long

1
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Client/wwwroot/global.css

File diff suppressed because one or more lines are too long

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Client/wwwroot/global.js

File diff suppressed because one or more lines are too long

1
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Tiered.Client/wwwroot/global.css

File diff suppressed because one or more lines are too long

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.WebApp.Tiered.Client/wwwroot/global.js

File diff suppressed because one or more lines are too long

4
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/App.razor

@ -8,7 +8,7 @@
<base href="/" />
<!--ABP:Styles-->
<link href="global.css?_v=638472371105418474" rel="stylesheet"/>
<link href="global.css?_v=638473199568040519" rel="stylesheet"/>
<link href="main.css" rel="stylesheet"/>
<!--/ABP:Styles-->
<link href="MyCompanyName.MyProjectName.Blazor.Client.styles.css" rel="stylesheet"/>
@ -36,7 +36,7 @@
</div>
<!--ABP:Scripts-->
<script src="global.js?_v=638472371106655051"></script>
<script src="global.js?_v=638473199570937070"></script>
<!--/ABP:Scripts-->
<!-- <TEMPLATE-REMOVE IF-NOT='PWA'> -->

1
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host.Client/wwwroot/global.css

File diff suppressed because one or more lines are too long

2
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host.Client/wwwroot/global.js

File diff suppressed because one or more lines are too long

4
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/App.razor

@ -8,7 +8,7 @@
<base href="/" />
<!--ABP:Styles-->
<link href="global.css?_v=638472371674955462" rel="stylesheet"/>
<link href="global.css?_v=638473199135168410" rel="stylesheet"/>
<link href="main.css" rel="stylesheet"/>
<!--/ABP:Styles-->
<link href="MyCompanyName.MyProjectName.Blazor.Host.Client.styles.css" rel="stylesheet"/>
@ -30,7 +30,7 @@
</div>
<!--ABP:Scripts-->
<script src="global.js?_v=638472371675508116"></script>
<script src="global.js?_v=638473199135794271"></script>
<!--/ABP:Scripts-->
</body>

Loading…
Cancel
Save