Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
weibaohui committed Nov 24, 2023
1 parent 5e87416 commit 83199c5
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 119 deletions.
3 changes: 3 additions & 0 deletions BlazorApp/BlazorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
<ProjectReference Include="..\Entity\Entity.csproj"/>
<ProjectReference Include="..\Extension\Extension.csproj"/>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="Pages\Common\ResourceWatcher.razor"/>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions BlazorApp/Pages/ChatHubPage.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@page "/ChatHubPage"
@using k8s.Models
@using BlazorApp.Pages.Common
<h3>ChatHubPage</h3>

<div class="row">
Expand Down
4 changes: 2 additions & 2 deletions BlazorApp/Pages/ChatHubPage.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace BlazorApp.Pages;

public partial class ChatHubPage : ComponentBase
{
private ResourceCache<V1Pod> _itemList = ResourceCache<V1Pod>.Instance();
private ResourceCacheHelper<V1Pod> _itemList = ResourceCacheHelper<V1Pod>.Instance();

private async Task OnResourceChanged(ResourceCache<V1Pod> data)
private async Task OnResourceChanged(ResourceCacheHelper<V1Pod> data)
{
_itemList = data;
await InvokeAsync(StateHasChanged);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
using System;
using System.Threading.Tasks;
using AntDesign;
using BlazorApp.Service.impl;
using BlazorApp.Utils;
using Entity;
using k8s;
using k8s.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.SignalR.Client;

namespace BlazorApp.Pages;
namespace BlazorApp.Pages.Common;

public partial class ResourceWatcher<T> : ComponentBase where T : IKubernetesObject<V1ObjectMeta>
{
[Inject]
protected NavigationManager MyUriHelper { get; set; }

[Parameter]
public EventCallback<ResourceCache<T>> OnResourceChanged { get; set; }
public EventCallback<ResourceCacheHelper<T>> OnResourceChanged { get; set; }

private ResourceCache<T> _cache = ResourceCache<T>.Instance();
private ResourceCacheHelper<T> _cache = ResourceCacheHelper<T>.Instance();

private async Task UpdateMessage(ResourceWatchEntity<T> data)
{
Expand Down
1 change: 1 addition & 0 deletions BlazorApp/Pages/Common/TableBase.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@typeparam T
52 changes: 52 additions & 0 deletions BlazorApp/Pages/Common/TableBase.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Linq;
using System.Threading.Tasks;
using AntDesign.TableModels;
using BlazorApp.Service;
using BlazorApp.Utils;
using k8s;
using k8s.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;

namespace BlazorApp.Pages.Common;

public partial class TableBase<T> : ComponentBase where T : IKubernetesObject<V1ObjectMeta>
{
[Inject]
protected IPageDrawerService PageDrawerService { get; set; }

protected ResourceCacheHelper<T> ItemList = ResourceCacheHelper<T>.Instance();

protected readonly TableDataHelper<T> TableDataHelper = new();
protected static readonly ILogger<TableBase<T>> Logger = LoggingHelper<TableBase<T>>.Logger();
private string _selectedNs = "";


protected async Task OnSearchHandler(string key)
{
await TableDataHelper.SearchName(key);

await InvokeAsync(StateHasChanged);
}


protected async Task OnNsSelectedHandler(string ns)
{
_selectedNs = ns;
await TableDataHelper.OnNsSelectedHandler(_selectedNs);
await InvokeAsync(StateHasChanged);
}


protected async Task OnPageChangeHandler(QueryModel<T> queryModel)
{
await TableDataHelper.OnChange(queryModel);
await InvokeAsync(StateHasChanged);
}


public void RemoveSelection(string uid)
{
TableDataHelper.SelectedRows = TableDataHelper.SelectedRows.Where(x => x.Metadata.Uid != uid);
}
}
1 change: 1 addition & 0 deletions BlazorApp/Pages/Deployment/DeploymentIndex.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using k8s.Models
@using Extension
@using BlazorApp.Pages.Workload
@using BlazorApp.Pages.Common
@if (tps.PagedItems != null)
{
<Card Bordered="false" Hoverable="true">
Expand Down
10 changes: 5 additions & 5 deletions BlazorApp/Pages/Deployment/DeploymentIndex.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public partial class DeploymentIndex : ComponentBase
[Inject]
private IPageDrawerService PageDrawerService { get; set; }

public TablePagedService<V1Deployment> tps = new();
public TableDataHelper<V1Deployment> tps = new();


private string _selectedNs = "";
private ResourceCache<V1Deployment> _itemList = ResourceCache<V1Deployment>.Instance();
private string _selectedNs = "";
private ResourceCacheHelper<V1Deployment> _itemList = ResourceCacheHelper<V1Deployment>.Instance();

private async Task OnResourceChanged(ResourceCache<V1Deployment> data)
private async Task OnResourceChanged(ResourceCacheHelper<V1Deployment> data)
{
_itemList = data;
await InvokeAsync(StateHasChanged);
Expand Down Expand Up @@ -71,4 +71,4 @@ private async Task OnDeployClick(V1Deployment deploy)
var options = PageDrawerService.DefaultOptions($"{deploy.Kind ?? "Deployment"}:{deploy.Name()}");
await PageDrawerService.ShowDrawerAsync<DeploymentDetailView, V1Deployment, bool>(options, deploy);
}
}
}
22 changes: 12 additions & 10 deletions BlazorApp/Pages/Pod/PodIndex.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
@using Extension
@using BlazorApp.Pages.Workload
@using BlazorApp.Pages.Container
@if (_itemList != null)
@using BlazorApp.Pages.Common
@inherits BlazorApp.Pages.Common.TableBase<V1Pod>


@if (ItemList != null)
{
<Card Bordered="false" Hoverable="true">
<TitleTemplate>
<SearchToolBar Title="Pods" Count="@_tps.Total"
<SearchToolBar Title="Pods" Count="@TableDataHelper.Total"
OnSearch="OnSearchHandler"
OnNsSelected="OnNsSelectedHandler">
</SearchToolBar>
</TitleTemplate>
<ChildContent>
<Body>

<Table TItem="V1Pod"
DataSource="@_tps.PagedItems"
DataSource="@TableDataHelper.PagedItems"
Size=@TableSize.Small Bordered="true"
Total="_tps.Total"
@bind-PageIndex="_tps.PageIndex"
@bind-PageSize="_tps.PageSize"
@bind-SelectedRows="_tps.SelectedRows"
OnChange="OnChange"
Total="TableDataHelper.Total"
@bind-PageIndex="TableDataHelper.PageIndex"
@bind-PageSize="TableDataHelper.PageSize"
@bind-SelectedRows="TableDataHelper.SelectedRows"
OnChange="OnPageChangeHandler"
ScrollX="1500">
<Selection Key="@(context.Name())" Width="40" Fixed="left"/>
<AntDesign.Column Field="@context.Name()" Title="Name">
Expand Down Expand Up @@ -58,6 +61,5 @@
</Body>
</ChildContent>
</Card>

<ResourceWatcher OnResourceChanged="OnResourceChanged" T="V1Pod"></ResourceWatcher>
}
63 changes: 9 additions & 54 deletions BlazorApp/Pages/Pod/PodIndex.razor.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,36 @@
using System;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using AntDesign.TableModels;
using BlazorApp.Pages.Common;
using BlazorApp.Pages.Node;
using BlazorApp.Service;
using BlazorApp.Service.impl;
using BlazorApp.Utils;
using Entity;
using k8s.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;

namespace BlazorApp.Pages.Pod
{
public partial class PodIndex : ComponentBase
public partial class PodIndex : TableBase<V1Pod>
{
[Inject]
private IPodService PodService { get; set; }

[Inject]
private INodeService NodeService { get; set; }

[Inject]
private IPageDrawerService PageDrawerService { get; set; }

[Inject]
private IWatchService WatchService { get; set; }


private TablePagedService<V1Pod> _tps = new();


private string _selectedNs = "";
private ResourceCache<V1Pod> _itemList = ResourceCache<V1Pod>.Instance();

private async Task OnResourceChanged(ResourceCache<V1Pod> data)
private async Task OnResourceChanged(ResourceCacheHelper<V1Pod> data)
{
_itemList = data;
await _tps.CopyData(_itemList);
ItemList = data;
await TableDataHelper.CopyData(ItemList);
await InvokeAsync(StateHasChanged);
}

protected override async Task OnInitializedAsync()
{
await _tps.CopyData(_itemList);
}


private async Task OnNsSelectedHandler(string ns)
{
_selectedNs = ns;
await _tps.OnNsSelectedHandler(ns);
await InvokeAsync(StateHasChanged);
}

public void RemoveSelection(string uid)
{
_tps.SelectedRows = _tps.SelectedRows.Where(x => x.Metadata.Uid != uid);
}


private async Task OnChange(QueryModel<V1Pod> queryModel)
{
_tps.OnChange(queryModel);
await InvokeAsync(StateHasChanged);
}

private async Task OnSearchHandler(string key)
{
_tps.SearchName(key);

await base.OnInitializedAsync();
await TableDataHelper.CopyData(ItemList);
await InvokeAsync(StateHasChanged);
}

Expand All @@ -91,11 +52,5 @@ private async Task PodDeleteHandler(V1Pod pod)
{
await InvokeAsync(StateHasChanged);
}

private async Task OnPodChanged(string obj)
{
await _tps.GetData(_selectedNs);
await InvokeAsync(StateHasChanged);
}
}
}
4 changes: 2 additions & 2 deletions BlazorApp/Pages/ReplicaSet/ReplicaSetIndex.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class ReplicaSetIndex : ComponentBase
[Inject]
private IPageDrawerService PageDrawerService { get; set; }

private TablePagedService<V1ReplicaSet> tps = new();
private TableDataHelper<V1ReplicaSet> tps = new();


private string _selectedNs = "";
Expand Down Expand Up @@ -65,4 +65,4 @@ private async Task OnRsClick(V1ReplicaSet rs)
await PageDrawerService.ShowDrawerAsync<ReplicaSetDetailView, V1ReplicaSet, bool>(options, rs);
}
}
}
}
8 changes: 4 additions & 4 deletions BlazorApp/Service/impl/PodService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace BlazorApp.Service.impl
{
public class PodService : IPodService
{
private readonly IBaseService _baseService;
private readonly IWatchService _watchService;
private readonly IServiceScope _scope;
private ResourceCache<V1Pod> _cache = ResourceCache<V1Pod>.Instance();
private readonly IBaseService _baseService;
private readonly IWatchService _watchService;
private readonly IServiceScope _scope;
private readonly ResourceCacheHelper<V1Pod> _cache = ResourceCacheHelper<V1Pod>.Instance();

public PodService(IBaseService baseService, IServiceScopeFactory serviceScopeFactory)
{
Expand Down
4 changes: 2 additions & 2 deletions BlazorApp/Service/impl/WatchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class WatchService : IWatchService
{
private readonly IBaseService _baseService;

private ResourceCache<V1Pod> _cache = ResourceCache<V1Pod>.Instance();
private readonly IHubContext<ChatHub> _ctx;
private readonly ResourceCacheHelper<V1Pod> _cache = ResourceCacheHelper<V1Pod>.Instance();
private readonly IHubContext<ChatHub> _ctx;

public WatchService(IBaseService baseService, IHubContext<ChatHub> ctx)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace BlazorApp.Utils;

public class LoggingUtils<T>
public class LoggingHelper<T>
{
public static ILogger<T> Logger()
{
using ILoggerFactory factory = LoggerFactory.Create(builder => builder.AddConsole());
var logger = factory.CreateLogger<T>();
return logger;
}
}
}
Loading

0 comments on commit 83199c5

Please sign in to comment.