Commit 73949a41 authored by Savorboard's avatar Savorboard

Improve dashboard

parent d101c75c
...@@ -652,4 +652,5 @@ $(function() { ...@@ -652,4 +652,5 @@ $(function() {
function nodeSwitch(id) { function nodeSwitch(id) {
console.log(`id:${id}`); console.log(`id:${id}`);
document.cookie = `cap.node=${escape(id)};`; document.cookie = `cap.node=${escape(id)};`;
window.location.reload();
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
...@@ -11,6 +12,7 @@ namespace DotNetCore.CAP.Dashboard ...@@ -11,6 +12,7 @@ namespace DotNetCore.CAP.Dashboard
public abstract class DashboardRequest public abstract class DashboardRequest
{ {
public abstract string Method { get; } public abstract string Method { get; }
public abstract Dictionary<string, string> Cookies { get; }
public abstract string Path { get; } public abstract string Path { get; }
public abstract string PathBase { get; } public abstract string PathBase { get; }
...@@ -28,10 +30,11 @@ namespace DotNetCore.CAP.Dashboard ...@@ -28,10 +30,11 @@ namespace DotNetCore.CAP.Dashboard
public CapDashboardRequest(HttpContext context) public CapDashboardRequest(HttpContext context)
{ {
_context = context ?? throw new ArgumentNullException(nameof(context)); _context = context ?? throw new ArgumentNullException(nameof(context));
} }
public override string Method => _context.Request.Method; public override string Method => _context.Request.Method;
public override Dictionary<string, string> Cookies => _context.Request.Cookies.ToDictionary(x => x.Key, v => v.Value);
public override string Path => _context.Request.Path.Value; public override string Path => _context.Request.Path.Value;
public override string PathBase => _context.Request.PathBase.Value; public override string PathBase => _context.Request.PathBase.Value;
public override string LocalIpAddress => _context.Connection.LocalIpAddress.MapToIPv4().ToString(); public override string LocalIpAddress => _context.Connection.LocalIpAddress.MapToIPv4().ToString();
......
...@@ -119,16 +119,20 @@ namespace DotNetCore.CAP.Dashboard ...@@ -119,16 +119,20 @@ namespace DotNetCore.CAP.Dashboard
Routes.AddRazorPage( Routes.AddRazorPage(
"/published/(?<StatusName>.+)", "/published/(?<StatusName>.+)",
x => new PublishedPage(x.Groups["StatusName"].Value)); x => new PublishedPage(x.UriMatch.Groups["StatusName"].Value));
Routes.AddRazorPage( Routes.AddRazorPage(
"/received/(?<StatusName>.+)", "/received/(?<StatusName>.+)",
x => new ReceivedPage(x.Groups["StatusName"].Value)); x => new ReceivedPage(x.UriMatch.Groups["StatusName"].Value));
Routes.AddRazorPage("/subscribers", x => new SubscriberPage()); Routes.AddRazorPage("/subscribers", x => new SubscriberPage());
Routes.AddRazorPage("/nodes", x =>
{
var id = x.Request.Cookies["cap.node"];
return new NodePage(id);
});
Routes.AddRazorPage("/nodes", x => new NodePage()); Routes.AddRazorPage("/nodes/node/(?<Id>.+)", x => new NodePage(x.UriMatch.Groups["Id"].Value));
Routes.AddRazorPage("/nodes/node/(?<Id>.+)", x => new NodePage(x.Groups["Id"].Value));
#endregion Razor pages and commands #endregion Razor pages and commands
} }
......
...@@ -9,9 +9,9 @@ namespace DotNetCore.CAP.Dashboard ...@@ -9,9 +9,9 @@ namespace DotNetCore.CAP.Dashboard
{ {
internal class RazorPageDispatcher : IDashboardDispatcher internal class RazorPageDispatcher : IDashboardDispatcher
{ {
private readonly Func<Match, RazorPage> _pageFunc; private readonly Func<DashboardContext, RazorPage> _pageFunc;
public RazorPageDispatcher(Func<Match, RazorPage> pageFunc) public RazorPageDispatcher(Func<DashboardContext, RazorPage> pageFunc)
{ {
_pageFunc = pageFunc; _pageFunc = pageFunc;
} }
...@@ -20,7 +20,7 @@ namespace DotNetCore.CAP.Dashboard ...@@ -20,7 +20,7 @@ namespace DotNetCore.CAP.Dashboard
{ {
context.Response.ContentType = "text/html"; context.Response.ContentType = "text/html";
var page = _pageFunc(context.UriMatch); var page = _pageFunc(context);
page.Assign(context); page.Assign(context);
return context.Response.WriteAsync(page.ToString()); return context.Response.WriteAsync(page.ToString());
......
...@@ -11,7 +11,7 @@ namespace DotNetCore.CAP.Dashboard ...@@ -11,7 +11,7 @@ namespace DotNetCore.CAP.Dashboard
public static void AddRazorPage( public static void AddRazorPage(
this RouteCollection routes, this RouteCollection routes,
string pathTemplate, string pathTemplate,
Func<Match, RazorPage> pageFunc) Func<DashboardContext, RazorPage> pageFunc)
{ {
if (routes == null) if (routes == null)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment