public object Render(Blade blade)
            {
                object PrepareBody(object body)
                {
                    if (body is string strBody)
                    {
                        return(Typography.P(strBody));
                    }
                    return(body);
                }

                Controls.Button RenderButton(AlertAction action)
                {
                    return(new Controls.Button(action.Label, (_) =>
                    {
                        blade.Manager.CloseSideBlade(action);
                    }, theme: action.IsPrimary?Theme.Primary: Theme.Secondary));
                }

                var primary = RenderButton(_builder._actions.Single(e => e.IsPrimary));
                var buttons = new[] { primary }.Union(_builder._actions.Where(e => !e.IsPrimary).Select(RenderButton));

                IContentFormatter formatter = new DefaultContentFormatter();

                return(Layout.Vertical(
                           formatter.Format(PrepareBody(_builder._body)),
                           _builder._editor?.Render(primary),
                           Layout.Horizontal(buttons)
                           ));
            }
 public void ShowException(Exception ex, Action <AlertAction> onClose = null)
 {
     _title = ex.GetType().Name;
     _body  = Layout.Vertical(Typography.P(ex.Message), new CollapsablePanel("Stack Trace", Typography.Code(ex.StackTrace)));
     _actions.Add(AlertAction.Ok);
     Show(onClose);
 }
Beispiel #3
0
        public async Task <object> Render()
        {
            Container?.RemoveClass("blade-hidden");
            try
            {
                var dc = new DumpContainer();

                var buttons = new List <Control>();

                if (Index != -1)
                {
                    buttons.Add(new IconButton(Icons.Refresh, (_) =>
                    {
                        Manager.PopTo(Index, true);
                    }, theme: Theme.PrimaryAlternate));
                }

                if (Index == 0 && Manager.ShowDebugButton)
                {
                    buttons.Add(new IconButton(Icons.Duck, (_) =>
                    {
                        Manager.DebugHtml();
                    }, theme: Theme.PrimaryAlternate));
                }

                if (Index != 0)
                {
                    buttons.Add(new IconButton(Icons.Close, (_) =>
                    {
                        if (Index == -1)
                        {
                            Manager.CloseSideBlade(false);
                        }
                        else
                        {
                            Manager.PopTo(Index - 1, false);
                        }
                    }, theme: Theme.PrimaryAlternate));
                }

                _titleH1 = Element("h1", null, string.IsNullOrEmpty(Title) ? " " : Title);

                var div = Div("blade-panel",
                              Div("blade-header",
                                  _titleH1,
                                  Element("aside", null, buttons.ToArray())
                                  ),
                              Div("blade-content", dc)
                              );

                await ControlExtensions.AddPadding(dc, Renderer.Render(this));

                return(div);
            }
            catch (Exception ex)
            {
                return(Layout.Padding(true).Vertical(
                           Typography.H2(ex.GetType().Name),
                           Typography.P(ex.Message),
                           new CollapsablePanel("Stack Trace", Typography.Code(ex.StackTrace))));
            }
        }