diff --git a/src/UniversalDashboard/Help/Invoke-UDRedirect.md b/src/UniversalDashboard/Help/Invoke-UDRedirect.md index f975f309..729f5a32 100644 --- a/src/UniversalDashboard/Help/Invoke-UDRedirect.md +++ b/src/UniversalDashboard/Help/Invoke-UDRedirect.md @@ -21,15 +21,24 @@ Redirects a user to a URL. This cmdlet can be called from any endpoint. ## EXAMPLES -### Example 1 +### Redirect to Google ``` -PS C:\> New-UDButton -Text "Redirect to Google" -OnClick { +New-UDButton -Text "Redirect to Google" -OnClick { Invoke-UDRedirect -Url "https://www.google.com" } ``` Redirects the user to Google. +### Open in a new tab or window +``` +New-UDButton -Text "Redirect to Google" -OnClick { + Invoke-UDRedirect -Url "https://www.google.com" -OpenInNewWindow +} +``` + +Redirects the user to Google. + ## PARAMETERS ### -OpenInNewWindow diff --git a/src/poshud/dashboard.ps1 b/src/poshud/dashboard.ps1 index e3914c7c..933d17fd 100644 --- a/src/poshud/dashboard.ps1 +++ b/src/poshud/dashboard.ps1 @@ -6,7 +6,10 @@ $NavBarLinks = @((New-UDLink -Text "Buy Universal Dashboard" -Url "https://ironm $Pages = @() $Pages += . (Join-Path $PSScriptRoot "pages\home.ps1") $Pages += . (Join-Path $PSScriptRoot "pages\getting-started.ps1") +$Pages += . (Join-Path $PSScriptRoot "pages\rest-apis.ps1") +$Pages += . (Join-Path $PSScriptRoot "pages\scheduled-endpoints.ps1") $Pages += . (Join-Path $PSScriptRoot "dashboards\azure.ps1") +$Pages += New-UDComponentPage -Command 'Invoke-UDRedirect' $Components = @() @('New-UDButton', @@ -48,8 +51,8 @@ $Pages += (New-UDComponentPage -Command "Show-UDToast") $Navigation = New-UDSideNav -Content { New-UDSideNavItem -Text "Home" -Url "Home" -Icon home - New-UDSideNavItem -SubHeader -Text "Dashboards" -Children { - New-UDSideNavItem -Text "Azure Resources" -Url "Azure" -Icon cloud + New-UDSideNavItem -SubHeader -Text "Sample Dashboards" -Icon chart_line -Children { + New-UDSideNavItem -Text "Azure Resources" -Url "Azure" } New-UDSideNavItem -SubHeader -Text "About Universal Dashboard" -Icon question -Children { New-UDSideNavItem -Text "Getting Started" -Url "Getting-Started" @@ -58,11 +61,16 @@ $Navigation = New-UDSideNav -Content { $Components } New-UDSideNavItem -SubHeader -Text "Utilities" -Icon wrench -Children { + New-UDSideNavItem -Text "Modals" -Url "Show-UDModal" + New-UDSideNavItem -Text 'Scheduled Endpoints' -Url 'Scheduled-Endpoints' New-UDSideNavItem -Text "Toasts" -Url "Show-UDToast" + New-UDSideNavItem -Text 'Redirect' -Url 'Invoke-UDRedirect' + New-UDSideNavItem -Text 'REST APIs' -Url 'REST-APIs' + } } -Fixed -$EndpointInitialization = New-UDEndpointInitialization -Function "New-UDComponentExample" +$EndpointInitialization = New-UDEndpointInitialization -Function @("New-UDComponentExample", "New-UDRestApiExample", "New-UDRawExample") New-UDDashboard -NavbarLinks $NavBarLinks -Title "PowerShell Universal Dashboard" -Pages $Pages -Footer $Footer -Navigation $Navigation -EndpointInitialization $EndpointInitialization diff --git a/src/poshud/pages/rest-apis.ps1 b/src/poshud/pages/rest-apis.ps1 new file mode 100644 index 00000000..2a6a3c1d --- /dev/null +++ b/src/poshud/pages/rest-apis.ps1 @@ -0,0 +1,65 @@ +New-UDPage -Name "REST-APIs" -Endpoint { + + $OnlineVersion = 'https://github.com/ironmansoftware/universal-dashboard/blob/master/src/poshud/pages/rest-apis.ps1' + + New-UDElement -Tag div -Attributes @{ style = @{ paddingLeft = "20px" }} -Content { + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDHeading -Size 3 -Text "REST APIs" + } + } + + New-UDRow -Columns { + New-UDButton -Icon github -Text "Edit on GitHub" -OnClick ( + New-UDEndpoint -Endpoint { + Invoke-UDRedirect -Url $ArgumentList[0] -OpenInNewWindow + } -ArgumentList $OnlineVersion + ) -BackgroundColor 'white' -FontColor 'black' + } + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDHeading -Size 5 -Text "You can define REST APIs to allow herrogenous systems to interact with PowerShell over HTTP." + } + } + + New-UDElement -tag 'hr' + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDHeading -Size 4 -Text "Examples" + } + } + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDRestApiExample -Name "Return Data" -Description "Creates a basic GET endpoint that returns data." -Code "New-UDEndpoint -Url '/data' -Endpoint { 'Hello, World!' } " -Invocation "Invoke-RestMethod http://localhost:10001/api/data" + } + } + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDRestApiExample -Name "Filter Data" -Description "Filter data using route variables." -Code "New-UDEndpoint -Url '/data/:filter' -Endpoint { param(`$filter) @(1,2,3) | Where-Object { `$_ -eq `$filter } } " -Invocation "Invoke-RestMethod http://localhost:10001/api/data/1" + } + } + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDRestApiExample -Name "Filter Data with query string parameters" -Description "Filter data using query string parameters." -Code "New-UDEndpoint -Url '/queryData' -Endpoint { param(`$filter) @(1,2,3) | Where-Object { `$_ -eq `$filter } } " -Invocation "Invoke-RestMethod http://localhost:10001/api/queryData?filter=1" + } + } + + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDRestApiExample -Name "Send Data to the Server" -Description "Sends data to the server via the body" -Code "New-UDEndpoint -Method POST -Url '/data' -Endpoint { param(`$Body) `$Body } " -Invocation "Invoke-RestMethod http://localhost:10001/api/data -Method POST -Body 'Echo'" + } + } + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDRestApiExample -Name "Send Data via route variables" -Description "Uses route variables to send data to the endpoint on the server" -Code "New-UDEndpoint -Method POST -Url '/data/:variable' -Endpoint { param(`$variable) `$variable } " -Invocation "Invoke-RestMethod http://localhost:10001/api/data/echo -Method POST" + } + } + } +} \ No newline at end of file diff --git a/src/poshud/pages/scheduled-endpoints.ps1 b/src/poshud/pages/scheduled-endpoints.ps1 new file mode 100644 index 00000000..6dfd1773 --- /dev/null +++ b/src/poshud/pages/scheduled-endpoints.ps1 @@ -0,0 +1,40 @@ +New-UDPage -Name "Scheduled-Endpoints" -Endpoint { + + $OnlineVersion = 'https://github.com/ironmansoftware/universal-dashboard/blob/master/src/poshud/pages/scheduled-endpoints.ps1' + + New-UDElement -Tag div -Attributes @{ style = @{ paddingLeft = "20px" }} -Content { + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDHeading -Size 3 -Text "Scheduled Endpoints" + } + } + + New-UDRow -Columns { + New-UDButton -Icon github -Text "Edit on GitHub" -OnClick ( + New-UDEndpoint -Endpoint { + Invoke-UDRedirect -Url $ArgumentList[0] -OpenInNewWindow + } -ArgumentList $OnlineVersion + ) -BackgroundColor 'white' -FontColor 'black' + } + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDHeading -Size 5 -Text "Scheduled endpoints allow you to schedule actions to be taken on an interval. This is similar to a task scheduler but can interact with features of Universal Dashboard." + } + } + + New-UDElement -tag 'hr' + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDHeading -Size 4 -Text "Examples" + } + } + + New-UDRow -Columns { + New-UDColumn -Size 12 -Content { + New-UDRawExample -Title 'Scheduled every 10 minutes' -Description "Runs the scheduled endpoint every ten minutes." -Code "New-UDEndpoint -Schedule (New-UDEndpointSchedule -Every 10 -Minute) -Endpoint { `$Cache:Processes = Get-Process }" + } + } + } +} \ No newline at end of file diff --git a/src/poshud/utils.ps1 b/src/poshud/utils.ps1 index ab93c28e..fb9f2503 100644 --- a/src/poshud/utils.ps1 +++ b/src/poshud/utils.ps1 @@ -103,5 +103,77 @@ function New-UDComponentExample { } } + New-UDElement -tag 'hr' +} + +function New-UDRestApiExample { + param( + $Name, + $Description, + $Code, + $Invocation + ) + + New-UDHeading -Size 4 -Text $Name + New-UDHeading -Size 5 -Text $Description + + New-UDTabContainer -Tabs { + New-UDTab -Text "Code" -Content { + New-UDElement -Tag 'div' -Attributes @{ + style = @{ + padding = '30px' + background = '#f8f8f8' + } + } -Content { + New-UDElement -tag pre -Content { + $Code + Invoke-Expression $Code | Out-Null + } + } + } + New-UDTab -Text "Try It" -Content { + New-UDElement -Tag 'div' -Attributes @{ + style = @{ + padding = '30px' + background = '#f8f8f8' + } + } -Content { + New-UDElement -tag pre -Content { + $Invocation + } + } + } + } + + New-UDElement -tag 'hr' +} + + +function New-UDRawExample { + param( + $Name, + $Description, + $Code + ) + + New-UDHeading -Size 4 -Text $Name + New-UDHeading -Size 5 -Text $Description + + New-UDTabContainer -Tabs { + New-UDTab -Text "Code" -Content { + New-UDElement -Tag 'div' -Attributes @{ + style = @{ + padding = '30px' + background = '#f8f8f8' + } + } -Content { + New-UDElement -tag pre -Content { + $Code + Invoke-Expression $Code | Out-Null + } + } + } + } + New-UDElement -tag 'hr' } \ No newline at end of file