-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6647 from abpframework/ui-extensions-blazor
Blazor UI extensions
- Loading branch information
Showing
65 changed files
with
2,133 additions
and
253 deletions.
There are no files selected for viewing
This file contains 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 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
92 changes: 92 additions & 0 deletions
92
...olo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs
This file contains 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,92 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Linq.Dynamic.Core; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.Extensions.Primitives; | ||
using Volo.Abp.AspNetCore.Components.Web.Extensibility; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Http.Client; | ||
using Volo.Abp.Http.Client.Authentication; | ||
using Volo.Abp.MultiTenancy; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Server.Extensibility | ||
{ | ||
public class BlazorServerLookupApiRequestService : ILookupApiRequestService, ITransientDependency | ||
{ | ||
public IHttpClientFactory HttpClientFactory { get; } | ||
public IRemoteServiceHttpClientAuthenticator HttpClientAuthenticator { get; } | ||
|
||
public AbpRemoteServiceOptions RemoteServiceOptions { get; } | ||
|
||
public ICurrentTenant CurrentTenant { get; } | ||
public IHttpContextAccessor HttpContextAccessor { get; } | ||
public NavigationManager NavigationManager { get; } | ||
|
||
public BlazorServerLookupApiRequestService(IHttpClientFactory httpClientFactory, | ||
IRemoteServiceHttpClientAuthenticator httpClientAuthenticator, | ||
ICurrentTenant currentTenant, | ||
IOptions<AbpRemoteServiceOptions> remoteServiceOptions, | ||
IHttpContextAccessor httpContextAccessor, | ||
NavigationManager navigationManager) | ||
{ | ||
HttpClientFactory = httpClientFactory; | ||
HttpClientAuthenticator = httpClientAuthenticator; | ||
RemoteServiceOptions = remoteServiceOptions.Value; | ||
CurrentTenant = currentTenant; | ||
HttpContextAccessor = httpContextAccessor; | ||
NavigationManager = navigationManager; | ||
} | ||
|
||
public async Task<string> SendAsync(string url) | ||
{ | ||
var client = HttpClientFactory.CreateClient(); | ||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, url); | ||
|
||
var uri = new Uri(url, UriKind.RelativeOrAbsolute); | ||
if (!uri.IsAbsoluteUri) | ||
{ | ||
var baseUrl = string.Empty; | ||
try | ||
{ | ||
//Blazor tiered -- mode | ||
var remoteServiceConfig = RemoteServiceOptions.RemoteServices.GetConfigurationOrDefault("Default"); | ||
baseUrl = remoteServiceConfig.BaseUrl; | ||
client.BaseAddress = new Uri(baseUrl); | ||
AddHeaders(requestMessage); | ||
await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, | ||
requestMessage, new RemoteServiceConfiguration(baseUrl), string.Empty)); | ||
} | ||
catch (AbpException) // Blazor-Server mode. | ||
{ | ||
baseUrl = NavigationManager.BaseUri; | ||
client.BaseAddress = new Uri(baseUrl); | ||
foreach (var header in HttpContextAccessor.HttpContext.Request.Headers) | ||
{ | ||
requestMessage.Headers.Add(header.Key, header.Value.ToArray()); | ||
} | ||
} | ||
} | ||
|
||
var response = await client.SendAsync(requestMessage); | ||
return await response.Content.ReadAsStringAsync(); | ||
} | ||
|
||
protected virtual void AddHeaders(HttpRequestMessage requestMessage) | ||
{ | ||
if (CurrentTenant.Id.HasValue) | ||
{ | ||
requestMessage.Headers.Add(TenantResolverConsts.DefaultTenantKey, CurrentTenant.Id.Value.ToString()); | ||
} | ||
|
||
var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name; | ||
if (!currentCulture.IsNullOrEmpty()) | ||
{ | ||
requestMessage.Headers.AcceptLanguage.Add(new(currentCulture)); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
78 changes: 78 additions & 0 deletions
78
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageHeader.razor.cs
This file contains 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,78 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Components; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars; | ||
using Volo.Abp.BlazoriseUI; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Layout | ||
{ | ||
public partial class PageHeader : ComponentBase | ||
{ | ||
protected List<RenderFragment> ToolbarItemRenders { get; set; } | ||
|
||
public IPageToolbarManager PageToolbarManager { get; set; } | ||
|
||
[Parameter] | ||
public string Title { get; set; } | ||
|
||
[Parameter] | ||
public bool BreadcrumbShowHome { get; set; } = true; | ||
|
||
[Parameter] | ||
public bool BreadcrumbShowCurrent { get; set; } = true; | ||
|
||
[Parameter] | ||
public RenderFragment ChildContent { get; set; } | ||
|
||
[Parameter] | ||
public List<BreadcrumbItem> BreadcrumbItems { get; set; } | ||
|
||
[Parameter] | ||
public PageToolbar Toolbar { get; set; } | ||
|
||
[Parameter] | ||
public string PageName { get; set; } | ||
|
||
public PageHeader() | ||
{ | ||
BreadcrumbItems = new List<BreadcrumbItem>(); | ||
ToolbarItemRenders = new List<RenderFragment>(); | ||
} | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
await base.OnParametersSetAsync(); | ||
if (Toolbar!=null) | ||
{ | ||
Console.WriteLine("Toolbar is not null"); | ||
var toolbarItems = await PageToolbarManager.GetItemsAsync(Toolbar); | ||
Console.WriteLine($"Toolbar item count:{toolbarItems.Length}"); | ||
ToolbarItemRenders.Clear(); | ||
|
||
foreach (var item in toolbarItems) | ||
{ | ||
var sequence = 0; | ||
ToolbarItemRenders.Add(builder => | ||
{ | ||
builder.OpenComponent(sequence, item.ComponentType); | ||
if (item.Arguments != null) | ||
{ | ||
foreach (var argument in item.Arguments) | ||
{ | ||
sequence++; | ||
builder.AddAttribute(sequence, argument.Key, argument.Value); | ||
} | ||
} | ||
builder.CloseComponent(); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await base.OnInitializedAsync(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...rk/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/IPageToolbarContributor.cs
This file contains 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,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars | ||
{ | ||
public interface IPageToolbarContributor | ||
{ | ||
Task ContributeAsync(PageToolbarContributionContext context); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/IPageToolbarManager.cs
This file contains 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,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars | ||
{ | ||
public interface IPageToolbarManager | ||
{ | ||
Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbar.cs
This file contains 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,12 @@ | ||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars | ||
{ | ||
public class PageToolbar | ||
{ | ||
public PageToolbarContributorList Contributors { get; set; } | ||
|
||
public PageToolbar() | ||
{ | ||
Contributors = new PageToolbarContributorList(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributionContext.cs
This file contains 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,21 @@ | ||
using JetBrains.Annotations; | ||
using System; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars | ||
{ | ||
public class PageToolbarContributionContext | ||
{ | ||
[NotNull] | ||
public IServiceProvider ServiceProvider { get; } | ||
|
||
[NotNull] | ||
public PageToolbarItemList Items { get; } | ||
|
||
public PageToolbarContributionContext( | ||
[NotNull] IServiceProvider serviceProvider) | ||
{ | ||
ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider)); | ||
Items = new PageToolbarItemList(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ork/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributor.cs
This file contains 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,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars | ||
{ | ||
public abstract class PageToolbarContributor : IPageToolbarContributor | ||
{ | ||
public abstract Task ContributeAsync(PageToolbarContributionContext context); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributorList.cs
This file contains 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 System.Collections.Generic; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars | ||
{ | ||
public class PageToolbarContributorList : List<IPageToolbarContributor> | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...work/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarDictionary.cs
This file contains 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,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars | ||
{ | ||
public class PageToolbarDictionary : Dictionary<string, PageToolbar> | ||
{ | ||
|
||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...work/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarExtensions.cs
This file contains 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 @@ | ||
using Blazorise; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.BlazoriseUI.Components; | ||
using Volo.Abp.Localization; | ||
|
||
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars | ||
{ | ||
public static class PageToolbarExtensions | ||
{ | ||
public static PageToolbar AddComponent<TComponent>( | ||
this PageToolbar toolbar, | ||
Dictionary<string, object> arguments = null, | ||
int order = 0, | ||
string requiredPolicyName = null) | ||
{ | ||
return toolbar.AddComponent( | ||
typeof(TComponent), | ||
arguments, | ||
order, | ||
requiredPolicyName | ||
); | ||
} | ||
|
||
public static PageToolbar AddComponent( | ||
this PageToolbar toolbar, | ||
Type componentType, | ||
Dictionary<string, object> arguments = null, | ||
int order = 0, | ||
string requiredPolicyName = null) | ||
{ | ||
toolbar.Contributors.Add( | ||
new SimplePageToolbarContributor( | ||
componentType, | ||
arguments, | ||
order, | ||
requiredPolicyName | ||
) | ||
); | ||
|
||
return toolbar; | ||
} | ||
|
||
public static PageToolbar AddButton( | ||
this PageToolbar toolbar, | ||
string text, | ||
Func<Task> clicked, | ||
object icon = null, | ||
Color color = Color.Primary, | ||
bool disabled = false, | ||
int order = 0, | ||
string requiredPolicyName = null) | ||
{ | ||
toolbar.AddComponent<ToolbarButton>( | ||
new Dictionary<string, object> | ||
{ | ||
{ nameof(ToolbarButton.Color), color}, | ||
{ nameof(ToolbarButton.Text), text}, | ||
{ nameof(ToolbarButton.Disabled), disabled}, | ||
{ nameof(ToolbarButton.Icon), icon}, | ||
{ nameof(ToolbarButton.Clicked),clicked}, | ||
}, | ||
order, | ||
requiredPolicyName | ||
); | ||
|
||
return toolbar; | ||
} | ||
} | ||
} |
Oops, something went wrong.