Skip to content

Commit

Permalink
Fixes #1292 (#1419)
Browse files Browse the repository at this point in the history
* fixes #1292

* Add Set-UDClipboard examples on demo site  and tests

* finish fixes #1292

* Fix package.lock.json.

Co-authored-by: Adam Driscoll <adamdriscoll@users.noreply.github.com>
  • Loading branch information
AlonGvili and adamdriscoll committed Jan 4, 2020
1 parent 39b50ec commit 50d6aa8
Show file tree
Hide file tree
Showing 10 changed files with 4,357 additions and 4,909 deletions.
63 changes: 63 additions & 0 deletions src/UniversalDashboard.UITest/Integration/Clipboard.Test.ps1
@@ -0,0 +1,63 @@
param([Switch]$Release)

Import-Module "$PSScriptRoot\..\TestFramework.psm1" -Force
$ModulePath = Get-ModulePath -Release:$Release
$BrowserPort = Get-BrowserPort -Release:$Release

Import-Module $ModulePath -Force

Get-UDDashboard | Stop-UDDashboard

$Driver = Start-SeFirefox
$Server = Start-UDDashboard -Port 10001

function Set-TestDashboard {
param($Dashboard)

$Server.DashboardService.SetDashboard($Dashboard)
Enter-SeUrl -Url "http://localhost:$BrowserPort" -Driver $Driver
}

Describe "Set-UDClipboard" {

Context "set the clipboard by button click" {
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDButton -Id 'btnClipboard' -Floating -Icon clipboard -OnClick {
Set-UDClipboard -Data 'You just copy me!!'
}
}

Set-TestDashboard -Dashboard $dashboard

It "should set clipboard with You just copy me!! text" {
Find-SeElement -Driver $Driver -Id "btnClipboard" | Invoke-SeClick
Start-Sleep 2
Get-Clipboard | Should be 'You just copy me!!'
}
}

Context "set the clipboard with text box value by button click" {
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDTextbox -Label "Textbox" -Placeholder "Enter your name" -Id 'textToCopy1'
New-UDButton -Id 'btnClipboard' -Icon clipboard -OnClick {
$Element = Get-UDElement -Id 'textToCopy1'
$text = $Element.Attributes.value
Set-UDClipboard -Data $text
}
}

Set-TestDashboard -Dashboard $dashboard

It "should set clipboard with hello text" {
$Element = Find-SeElement -Id "textToCopy1" -Driver $Driver
Send-SeKeys -Element $Element -Keys "hello"
Start-Sleep 2
Find-SeElement -Driver $Driver -Id "btnClipboard" | Invoke-SeClick
Start-Sleep 2
Get-Clipboard | Should be 'hello'
}
}

Stop-SeDriver $Driver
Stop-UDDashboard $Server
}
59 changes: 57 additions & 2 deletions src/UniversalDashboard/Help/Set-UDClipboard.md
Expand Up @@ -23,10 +23,65 @@ Sets the contents of the clipboard.

### Example 1
```
PS C:\> Set-UDClipboard -Data 'Some text'
New-UDHeading -Size 5 -Text 'You just copy me!!'
New-UDButton -Floating -Icon clipboard -OnClick {
Set-UDClipboard -Data 'You just copy me!!'
}
```

Sets 'Some text' into the clipboard.
Sets 'You just copy me!!' into the clipboard.

### Example 2
```
New-UDTextbox -Label "Textbox" -Placeholder "Enter your name" -Id 'textToCopy'
New-UDButton -Icon clipboard -OnClick {
$Element = Get-UDElement -Id 'textToCopy'
$text = $Element.Attributes.value
Set-UDClipboard -Data $text
}
```

Sets text box value into the clipboard.

### Example 3
```
New-UDTextbox -Label "Textbox" -Placeholder "Enter your name" -Id 'textToCopySuccess'
New-UDButton -Icon clipboard -OnClick {
$Element = Get-UDElement -Id 'textToCopySuccess'
$text = $Element.Attributes.value
Set-UDClipboard -Data $text -toastOnSuccess
}
```

Sets text box value into the clipboard and show toast message on success.

### Example 4
```
New-UDTextbox -Label "Textbox" -Placeholder "Enter your name" -Id 'textToCopyFail'
New-UDButton -Icon clipboard -OnClick {
$Element = Get-UDElement -Id 'textToCopyFailed'
$text = $Element.Attributes.value
Set-UDClipboard -Data $text -toastOnError
}
```

Sets text box value into the clipboard and show toast message on failed.

### Example 5
```
New-UDButton -Text "Show Modal" -OnClick {
Show-UDModal -Header {
New-UDHeading -Size 4 -Text "This is the text to copy"
} -Content {
'This is the text to copy'
New-UDButton -Floating -Icon clipboard -OnClick {
Set-UDClipboard -Data 'This is the text to copy'
}
}
}
```

Shows a modal with button that set text in the clipboard.

## PARAMETERS

Expand Down
2 changes: 1 addition & 1 deletion src/UniversalDashboard/New-UDModuleManifest.ps1
Expand Up @@ -98,7 +98,7 @@ $manifestParameters = @{
"New-UDTreeNode"
"New-UDTreeView"
"New-UDTooltip"
"Invoke-UDEvent"
"Invoke-UDEvent"

#Material UI
'New-UDMuAvatar'
Expand Down
23 changes: 14 additions & 9 deletions src/UniversalDashboard/Server/DashboardHub.cs
Expand Up @@ -61,15 +61,15 @@ public static async Task InvokeJavaScript(this IHubContext<DashboardHub> hub, st

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);
await hub.Clients.Client(clientId).SendAsync("clipboard", Data, toastOnSuccess, toastOnError);
}

public static async Task SetState(this IHubContext<DashboardHub> hub, string componentId, Element state)
{
await hub.Clients.All.SendAsync("setState", componentId, state);
}

public static async Task SetState(this IHubContext<DashboardHub> hub, string clientId, string componentId, Element state)
public static async Task SetState(this IHubContext<DashboardHub> hub, string clientId, string componentId, Element state)
{
await hub.Clients.Client(clientId).SendAsync("setState", componentId, state);
}
Expand All @@ -79,7 +79,7 @@ public static async Task AddElement(this IHubContext<DashboardHub> hub, string p
await hub.Clients.All.SendAsync("addElement", parentComponentId, element);
}

public static async Task AddElement(this IHubContext<DashboardHub> hub, string clientId, string parentComponentId, object[] element)
public static async Task AddElement(this IHubContext<DashboardHub> hub, string clientId, string parentComponentId, object[] element)
{
await hub.Clients.Client(clientId).SendAsync("addElement", parentComponentId, element);
}
Expand Down Expand Up @@ -122,15 +122,17 @@ public static async Task Write(this IHubContext<DashboardHub> hub, string client
}
}

public class DashboardHub : Hub {
public class DashboardHub : Hub
{
private IExecutionService _executionService;
private readonly StateRequestService _stateRequestService;
private readonly ConnectionManager _connectionManager;
private readonly IDashboardService _dashboardService;
private readonly IMemoryCache _memoryCache;
private static readonly Logger _logger = LogManager.GetLogger(nameof(DashboardHub));

public DashboardHub(IExecutionService executionService, ConnectionManager connectionManager, StateRequestService stateRequestService, IDashboardService dashboardService, IMemoryCache memoryCache) {
public DashboardHub(IExecutionService executionService, ConnectionManager connectionManager, StateRequestService stateRequestService, IDashboardService dashboardService, IMemoryCache memoryCache)
{
Log.Debug("DashboardHub constructor");

_executionService = executionService;
Expand All @@ -148,7 +150,8 @@ public override async Task OnConnectedAsync()
public override async Task OnDisconnectedAsync(Exception exception)
{
await Task.FromResult(0);
if (exception == null) {
if (exception == null)
{
Log.Debug("Disconnected");
}
else
Expand Down Expand Up @@ -206,7 +209,8 @@ public async Task UnregisterEvent(string eventId)
}
}

public async Task ClientEvent(string eventId, string eventName, string eventData, string location) {
public async Task ClientEvent(string eventId, string eventName, string eventData, string location)
{
_logger.Debug($"ClientEvent {eventId} {eventName}");

var variables = new Dictionary<string, object>();
Expand All @@ -217,11 +221,12 @@ public async Task UnregisterEvent(string eventId)
variables.Add("user", userName);
}

if (!string.IsNullOrEmpty(location)) {
if (!string.IsNullOrEmpty(location))
{
location = Encoding.UTF8.GetString(Convert.FromBase64String(location));
var locationObject = JsonConvert.DeserializeObject<Location>(location);
variables.Add("Location", locationObject);
}
}

if (bool.TryParse(eventData, out bool data))
{
Expand Down

0 comments on commit 50d6aa8

Please sign in to comment.