Add query support
This commit is contained in:
parent
c3ea0b0766
commit
786e20bf3a
|
@ -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>
|
||||
|
|
|
@ -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);
|
|
@ -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:") {
|
||||
|
|
|
@ -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; }
|
||||
|
|
Loading…
Reference in New Issue