Refresh Content in New-UDParagraph (After a New-UDInput event)

@ maylife The link you referenced is where I started on dynamic pages. Just have to play with the example to get the experience. I put together a UDGrid showing the Windows Services with start and stop buttons. The buttons need a little more work to have them functional. The refresh icon in the bottom right corner does pickup the current status for each service.


$ServicesStatus = New-UDPage -Name "Windows Service Dashboard" -Icon home -Content {

  New-UDGrid -Title "Windows Service Report" -Endpoint {
    $servicesDB = Get-Service;
    [int]$psIdx = $servicesDB.Count - 1;
    if ($psIdx -gt 0) {
      $PSreports = 0 .. $psIdx | ForEach-Object {
        [PSCustomObject] @{Status = 'data1'; Name = 'data2'; DisplayName = 'data3'; Action = 'data4';}
      }
    } else {
      $PSreports = [PSCustomObject] @{Status = 'data1'; Name = 'data2'; DisplayName = 'data3'; Action = 'data4';}
    }
    $psIdx = 0;
    $servicesDB | ForEach-Object {
        $PSreports[$psIdx].Name = $_.Name
        $PSreports[$psIdx].DisplayName = $_.DisplayName
        if ($_.Status -eq "Running") {
          $PSreports[$psIdx].Status = "Running";
          $PSreports[$psIdx].Action = New-UDButton -Text "Stop" -BackgroundColor Red -OnClick (New-UDEndpoint -Endpoint {
            Stop-Service $_.Name;
            Show-UDToast -Message "Stopped $_.Name" -CloseOnClick
          })
        } else {
          $PSreports[$psIdx].Status = "Stopped";
          $PSreports[$psIdx].Action = New-UDButton -Text "Start" -BackgroundColor Green -OnClick (New-UDEndpoint -Endpoint {
            Start-Service $_.Name;
            Show-UDToast -Message "Started $_.Name" -CloseOnClick
          })
        }
        $psIdx++;
    }

    $PSreports | Select-Object Status,Name,DisplayName,Action | Out-UDGridData

  }
}

$DB1 = New-UDDashboard -Title "Windows Service Dashboard" `
  -Pages @($ServicesStatus);

Start-UDDashboard -Name "Services" -Dashboard $DB1 -Port 10062;```
2 Likes