UniversalDashboard.psm1
if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") { Import-Module -Name "$PSScriptRoot/net451/PowerShellProTools.UniversalDashboard.dll" | Out-Null } else { Import-Module -Name "$PSScriptRoot/netcoreapp2.0/PowerShellProTools.UniversalDashboard.dll" | Out-Null } function Out-MonitorData { [CmdletBinding()] param( [Parameter(ValueFromPipeline = $true)] $Data) Process { @{ x = [DateTime]::UtcNow y = $Data } | ConvertTo-Json } } function Out-ChartData { [CmdletBinding()] param( [Parameter(ValueFromPipeline = $true)] $Data, [Parameter()] [string]$DataProperty, [Parameter()] [string]$LabelProperty, [Parameter()] [string]$DatasetLabel = "", [Parameter()] [Hashtable[]]$Dataset) Begin { New-Variable -Name Items -Value @() } Process { $Items += $Data } End { $datasets = @() if ($Dataset -ne $null) { $Dataset | ForEach-Object { $_.data = $Items.($_.DataProperty) $datasets += $_ } } else { $datasets += @{ label = $DatasetLabel backgroundColor = "rgba(29,72,255, .5)" borderColor = "rgb(0,34,178)" borderWidth = 1 data = $Items.($DataProperty) } } @{ labels = $Items.$LabelProperty datasets = $datasets } | ConvertTo-Json -Depth 10 } } function New-ChartDataset { [CmdletBinding()] param( [string]$DataProperty, [string]$Label, [PowerShellProTools.UniversalDashboard.Models.DashboardColor]$BackgroundColor = "#807B210C", [PowerShellProTools.UniversalDashboard.Models.DashboardColor]$BorderColor = "#FF7B210C", [int]$BorderWidth, [PowerShellProTools.UniversalDashboard.Models.DashboardColor]$HoverBackgroundColor = "#807B210C", [PowerShellProTools.UniversalDashboard.Models.DashboardColor]$HoverBorderColor = "#FF7B210C", [int]$HoverBorderWidth, [string]$XAxisId, [string]$YAxisId, [Hashtable]$AdditionalOptions ) Begin { $datasetOptions = @{ data = @() DataProperty = $DataProperty label = $Label backgroundColor = $BackgroundColor.HtmlColor borderColor = $BorderColor.HtmlColor borderWidth = $BorderWidth hoverBackgroundColor = $HoverBackgroundColor.HtmlColor hoverBorderColor = $HoverBorderColor.HtmlColor hoverBorderWidth = $HoverBorderWidth xAxisId = $XAxisId yAxisId = $YAxisId } if ($AdditionalOptions) { $AdditionalOptions.GetEnumerator() | ForEach-Object { $datasetOptions.($_.Key) = $_.Value } } $datasetOptions } } function Out-GridData { [CmdletBinding()] param( [Parameter(ValueFromPipeline = $true)] $Data) Begin { New-Variable -Name Items -Value @() } Process { $Items += $Data } End { @{ data = $Items } | ConvertTo-Json -Depth 10 } } function Out-TableData { [CmdletBinding()] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] $Data, [Parameter(Mandatory = $true)] [string[]]$Property ) Begin { New-Variable -Name Items -Value @() } Process { $Items += $Data } End { $rows = "" foreach($item in $items) { $rows += "<tr>"; foreach($itemProperty in $Property) { $rows += "<td>$($item.$itemProperty)</td>" } $rows += "</tr>" } @{ rows = $rows } | ConvertTo-Json -Depth 10 } } New-Alias -Name "Row" -Value "New-Row" New-Alias -Name "Column" -Value "New-Column" New-Alias -Name "Chart" -Value "New-Chart" New-Alias -Name "Table" -Value "New-Table" New-Alias -Name "Grid" -Value "New-Grid" |