Add query support

This commit is contained in:
Mike Nolan 2024-03-26 12:45:36 -05:00
parent c3ea0b0766
commit 786e20bf3a
4 changed files with 21 additions and 7 deletions

View File

@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Ooui\Ooui.csproj" />
<ItemGroup>
<ProjectReference Include="..\Ooui\Ooui.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
<ItemGroup>
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -9,5 +9,17 @@ btn.Click += (sender,e)=>{
btn.Text = $"Clicked {++i} time(s)";
};
ui.Publish("/",btn);
ui.Publish("/query",(ctx)=>{
Ooui.List list=new List();
foreach(var item in ctx.QueryParams)
{
foreach(var v in item.Value)
{
Ooui.ListItem listItem=new ListItem();
listItem.Text = $"{item.Key}: {v}";
list.AppendChild(listItem);
}
}
return list;
});
ui.StartServer(45252);

View File

@ -125,7 +125,7 @@ function connectWebSocket() {
saveSize (initialSize);
var wsArgs = (rootElementPath.indexOf("?") >= 0 ? "&" : "?") +
"w=" + initialSize.width + "&h=" + initialSize.height;
"w=" + initialSize.width + "&h=" + initialSize.height + window.location.search.replace('?','&');
var proto = "ws";
if (location.protocol == "https:") {

View File

@ -489,6 +489,7 @@ namespace Ooui
bool disposeElementWhenDone = true;
try {
var context = UIContext.ForListenerContext (listenerContext, variables);
context.QueryParams = listenerContext.QueryParams;
element = elementHandler.GetElement (context);
disposeElementWhenDone = elementHandler.DisposeElementWhenDone;
@ -609,6 +610,7 @@ namespace Ooui
public class UIContext
{
public Dictionary<string,List<string>> QueryParams {get;set;}=new Dictionary<string, List<string>>();
readonly Dictionary<string, string> variables = new Dictionary<string, string> ();
public string RequestUrl { get; }