From 14468d4ce0ac51625f5e2d23f7144c2f663eb6e3 Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Fri, 11 Jan 2019 10:44:46 -0700 Subject: [PATCH] Implements #440 --- .../Cmdlets/Invoke-UDRedirect.cs | 16 +++++----------- src/UniversalDashboard/Server/DashboardHub.cs | 4 ++-- src/client/src/app/ud-dashboard.jsx | 9 +++++++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/UniversalDashboard/Cmdlets/Invoke-UDRedirect.cs b/src/UniversalDashboard/Cmdlets/Invoke-UDRedirect.cs index e6c99043..72d67d6b 100644 --- a/src/UniversalDashboard/Cmdlets/Invoke-UDRedirect.cs +++ b/src/UniversalDashboard/Cmdlets/Invoke-UDRedirect.cs @@ -1,19 +1,10 @@ -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)); @@ -21,11 +12,14 @@ public class InvokeRedirectCommand : PSCmdlet [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; var connectionId = this.GetVariableValue("ConnectionId") as string; - hub.Redirect(connectionId, Url).Wait(); + hub.Redirect(connectionId, Url, OpenInNewWindow.IsPresent).Wait(); } } } diff --git a/src/UniversalDashboard/Server/DashboardHub.cs b/src/UniversalDashboard/Server/DashboardHub.cs index 6a20700b..026e1048 100644 --- a/src/UniversalDashboard/Server/DashboardHub.cs +++ b/src/UniversalDashboard/Server/DashboardHub.cs @@ -38,9 +38,9 @@ public static async Task RequestState(this IHubContext hub, string await hub.Clients.Client(clientId).SendAsync("requestState", componentId, requestId); } - public static async Task Redirect(this IHubContext hub, string clientId, string url) + public static async Task Redirect(this IHubContext 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 hub, string componentId, Element state) diff --git a/src/client/src/app/ud-dashboard.jsx b/src/client/src/app/ud-dashboard.jsx index 99e4d54d..60adf167 100644 --- a/src/client/src/app/ud-dashboard.jsx +++ b/src/client/src/app/ud-dashboard.jsx @@ -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) {