Skip to content

Commit 73949a4

Browse files
committed
Improve dashboard
1 parent d101c75 commit 73949a4

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

src/DotNetCore.CAP.Dashboard/Content/js/cap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,4 +652,5 @@ $(function() {
652652
function nodeSwitch(id) {
653653
console.log(`id:${id}`);
654654
document.cookie = `cap.node=${escape(id)};`;
655+
window.location.reload();
655656
}

src/DotNetCore.CAP.Dashboard/DashboardRequest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using System.Threading.Tasks;
78
using Microsoft.AspNetCore.Http;
89

@@ -11,6 +12,7 @@ namespace DotNetCore.CAP.Dashboard
1112
public abstract class DashboardRequest
1213
{
1314
public abstract string Method { get; }
15+
public abstract Dictionary<string, string> Cookies { get; }
1416
public abstract string Path { get; }
1517
public abstract string PathBase { get; }
1618

@@ -28,10 +30,11 @@ internal sealed class CapDashboardRequest : DashboardRequest
2830

2931
public CapDashboardRequest(HttpContext context)
3032
{
31-
_context = context ?? throw new ArgumentNullException(nameof(context));
33+
_context = context ?? throw new ArgumentNullException(nameof(context));
3234
}
3335

3436
public override string Method => _context.Request.Method;
37+
public override Dictionary<string, string> Cookies => _context.Request.Cookies.ToDictionary(x => x.Key, v => v.Value);
3538
public override string Path => _context.Request.Path.Value;
3639
public override string PathBase => _context.Request.PathBase.Value;
3740
public override string LocalIpAddress => _context.Connection.LocalIpAddress.MapToIPv4().ToString();

src/DotNetCore.CAP.Dashboard/DashboardRoutes.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,20 @@ static DashboardRoutes()
119119

120120
Routes.AddRazorPage(
121121
"/published/(?<StatusName>.+)",
122-
x => new PublishedPage(x.Groups["StatusName"].Value));
122+
x => new PublishedPage(x.UriMatch.Groups["StatusName"].Value));
123123
Routes.AddRazorPage(
124124
"/received/(?<StatusName>.+)",
125-
x => new ReceivedPage(x.Groups["StatusName"].Value));
125+
x => new ReceivedPage(x.UriMatch.Groups["StatusName"].Value));
126126

127127
Routes.AddRazorPage("/subscribers", x => new SubscriberPage());
128+
129+
Routes.AddRazorPage("/nodes", x =>
130+
{
131+
var id = x.Request.Cookies["cap.node"];
132+
return new NodePage(id);
133+
});
128134

129-
Routes.AddRazorPage("/nodes", x => new NodePage());
130-
131-
Routes.AddRazorPage("/nodes/node/(?<Id>.+)", x => new NodePage(x.Groups["Id"].Value));
135+
Routes.AddRazorPage("/nodes/node/(?<Id>.+)", x => new NodePage(x.UriMatch.Groups["Id"].Value));
132136

133137
#endregion Razor pages and commands
134138
}

src/DotNetCore.CAP.Dashboard/RazorPageDispatcher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace DotNetCore.CAP.Dashboard
99
{
1010
internal class RazorPageDispatcher : IDashboardDispatcher
1111
{
12-
private readonly Func<Match, RazorPage> _pageFunc;
12+
private readonly Func<DashboardContext, RazorPage> _pageFunc;
1313

14-
public RazorPageDispatcher(Func<Match, RazorPage> pageFunc)
14+
public RazorPageDispatcher(Func<DashboardContext, RazorPage> pageFunc)
1515
{
1616
_pageFunc = pageFunc;
1717
}
@@ -20,7 +20,7 @@ public Task Dispatch(DashboardContext context)
2020
{
2121
context.Response.ContentType = "text/html";
2222

23-
var page = _pageFunc(context.UriMatch);
23+
var page = _pageFunc(context);
2424
page.Assign(context);
2525

2626
return context.Response.WriteAsync(page.ToString());

src/DotNetCore.CAP.Dashboard/RouteCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class RouteCollectionExtensions
1111
public static void AddRazorPage(
1212
this RouteCollection routes,
1313
string pathTemplate,
14-
Func<Match, RazorPage> pageFunc)
14+
Func<DashboardContext, RazorPage> pageFunc)
1515
{
1616
if (routes == null)
1717
{

0 commit comments

Comments
 (0)