Add query support
This commit is contained in:
parent
c3ea0b0766
commit
786e20bf3a
|
@ -1,16 +1,16 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ooui\Ooui.csproj" />
|
<ProjectReference Include="..\Ooui\Ooui.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
|
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
@ -9,5 +9,17 @@ btn.Click += (sender,e)=>{
|
||||||
btn.Text = $"Clicked {++i} time(s)";
|
btn.Text = $"Clicked {++i} time(s)";
|
||||||
};
|
};
|
||||||
ui.Publish("/",btn);
|
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);
|
ui.StartServer(45252);
|
|
@ -125,7 +125,7 @@ function connectWebSocket() {
|
||||||
saveSize (initialSize);
|
saveSize (initialSize);
|
||||||
|
|
||||||
var wsArgs = (rootElementPath.indexOf("?") >= 0 ? "&" : "?") +
|
var wsArgs = (rootElementPath.indexOf("?") >= 0 ? "&" : "?") +
|
||||||
"w=" + initialSize.width + "&h=" + initialSize.height;
|
"w=" + initialSize.width + "&h=" + initialSize.height + window.location.search.replace('?','&');
|
||||||
|
|
||||||
var proto = "ws";
|
var proto = "ws";
|
||||||
if (location.protocol == "https:") {
|
if (location.protocol == "https:") {
|
||||||
|
|
|
@ -489,6 +489,7 @@ namespace Ooui
|
||||||
bool disposeElementWhenDone = true;
|
bool disposeElementWhenDone = true;
|
||||||
try {
|
try {
|
||||||
var context = UIContext.ForListenerContext (listenerContext, variables);
|
var context = UIContext.ForListenerContext (listenerContext, variables);
|
||||||
|
context.QueryParams = listenerContext.QueryParams;
|
||||||
element = elementHandler.GetElement (context);
|
element = elementHandler.GetElement (context);
|
||||||
disposeElementWhenDone = elementHandler.DisposeElementWhenDone;
|
disposeElementWhenDone = elementHandler.DisposeElementWhenDone;
|
||||||
|
|
||||||
|
@ -609,6 +610,7 @@ namespace Ooui
|
||||||
|
|
||||||
public class UIContext
|
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> ();
|
readonly Dictionary<string, string> variables = new Dictionary<string, string> ();
|
||||||
|
|
||||||
public string RequestUrl { get; }
|
public string RequestUrl { get; }
|
||||||
|
|
Loading…
Reference in New Issue