Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
Added "scrolltoelement" param to select (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoSen29 authored and adamdriscoll committed Oct 25, 2019
1 parent 13a2623 commit 0ea425e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/UniversalDashboard/Cmdlets/Select-UDElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ namespace UniversalDashboard.Cmdlets
[Cmdlet(VerbsCommon.Select, "UDElement")]
public class SelectUDElementCommand : PSCmdlet
{
//private readonly Logger Log = LogManager.GetLogger(nameof(InvokeRedirectCommand));
//private readonly Logger Log = LogManager.GetLogger(nameof(SelectUDElementCommand));

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

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

protected override void EndProcessing()
{
var hub = this.GetVariableValue("DashboardHub") as IHubContext<DashboardHub>;
var connectionId = this.GetVariableValue("ConnectionId") as string;
hub.Select(connectionId, ID).Wait();
hub.Select(connectionId, ID, ScrollToElement.IsPresent).Wait();
}
}
}
20 changes: 17 additions & 3 deletions src/UniversalDashboard/Help/Select-UDElement.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Selects an element.
## SYNTAX

```
Select-UDElement -ID <String> [<CommonParameters>]
Select-UDElement -ID <String> [<CommonParameters>] -ScrollToElement [Switch]
```

## DESCRIPTION
Expand All @@ -23,10 +23,10 @@ Selects an element.

### Example 1
```
PS C:\> Select-UDElement -Id 'textbox'
PS C:\> Select-UDElement -Id 'textbox' -ScrollToElement
```

Selects the text box with the ID 'textbox'
Selects the text box with the ID 'textbox' and scrolls to the position on page.

## PARAMETERS

Expand All @@ -45,6 +45,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -ScrollToElemenet
```yaml
Type: Switch
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down
4 changes: 2 additions & 2 deletions src/UniversalDashboard/Server/DashboardHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public static async Task Redirect(this IHubContext<DashboardHub> hub, string cli
await hub.Clients.Client(clientId).SendAsync("redirect", url, newWindow);
}

public static async Task Select(this IHubContext<DashboardHub> hub, string clientId, string ID)
public static async Task Select(this IHubContext<DashboardHub> hub, string clientId, string ID, bool scrollToElement)
{
await hub.Clients.Client(clientId).SendAsync("select", ID);
await hub.Clients.Client(clientId).SendAsync("select", ID, scrollToElement);
}

public static async Task Clipboard(this IHubContext<DashboardHub> hub, string clientId, string Data, bool toastOnSuccess, bool toastOnError)
Expand Down
5 changes: 4 additions & 1 deletion src/client/src/app/ud-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ export default class UdDashboard extends React.Component {
}
});

connection.on('select', (ID) => {
connection.on('select', (ID, scrollToElement) => {
document.getElementById(ID).focus();
if (scrollToElement) {
document.getElementById(ID).scrollIntoView();
}
});

connection.on('clipboard', (Data, toastOnSuccess, toastOnError) => {
Expand Down

0 comments on commit 0ea425e

Please sign in to comment.