public async Task ContributeAsync(PageToolbarContributionContext context) { if (await ShouldAddComponentAsync(context)) { context.Items.Add(new PageToolbarItem(ComponentType, Argument, Order)); } }
protected virtual async Task <bool> ShouldAddComponentAsync(PageToolbarContributionContext context) { if (RequiredPolicyName != null) { var authorizationService = context.ServiceProvider.GetRequiredService <IAuthorizationService>(); if (!await authorizationService.IsGrantedAsync(RequiredPolicyName)) { return(false); } } return(true); }
public virtual async Task <PageToolbarItem[]> GetItemsAsync(string pageName) { var toolbar = Options.Toolbars.GetOrDefault(pageName); if (toolbar == null || !toolbar.Contributors.Any()) { return(Array.Empty <PageToolbarItem>()); } using (var scope = ServiceScopeFactory.CreateScope()) { var context = new PageToolbarContributionContext(pageName, scope.ServiceProvider); foreach (var contributor in toolbar.Contributors) { await contributor.ContributeAsync(context); } return(context.Items.OrderBy(i => i.Order).ToArray()); } }
public abstract Task ContributeAsync(PageToolbarContributionContext context);