A Color Changing Card or Box?

Hi guys,

I have created my first dashboard and it works really well, except for one thing that I can’t figure out. I have a script running on a server and it writes data to a DB depending on how serious a problem is. 3 of these states are colors, they are:
green,
orange,
and red.

I can get these into the dashboard as variables, but I cannot figure out how to auto refresh the background color on the card?. My UDTables work just fine and they auto refresh perfectly. Here is my code of a working table:
   New-UDRow -Columns {
             New-UDColumn -Size 12 -Content { }
               New-UDColumn -Size 12 -Content {            
                New-UDTable -Title "Errors Today" -Header @("Number of Broken Things Today") -Endpoint {
                            $cache:TodayCount | Out-UDTableData -Property @("Today")} -RefreshInterval 5 -AutoRefresh 
                        }     
                      }   

And here is the card code that doesn’t work:

     New-UDRow -Columns {
          New-UDColumn -Size 12 -Content { }
            New-UDColumn -Size 12 -Content {  
               New-UDCard -Title "Current Status" -Text "$cache:Status currently affecting $cache:Item" -BackgroundColor $cache:Colour -FontColor "white"  
                  } 
                }   

Is there something better than trying to use a UDCard as a status indicator?

Hi Graeme,

Try replacing

    New-UDColumn -Size 12 -Content { 

by

    New-UDColumn -Size 12 -Endpoint { 

Whatever is defined in -Content {} is part of the ‘static’ definition of the page and is created at startup of your Dashboard.

When using an -Endpoint {} The content is recalculated on every refresh.

3 Likes

Thanks for the great explanation Rudy, I’ll give this a try. :slight_smile:

Just to chip in further…you can use the -AutoRefresh and -RefreshInterval parameters to check how often that endpoint should run to check it is updating…with the refresh interval you need to supply an number for how often it needs to refresh. Also as you are using New-UDColumn you could set the endpoint on that instead of the card as the card is nested within the column. Less endponts the better, but they are super useful for just refreshing the state of a particular component/element on the page.

I am looking to write more blogs on universal dashboard here https://psdevuk.github.io/ud-flix/ so if you think this would make a good blog let me know. Thanks

1 Like

That sounds good, I would read that. I’ll take a look at your blog. Thanks

Boom done. https://psdevuk.github.io/ud-flix/Content-vs-Endpoint/

3 Likes

Great article! It makes much more sense now…

I have added your blog to my UD favorites list. :smiley:

1 Like