Add titles to ElementResults
This commit is contained in:
parent
3a7b01e747
commit
83fceb7ed1
|
@ -7,11 +7,13 @@ namespace Ooui.AspNetCore
|
||||||
{
|
{
|
||||||
public class ElementResult : ActionResult
|
public class ElementResult : ActionResult
|
||||||
{
|
{
|
||||||
readonly Element element;
|
readonly Element element;
|
||||||
|
readonly string title;
|
||||||
|
|
||||||
public ElementResult (Element element)
|
public ElementResult (Element element, string title = "")
|
||||||
{
|
{
|
||||||
this.element = element;
|
this.element = element;
|
||||||
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task ExecuteResultAsync (ActionContext context)
|
public override async Task ExecuteResultAsync (ActionContext context)
|
||||||
|
@ -20,10 +22,11 @@ namespace Ooui.AspNetCore
|
||||||
response.StatusCode = 200;
|
response.StatusCode = 200;
|
||||||
response.ContentType = "text/html; charset=utf-8";
|
response.ContentType = "text/html; charset=utf-8";
|
||||||
var sessionId = WebSocketHandler.BeginSession (context.HttpContext, element);
|
var sessionId = WebSocketHandler.BeginSession (context.HttpContext, element);
|
||||||
var html = Encoding.UTF8.GetBytes (UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId));
|
var html = UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId, title: title);
|
||||||
response.ContentLength = html.Length;
|
var htmlBytes = Encoding.UTF8.GetBytes (html);
|
||||||
|
response.ContentLength = htmlBytes.Length;
|
||||||
using (var s = response.Body) {
|
using (var s = response.Body) {
|
||||||
await s.WriteAsync (html, 0, html.Length).ConfigureAwait (false);
|
await s.WriteAsync (htmlBytes, 0, htmlBytes.Length).ConfigureAwait (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,9 +299,9 @@ namespace Ooui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string RenderTemplate (string webSocketPath)
|
public static string RenderTemplate (string webSocketPath, string title = "")
|
||||||
{
|
{
|
||||||
return Template.Replace ("@WebSocketPath", webSocketPath).Replace ("@Styles", rules.ToString ());
|
return Template.Replace ("@WebSocketPath", webSocketPath).Replace ("@Styles", rules.ToString ()).Replace ("@Title", title);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataHandler : RequestHandler
|
class DataHandler : RequestHandler
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace AspNetCoreMvc.Controllers
|
||||||
if (s == null)
|
if (s == null)
|
||||||
return NotFound ();
|
return NotFound ();
|
||||||
|
|
||||||
return new ElementResult (s.CreateElement ());
|
return new ElementResult (s.CreateElement (), title: s.Title + " - Ooui Samples");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue