Skip to content

Commit

Permalink
Implements #440
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Jan 11, 2019
1 parent 9d13426 commit 14468d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
16 changes: 5 additions & 11 deletions src/UniversalDashboard/Cmdlets/Invoke-UDRedirect.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
using Newtonsoft.Json;
using NLog;
using UniversalDashboard.Models;
using System.Management.Automation;
using UniversalDashboard.Models.Enums;
using UniversalDashboard.Models.Basics;
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using Microsoft.AspNetCore.SignalR;
using System.Security.Claims;
using Microsoft.Extensions.Caching.Memory;

namespace UniversalDashboard.Cmdlets
{
[Cmdlet(VerbsLifecycle.Invoke, "UDRedirect")]
[Cmdlet(VerbsLifecycle.Invoke, "UDRedirect")]
public class InvokeRedirectCommand : PSCmdlet
{
private readonly Logger Log = LogManager.GetLogger(nameof(InvokeRedirectCommand));

[Parameter(Mandatory = true)]
public string Url { get; set; }

[Parameter]
public SwitchParameter OpenInNewWindow { get; set; }

protected override void EndProcessing()
{
var hub = this.GetVariableValue("DashboardHub") as IHubContext<DashboardHub>;
var connectionId = this.GetVariableValue("ConnectionId") as string;
hub.Redirect(connectionId, Url).Wait();
hub.Redirect(connectionId, Url, OpenInNewWindow.IsPresent).Wait();
}
}
}
4 changes: 2 additions & 2 deletions src/UniversalDashboard/Server/DashboardHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public static async Task RequestState(this IHubContext<DashboardHub> hub, string
await hub.Clients.Client(clientId).SendAsync("requestState", componentId, requestId);
}

public static async Task Redirect(this IHubContext<DashboardHub> hub, string clientId, string url)
public static async Task Redirect(this IHubContext<DashboardHub> hub, string clientId, string url, bool newWindow)
{
await hub.Clients.Client(clientId).SendAsync("redirect", url);
await hub.Clients.Client(clientId).SendAsync("redirect", url, newWindow);
}

public static async Task SetState(this IHubContext<DashboardHub> hub, string componentId, Element state)
Expand Down
9 changes: 7 additions & 2 deletions src/client/src/app/ud-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ export default class UdDashboard extends React.Component {
PubSub.publish("modal.close", {});
});

connection.on('redirect', (url) => {
window.location.href = url;
connection.on('redirect', (url, newWindow) => {
if (newWindow) {
window.open(url);
}
else {
window.location.href = url;
}
});

PubSub.subscribe('element-event', function(e, data) {
Expand Down

0 comments on commit 14468d4

Please sign in to comment.