Beispiel #1
0
        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;
        }
Beispiel #2
0
 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
     );
 }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        public virtual async Task <PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar)
        {
            if (toolbar == null || !toolbar.Contributors.Any())
            {
                return(Array.Empty <PageToolbarItem>());
            }

            using (var scope = ServiceScopeFactory.CreateScope())
            {
                var context = new PageToolbarContributionContext(scope.ServiceProvider);

                foreach (var contributor in toolbar.Contributors)
                {
                    await contributor.ContributeAsync(context);
                }

                return(context.Items.OrderBy(i => i.Order).ToArray());
            }
        }