Skip to content

Commit

Permalink
update ingress display logic & clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
weibaohui committed Apr 24, 2024
1 parent 8ba4c1b commit a0c4b95
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
6 changes: 3 additions & 3 deletions BlazorApp/Pages/Ingress/IngressIndex.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
<AntDesign.Column Title=@L["IngressClass"] TData="string">
@context.Spec.IngressClassName
</AntDesign.Column>
<AntDesign.Column Title=@L["Hosts"] TData="string">
<AntDesign.Column Title=@L["Detail"] TData="string">
@if (context.Spec.Rules is { Count: > 0 })
{
@foreach (var rule in context.Spec.Rules)
{
@foreach (var path in rule.Http.Paths)
{
<div>
<a href="@GetRulePathDisplay(rule, path, context.Spec.Tls)"
<a href="@IngressService.GetRulePathDisplayUrl(rule, path, context.Spec.Tls)"
target="_blank">
@GetRulePathDisplay(rule, path, context.Spec.Tls)
@IngressService.GetRulePathDisplayUrl(rule, path, context.Spec.Tls)
</a>
@{
var backend = GetRulePathBackend(path);
Expand Down
20 changes: 0 additions & 20 deletions BlazorApp/Pages/Ingress/IngressIndex.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using BlazorApp.Pages.Common;
using BlazorApp.Service.k8s;
Expand Down Expand Up @@ -33,25 +32,6 @@ await PageDrawerHelper<V1Ingress>.Instance
.ShowDrawerAsync<IngressDetailView, V1Ingress, bool>(item);
}

private static string GetRulePathDisplay(V1IngressRule rule, V1HTTPIngressPath path, IList<V1IngressTLS> specTls)
{
var pathDisplay = "";
if (specTls is { Count: > 0 })
pathDisplay += "https://";
else
pathDisplay += "http://";

if (rule?.Host != null && !string.IsNullOrWhiteSpace(rule?.Host))
pathDisplay += $"{rule.Host}";
else
pathDisplay += "*";

if (path?.Path != null) pathDisplay += $"{path.Path}";


return pathDisplay;
}

private static string GetRulePathBackend(V1HTTPIngressPath path)
{
var pathDisplay = "";
Expand Down
17 changes: 17 additions & 0 deletions BlazorApp/Pages/Ingress/MiniIngressListView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@
</AntDesign.Column>
<AntDesign.Column Sortable="true" TData="string" Title=@L["Namespace"] Field="@context.Namespace()"/>

<AntDesign.Column Title=@L["Detail"] TData="string">
@if (context.Spec.Rules is { Count: > 0 })
{
@foreach (var rule in context.Spec.Rules)
{
@foreach (var path in rule.Http.Paths)
{
<div>
<a href="@IngressService.GetRulePathDisplayUrl(rule, path, context.Spec.Tls)"
target="_blank">
@IngressService.GetRulePathDisplayUrl(rule, path, context.Spec.Tls)
</a>

</div>
}
}
}
</AntDesign.Column>
</Table>
}

Expand Down
1 change: 1 addition & 0 deletions BlazorApp/Service/k8s/IIngressService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface IIngressService : ICommonAction<V1Ingress>
Task<List<Result>> Analyze();

IList<V1Ingress> ListByServiceList(IList<V1Service> services);
string GetRulePathDisplayUrl(V1IngressRule rule, V1HTTPIngressPath path, IList<V1IngressTLS> specTls);
}
19 changes: 19 additions & 0 deletions BlazorApp/Service/k8s/impl/IngressService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,23 @@ public IList<V1Ingress> ListByServiceList(IList<V1Service> services)

return list;
}

public string GetRulePathDisplayUrl(V1IngressRule rule, V1HTTPIngressPath path, IList<V1IngressTLS> specTls)
{
var pathDisplay = "";
if (specTls is { Count: > 0 })
pathDisplay += "https://";
else
pathDisplay += "http://";

if (rule?.Host != null && !string.IsNullOrWhiteSpace(rule?.Host))
pathDisplay += $"{rule.Host}";
else
pathDisplay += "*";

if (path?.Path != null) pathDisplay += $"{path.Path}";


return pathDisplay;
}
}

0 comments on commit a0c4b95

Please sign in to comment.