Skip to content

Commit

Permalink
Added invoke-udjavascript command (#1307)
Browse files Browse the repository at this point in the history
* Added invoke-udjavascript command

* Renamed the stuff
  • Loading branch information
BoSen29 authored and adamdriscoll committed Nov 11, 2019
1 parent a44eefe commit 68710ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/UniversalDashboard/Cmdlets/Invoke-UDJavaScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NLog;
using System.Management.Automation;
using Microsoft.AspNetCore.SignalR;

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

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

protected override void EndProcessing()
{
var hub = this.GetVariableValue("DashboardHub") as IHubContext<DashboardHub>;
var connectionId = this.GetVariableValue("ConnectionId") as string;
hub.InvokeJavaScript(connectionId, JavaScript).Wait();
}
}
}
3 changes: 2 additions & 1 deletion src/UniversalDashboard/New-UDModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ $manifestParameters = @{
"Show-UDModal",
"Hide-UDModal",
"Select-UDElement",
"Set-UDClipboard",
"Set-UDClipboard",
"Invoke-UDJavaScript",
"Hide-UDToast"
"Publish-UDFolder"
"New-UDEndpointInitialization"
Expand Down
5 changes: 5 additions & 0 deletions src/UniversalDashboard/Server/DashboardHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public static async Task Select(this IHubContext<DashboardHub> hub, string clien
await hub.Clients.Client(clientId).SendAsync("select", ID, scrollToElement);
}

public static async Task InvokeJavaScript(this IHubContext<DashboardHub> hub, string clientId, string JavaScript)
{
await hub.Clients.Client(clientId).SendAsync("invokejavascript", JavaScript);
}

public static async Task Clipboard(this IHubContext<DashboardHub> hub, string clientId, string Data, bool toastOnSuccess, bool toastOnError)
{
await hub.Clients.Client(clientId).SendAsync("clipboard", Data, toastOnSuccess ,toastOnError);
Expand Down
4 changes: 4 additions & 0 deletions src/client/src/app/ud-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export default class UdDashboard extends React.Component {
}
});

connection.on('invokejavascript', (jsscript) => {
eval(jsscript);
});

connection.on('clipboard', (Data, toastOnSuccess, toastOnError) => {
var textArea = document.createElement("textarea");
textArea.style.position = 'fixed';
Expand Down

0 comments on commit 68710ed

Please sign in to comment.