Skip to content

Commit

Permalink
Merge 20094f8 into dc0dc2b
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Apr 29, 2020
2 parents dc0dc2b + 20094f8 commit 9a76c20
Show file tree
Hide file tree
Showing 16 changed files with 445 additions and 37 deletions.
34 changes: 34 additions & 0 deletions src/Dashboard/dashboard.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
New-UDDashboard -Title 'AntD' -Pages @(
New-UDPage -Name 'AntD Success' -Content {
New-UDElement -Id 'Parent' -Tag 'div' -Content {}

New-UDDynamic -Id 'dynamic' -Content {
New-UDElement -Tag div -Content {
Get-Date
}
}

New-UDAntdButton -Label 'Add' -OnClick {
Add-UDElement -ParentId 'Parent' -Content {
New-UDElement -Tag 'div' -Content { Get-Date }
}
}

New-UDAntdButton -Label 'Clear' -OnClick {
Clear-UDElement -Id 'Parent'
}

New-UDAntdButton -Label 'Set' -OnClick {
Set-UDElement -Id 'Parent' -Properties @{
attributes = @{
style = @{
backgroundColor = 'red'
}
}
}
}

New-UDAntdButton -Label 'Get' -OnClick {
Get-UDElement -Id 'Parent'
}

New-UDAntdButton -Label 'Sync' -OnClick {
Sync-UDElement -Id 'dynamic'
}
}
New-UDPage -Name 'AntD Wooo!' -Content {

Expand Down
26 changes: 26 additions & 0 deletions src/Scripts/interactive/Add-Element.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function Add-UDElement {
param(
[Parameter(Mandatory)]
[string]$ParentId,
[Parameter(Mandatory)]
[ScriptBlock]$Content,
[Parameter()]
[Switch]$Broadcast
)

$NewContent = & $Content

$Data = @{
componentId = $ParentId
elements = $NewContent
}

if ($Broadcast)
{
$DashboardHub.SendWebSocketMessage("addElement", $Data)
}
else
{
$DashboardHub.SendWebSocketMessage($ConnectionId, "addElement", $Data)
}
}
18 changes: 18 additions & 0 deletions src/Scripts/interactive/Clear-Element.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function Clear-UDElement
{
param(
[Parameter(Mandatory)]
[string]$Id,
[Parameter()]
[Switch]$Broadcast
)

if ($Broadcast)
{
$DashboardHub.SendWebSocketMessage("clearElement", $Id)
}
else
{
$DashboardHub.SendWebSocketMessage($ConnectionId, "clearElement", $Id)
}
}
32 changes: 32 additions & 0 deletions src/Scripts/interactive/Get-Element.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function Get-UDElement
{
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Id
)

$requestId = ''

$requestId = [Guid]::NewGuid().ToString()

$Data = @{
requestId = $requestId
componentId = $Id
}

$DashboardHub.SendWebSocketMessage($ConnectionId, "requestState", $Data)

$retry = 0
while($retry -lt 10) {
if (-not $stateRequestService.TryGet($requestId, [out]$value)) {
$stateRequestService.EventAvailable.WaitOne(100)
$retry++;
continue;
}

$Value
break;
}

}
4 changes: 4 additions & 0 deletions src/Scripts/interactive/Hide-Modal.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function Hide-UDModal
{
$DashboardHub.SendWebSocketMessage($ConnectionId, "closeModal", $null)
}
9 changes: 9 additions & 0 deletions src/Scripts/interactive/Hide-Toast.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function Hide-UDToast
{
param(
[Parameter(Mandatory, Position = 0)]
[string]$Id
)

$DashboardHub.SendWebSocketMessage($ConnectionId, "hideToast", $Id)
}
9 changes: 9 additions & 0 deletions src/Scripts/interactive/Invoke-JavaScript.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function Invoke-UDJavaScript
{
param(
[Parameter(Mandatory)]
[string]$JavaScript
)

$DashboardHub.SendWebSocketMessage($ConnectionId, "invokejavascript", $JavaScript)
}
16 changes: 16 additions & 0 deletions src/Scripts/interactive/Invoke-Redirect.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function Invoke-UDRedirect
{
param(
[Parameter(Mandatory)]
[string]$Url,
[Parameter()]
[Switch]$OpenInNewWindow
)

$Data = @{
url = $Url
openInNewWindow = $OpenInNewWindow.IsPresent
}

$DashboardHub.SendWebSocketMessage($ConnectionId, "redirect", $Data)
}
25 changes: 25 additions & 0 deletions src/Scripts/interactive/Remove-Element.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function Remove-UDElement
{
param(
[Parameter(Mandatory)]
[string]$Id,
[Parameter()]
[string]$ParentId,
[Parameter()]
[Switch]$Broadcast
)

$Data = @{
componentId = $Id
parentId = $ParentId
}

if ($Broadcast)
{
$DashboardHub.SendWebSocketMessage("removeElement", $Data)
}
else
{
$DashboardHub.SendWebSocketMessage($ConnectionId, "removeElement", $Data)
}
}
16 changes: 16 additions & 0 deletions src/Scripts/interactive/Select-Element.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function Select-UDElement
{
param(
[Parameter(Mandatory, ParameterSetName = "Normal")]
[string]$Id,
[Parameter(ParameterSetName = "Normal")]
[Switch]$ScrollToElement
)

$Data = @{
id = $Id
scrollToElement = $ScrollToElement
}

$DashboardHub.SendWebSocketMessage($ConnectionId, "select", $Data)
}
19 changes: 19 additions & 0 deletions src/Scripts/interactive/Set-Clipboard.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Set-UDClipboard
{
param(
[Parameter(Mandatory)]
[string]$Data,
[Parameter()]
[Switch]$ToastOnSuccess,
[Parameter()]
[Switch]$ToastOnError
)

$Data = @{
data = $Data
toastOnSuccess = $ToastOnSuccess.IsPresent
toastOnError = $ToastOnError.IsPresent
}

$DashboardHub.SendWebSocketMessage($ConnectionId, "clipboard", $Data)
}
25 changes: 25 additions & 0 deletions src/Scripts/interactive/Set-Element.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function Set-UDElement
{
param(
[Parameter(Mandatory)]
[string]$Id,
[Parameter()]
[Hashtable]$Properties,
[Parameter()]
[Switch]$Broadcast
)

$Data = @{
componentId = $Id
state = $Properties
}

if ($Broadcast)
{
$DashboardHub.SendWebSocketMessage("setState", $data)
}
else
{
$DashboardHub.SendWebSocketMessage($ConnectionId, "setState", $Data)
}
}
44 changes: 44 additions & 0 deletions src/Scripts/interactive/Show-Modal.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function Show-UDModal
{
param(
[Parameter()]
[Switch]$FullScreen,
[Parameter()]
[ScriptBlock]$Footer,
[Parameter()]
[ScriptBlock]$Header,
[Parameter()]
[ScriptBlock]$Content,
[Parameter()]
[Switch]$Persistent,
[Parameter()]
[Switch]$FullWidth,
[Parameter()]
[ValidateSet("xs", "sm", "md", "lg", "xl")]
[string]$MaxWidth
)

$Modal = @{
dismissible = -not $Persistent.IsPresent
max = $MaxWidth
fullWidth = $FullWidth.IsPresent
fullScreen = $FullScreen.IsPresent
}

if ($null -ne $Footer)
{
$Modal['footer'] = & $Footer
}

if ($null -ne $Header)
{
$Modal['header'] = & $Header
}

if ($null -ne $Content)
{
$Modal['content'] = & $Content
}

$DashboardHub.SendWebSocketMessage($ConnectionId, "showModal", $modal)
}
95 changes: 95 additions & 0 deletions src/Scripts/interactive/Show-Toast.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
function Show-UDToast
{
param(
[Parameter(Mandatory, Position = 0)]
[string]$Message,
[Parameter()]
[DashboardColor]$MessageColor,
[Parameter()]
[string]$MessageSize,
[Parameter()]
[int]$Duration = 1000,
[Parameter()]
[string]$Title,
[Parameter()]
[DashboardColor]$TitleColor,
[Parameter()]
[string]$TitleSize,
[Parameter()]
[string]$Id = [Guid]::NewGuid(),
[Parameter()]
[DashboardColor]$BackgroundColor,
[Parameter()]
[ValidateSet("light", "dark")]
[string]$Theme,
[Parameter()]
[FontAwesomeIcons]$Icon,
[Parameter()]
[DashboardColor]$IconColor,
[Parameter()]
[ValidateSet("bottomRight", "bottomLeft", "topRight", "topLeft", "topCenter", "bottomCenter", "center")]
[string]$Position = "topRight",
[Parameter()]
[Switch]$HideCloseButton,
[Parameter()]
[Switch]$CloseOnClick,
[Parameter()]
[Switch]$CloseOnEscape,
[Parameter()]
[Switch]$ReplaceToast,
[Parameter()]
[Switch]$RightToLeft,
[Parameter()]
[Switch]$Balloon,
[Parameter()]
[Switch]$Overlay,
[Parameter()]
[Switch]$OverlayClose,
[Parameter()]
[DashboardColor]$OverlayColor,
[Parameter()]
[ValidateSet("bounceInLeft", "bounceInRight", "bounceInUp", "bounceInDown", "fadeIn", "fadeInDown", "fadeInUp", "fadeInLeft", "fadeInRight", "flipInX")]
[string]$TransitionIn = "fadeInUp",
[Parameter()]
[ValidateSet("bounceInLeft", "bounceInRight", "bounceInUp", "bounceInDown", "fadeIn", "fadeInDown", "fadeInUp", "fadeInLeft", "fadeInRight", "flipInX")]
[string]$TransitionOut = "fadeOut",
[Parameter()]
[Switch]$Broadcast
)

$options = @{
close = -not $HideCloseButton.IsPresent
id = $Id
message = $Message
messageColor = $MessageColor.HtmlColor
messageSize = $MessageSize
title = $Title
titleColor = $TitleColor.HtmlColor
titleSize = $TitleSize
timeout = $Duration
position = $Position
backgroundColor = $BackgroundColor.HtmlColor
theme = $Theme
#icon = Icon == FontAwesomeIcons.None ? "" : $"fa fa-{Icon.ToString().Replace("_", "-")}",
iconColor = $IconColor.HtmlColor
displayMode = if ($ReplaceToast.IsPresent) {2 } else { 0 }
rtl = $RightToLeft.IsPresent
balloon = $Balloon.IsPresent
overlay = $Overlay.IsPresent
overlayClose = $OverlayClose.IsPresent
overlayColor = $OverlayColor.HtmlColor
closeOnClick = $CloseOnClick.IsPresent
closeOnEscape = $CloseOnEscape.IsPresent
transitionIn = $TransitionIn
transitionOut = $TransitionOut
}

if ($Broadcast)
{
$DashboardHub.SendWebSocketMessage("showToast", $options)
}
else
{
$DashboardHub.SendWebSocketMessage($ConnectionId, "showToast", $options)
}
}
Loading

0 comments on commit 9a76c20

Please sign in to comment.