Skip to content

Instantly share code, notes, and snippets.

@gaelcolas
Created April 10, 2023 17:37
Show Gist options
  • Save gaelcolas/c28c11b75a57f379b004c8af3348ccc8 to your computer and use it in GitHub Desktop.
Save gaelcolas/c28c11b75a57f379b004c8af3348ccc8 to your computer and use it in GitHub Desktop.
# Put code you'd like to run during dashboard startup here.
New-UDDashboard -Title 'a' -Pages @(
# Create a page using the menu to the right ->
# Reference the page here with Get-UDPage
New-UDPage -Name 'Select a folder' -Content {
$Page:Path = $Env:USERPROFILE
New-UDPaper -Content {
New-UDAutocomplete -id 'myPath' -Value $Page:Path -Variant filled -FullWidth -OnLoadOptions {
$options = @(
(Get-ChildItem -Path "$body*" -ErrorAction SilentlyContinue).FullName
)
if ($options)
{
$options | ConvertTo-Json
}
} -OnChange {
if (Test-Path $body)
{
$Page:Path = $body
Sync-UDElement -Id 'table'
}
} -OnEnter {
$enteredValue = (Get-UDElement -Id 'myPath').value
if (Test-Path -Path $enteredValue)
{
$Page:Path = $enteredValue
}
Sync-UDElement -Id 'table'
}
}
$cols = @(
New-UDTableColumn -Property 'PSIsContainer' -Render {
if ($eventData.PSIsContainer)
{
New-UDIcon -Icon 'Folder'
}
else {
New-UDIcon -Icon 'Files'
}
} -Title 'Type'
New-UDTableColumn -Property 'BaseName' -Title 'Name' -Render {
New-UDLink -Text $eventData.BaseName -OnClick {
$Page:Path = $EventData.FullName
Sync-UDElement -Id 'table'
}
}
New-UDTableColumn -Property 'FullName' -Title 'FullName' -Hidden
)
New-UDGrid -Container -Content {
New-UDGrid -Item -SmallSize 5 -Content {
New-UDStack -Direction 'column' -Content {
Get-PSDrive -PSProvider 'FileSystem' | Where-Object -FilterScript {$_.Name -notmatch 'Temp'} | ForEach-Object -Process {
$root = $_.Root
New-UDPaper -Content {
New-UDTreeView -Node {
New-UDTreeNode -Name $root -id $root
} -id 'child1' -OnNodeClicked {
Get-ChildItem -Directory -Path $EventData.Id | ForEach-Object -Process {
New-UDTreeNode -Name $_.BaseName -id $_.FullName
}
$Page:Path = $EventData.Id
Set-UDElement -Id 'myPath' -Properties @{
value = $Page:Path
}
Sync-UDElement -Id 'table'
}
} -Elevation 10
}
}
}
New-UDGrid -Item -Content {
New-UDPaper -Content {
New-UDDynamic -id 'table' -Content {
if ($Page:Path -match '^"')
{
$mypath = $Page:Path | ConvertFrom-Json
}
else
{
$mypath = $Page:Path
}
$data = Get-ChildItem -Path $mypath -Directory
New-UDTable -id 'filesAndFolder' -Column $cols -Data $data -Dense -OnRowSelection {
$Page:Path = $EventData.FullName
Set-UDElement -Id 'myPath' -Properties @{
value = $Page:Path
}
Sync-UDElement -Id 'table'
}
}
}
}
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment