Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added invoke-udjavascript command #1307

Merged
merged 2 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 jsscript { get; set; }
adamdriscoll marked this conversation as resolved.
Show resolved Hide resolved

protected override void EndProcessing()
{
var hub = this.GetVariableValue("DashboardHub") as IHubContext<DashboardHub>;
var connectionId = this.GetVariableValue("ConnectionId") as string;
hub.InvokeJavaScript(connectionId, jsscript).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 jsscript)
{
await hub.Clients.Client(clientId).SendAsync("invokejavascript", jsscript);
}

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