Use Cascading Parameter to provide server component with selected city parameter to set a background color.
This commit is contained in:
parent
21e24945fd
commit
f24cc284f7
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
@if (Server != null)
|
@if (Server != null)
|
||||||
{
|
{
|
||||||
<li @key="Server.Id">
|
<li @key="Server.Id" style="background-color: @GetBackgroundColor();">
|
||||||
@Server.Name in @Server.City is
|
@Server.Name in @Server.City is
|
||||||
<span style="color:@(Server.IsOnline ? "green" : "red")">
|
<span style="color:@(Server.IsOnline ? "green" : "red")">
|
||||||
@(Server.IsOnline ? "online" : "offline")
|
@(Server.IsOnline ? "online" : "offline")
|
||||||
@ -51,6 +51,9 @@
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public Server? Server { get; set; }
|
public Server? Server { get; set; }
|
||||||
|
|
||||||
|
[CascadingParameter(Name="SelectedCity")]
|
||||||
|
public string? SelectedCity { get; set; }
|
||||||
|
|
||||||
private void DeleteServer(int serverId)
|
private void DeleteServer(int serverId)
|
||||||
{
|
{
|
||||||
if (serverId > 0)
|
if (serverId > 0)
|
||||||
@ -59,4 +62,24 @@
|
|||||||
NavigationManager.Refresh(forceReload: true);
|
NavigationManager.Refresh(forceReload: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetBackgroundColor()
|
||||||
|
{
|
||||||
|
if (SelectedCity != null) {
|
||||||
|
switch (this.SelectedCity)
|
||||||
|
{
|
||||||
|
case "Eindhoven": return "lightskyblue";
|
||||||
|
case "Helmond": return "lightcoral";
|
||||||
|
case "Oosterhout": return "lightgreen";
|
||||||
|
case "Roosendaal": return "lightsalmon";
|
||||||
|
case "Deurne": return "lightpink";
|
||||||
|
default:
|
||||||
|
return "white";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "white";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -11,11 +11,12 @@
|
|||||||
<a href="@($"/servers/add")" class="btn btn-primary">Add</a>
|
<a href="@($"/servers/add")" class="btn btn-primary">Add</a>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<ServerListComponent
|
<CascadingValue Name="SelectedCity" Value="@selectedCity">
|
||||||
CityName="@this.selectedCity"
|
<ServerListComponent
|
||||||
SearchFilter="@this.searchFilter">
|
CityName="@this.selectedCity"
|
||||||
|
SearchFilter="@this.searchFilter">
|
||||||
</ServerListComponent>
|
</ServerListComponent>
|
||||||
|
</CascadingValue>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private string selectedCity = "Eindhoven";
|
private string selectedCity = "Eindhoven";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user