controls/pipeline-details.modal.ps1

Function New-PipelineObjectDetailsModal {
    param(
        [Parameter(Mandatory = $true)]
        $PipelineObject
    )


    #TODO - Handlers for: System.Collections.ArrayList
    #TODO - Handlers for: Win32ShareProcess
    

    $PipeLineObjectValue = If(($PipeLineObject | Get-Member).Name  -NotContains "ToString"){$PipeLineObject.Name}else{$PipeLineObject.ToString()}

    Show-UDModal -Width "75%" -Height "75%" -Content {
        New-UDPageHeader -Text ("Pipeline Object Details")

        If($PipelineObject.GetType().Name -eq "Hashtable")  #TODO - should be able to roll this into one grid and do dynamic handling
        {
            New-UDGrid -Id ("PipelineHashTableDetailsGrid_" + $PipeLineObjectValue) -Title ("Hashtable Details") -Headers @("Name", "Value", "Actions") -Properties @("Name", "Value","Actions") -Endpoint {
                
            
                $PipelineObject.GetEnumerator() | ForEach-Object {

                    $HashValue = $_.Value

                    $CopyStringButton = New-UDButton -Icon copy -OnClick {
                        Set-UDClipboard -Data $HashValue
                    }
    
                    $ActionControls =  New-UDElement -Tag div -Content{
                        if($null -ne $HashValue -and $HashValue -ne "" -and $HashValue -ne " ")
                        {
                            New-UDTooltip -Content{$CopyStringButton} -TooltipContent {"Copy Hash String Value to Clipboard"}
                        }
                        else {
                            " "
                        }
                    }


                    [PSCustomObject]@{
                        Name = $_.Name
                        Value = $HashValue
                        Actions = $ActionControls
                    }
                    
                } | Out-UDGridData
            }
        }
        else {
            New-UDGrid -Id ("PipelineDetailsGrid_" + $PipeLineObjectValue) -Title ("Pipeline Object: " + $PipeLineObjectValue) -Headers @("Name", "Value", "Actions") -Properties @("Name", "Value", "Actions") -Endpoint {
                $Members = $PipelineObject | Get-Member
                
                $Members | Sort-Object -Property Name | ForEach-Object {
                    $Member = $_

                    if ($Member.MemberType -eq "Property" -or $Member.MemberType -eq "ScriptProperty")
                    {
                        $PipelineObjectMemberNameValue = $PipelineObject.($Member.Name)
                        
                        $PropertyValue = If($null -eq $PipelineObjectMemberNameValue -or $PipelineObjectMemberNameValue -eq ""){$null}else{$PipelineObjectMemberNameValue.ToString()}

                        $CopyStringButton = New-UDButton -Icon copy -OnClick {
                            Set-UDClipboard -Data $PropertyValue
                        }

                        $ActionControls =  New-UDElement -Tag div -Content{
                            if($null -ne $PropertyValue)
                            {
                                New-UDTooltip -Content{$CopyStringButton} -TooltipContent {"Copy String Value to Clipboard"}
                            }
                            else {
                                " "
                            }
                        }

                        [PSCustomObject]@{
                            Name = $Member.Name
                            Value = $PropertyValue
                            Actions = $ActionControls
                        }
                    }
                } | Out-UDGridData
            }
        }
    }
}