From 037ee04fe6d2ed285abb9cf779754682953f62c6 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 20 Mar 2025 18:50:37 -0400 Subject: [PATCH] misc updates --- src/lib/MBS.Web/UI/WebControl.cs | 11 +++- src/lib/MBS.Web/UI/WebControls/CommandBar.cs | 55 ++++++++++++++++++++ src/lib/MBS.Web/UI/WebPage.cs | 8 ++- src/lib/MBS.Web/WebServer.cs | 6 +++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/lib/MBS.Web/UI/WebControls/CommandBar.cs diff --git a/src/lib/MBS.Web/UI/WebControl.cs b/src/lib/MBS.Web/UI/WebControl.cs index b260877..749e0c5 100644 --- a/src/lib/MBS.Web/UI/WebControl.cs +++ b/src/lib/MBS.Web/UI/WebControl.cs @@ -17,7 +17,7 @@ public abstract class WebControl : Control return _NanoId.ToString(); } } - public string ClientId { get { return String.Format("UWT{0}", NanoIdString); } } + public string ClientId { get; set; } = ""; public ThemeColorPreset ThemeColorPreset { get; set;} = ThemeColorPreset.Unspecified; protected override IEnumerable GetStyleClasses() @@ -39,7 +39,14 @@ public abstract class WebControl : Control protected override IDictionary GetControlAttributes() { IDictionary dict = base.GetControlAttributes(); - dict["id"] = ClientId; + if (String.IsNullOrEmpty(ClientId)) + { + dict["id"] = String.Format("UWT{0}", NanoIdString); + } + else + { + dict["id"] = ClientId; + } return dict; } } \ No newline at end of file diff --git a/src/lib/MBS.Web/UI/WebControls/CommandBar.cs b/src/lib/MBS.Web/UI/WebControls/CommandBar.cs new file mode 100644 index 0000000..fa762ba --- /dev/null +++ b/src/lib/MBS.Web/UI/WebControls/CommandBar.cs @@ -0,0 +1,55 @@ +// Copyright (C) 2024 Michael Becker +// +// This file is part of editor-dotnet. +// +// editor-dotnet is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// editor-dotnet is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with editor-dotnet. If not, see . + + + +using System.Xml; +using MBS.Core; + +namespace MBS.Web.UI.WebControls; + +public class CommandBar : Container +{ + + protected override string TagName => "ul"; + protected override IEnumerable GetStyleClasses() + { + return new string[] { "uwt-commandbar" }; + } + + public List Items { get; } = new List(); + + protected override IList GetChildControls() + { + IList list = base.GetChildControls(); + foreach (CommandItem item in Items) + { + if (item is CommandReferenceCommandItem crci) + { + Command? cmd = Application.Instance?.Commands[crci.CommandID]; + if (cmd != null) + { + Button btn = new Button(); + btn.ClientId = String.Format("{0}-item{1}", ClientId, Items.IndexOf(item)); + btn.Text = cmd.Title; + list.Add(btn); + } + } + } + return list; + } +} \ No newline at end of file diff --git a/src/lib/MBS.Web/UI/WebPage.cs b/src/lib/MBS.Web/UI/WebPage.cs index 6700641..7c250c6 100644 --- a/src/lib/MBS.Web/UI/WebPage.cs +++ b/src/lib/MBS.Web/UI/WebPage.cs @@ -42,6 +42,11 @@ public class WebPage : Control return new Control[0]; } + protected virtual IEnumerable GetBodyControls() + { + return Controls; + } + protected override string TagName => "html"; protected override void RenderBeginTag(XmlWriter writer) { @@ -107,7 +112,8 @@ public class WebPage : Control protected override void RenderContents(XmlWriter writer) { - foreach (Control control in Controls) + IEnumerable ctls = GetBodyControls(); + foreach (Control control in ctls) { control.Context = Context; control.Render(writer); diff --git a/src/lib/MBS.Web/WebServer.cs b/src/lib/MBS.Web/WebServer.cs index 00011a6..fdfd8a1 100644 --- a/src/lib/MBS.Web/WebServer.cs +++ b/src/lib/MBS.Web/WebServer.cs @@ -338,6 +338,12 @@ public class WebServer return CoalesceVariables(right.PathTemplate).Length.CompareTo(CoalesceVariables(left.PathTemplate).Length); })); + int iq = path.IndexOf('?'); + if (iq > -1) + { + path = path.Substring(0, iq); + } + foreach (WebRoute route in sortedRoutes) { // !!! FIXME !!! /super/d/~/super/d/login.htmld/... falsely maps to ~/{tenant} route