Add titles to ElementResults

This commit is contained in:
Frank A. Krueger 2017-11-15 22:20:09 -06:00
parent 3a7b01e747
commit 83fceb7ed1
3 changed files with 12 additions and 9 deletions

View File

@ -7,11 +7,13 @@ namespace Ooui.AspNetCore
{
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)
@ -20,10 +22,11 @@ namespace Ooui.AspNetCore
response.StatusCode = 200;
response.ContentType = "text/html; charset=utf-8";
var sessionId = WebSocketHandler.BeginSession (context.HttpContext, element);
var html = Encoding.UTF8.GetBytes (UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId));
response.ContentLength = html.Length;
var html = UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId, title: title);
var htmlBytes = Encoding.UTF8.GetBytes (html);
response.ContentLength = htmlBytes.Length;
using (var s = response.Body) {
await s.WriteAsync (html, 0, html.Length).ConfigureAwait (false);
await s.WriteAsync (htmlBytes, 0, htmlBytes.Length).ConfigureAwait (false);
}
}
}

View File

@ -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

View File

@ -51,7 +51,7 @@ namespace AspNetCoreMvc.Controllers
if (s == null)
return NotFound ();
return new ElementResult (s.CreateElement ());
return new ElementResult (s.CreateElement (), title: s.Title + " - Ooui Samples");
}
}
}