Skip to content

Commit

Permalink
首页展示连接数、配置数量等信息。
Browse files Browse the repository at this point in the history
  • Loading branch information
Codespilot committed Mar 3, 2024
1 parent 598389c commit e4cd204
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 5 deletions.
110 changes: 110 additions & 0 deletions Source/Starfish.Webapp/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,114 @@

@attribute [Authorize]

@inject IDashboardApi DashboardApi

<PageTitle>Home</PageTitle>

<FluentGrid>
<FluentGridItem lg="4" md="4" sm="6">
<FluentCard>
<FluentStack Orientation="Orientation.Horizontal">
<div>
<p>@Resources.IDS_HOME_LABEL_CONNECTIONS</p>
<h2>@ConnectionCount</h2>
</div>
<FluentSpacer />
<div>
<FluentIcon Value="@(new Icons.Regular.Size28.PlugDisconnected())" />
</div>
</FluentStack>
</FluentCard>
</FluentGridItem>
<FluentGridItem lg="4" md="4" sm="6">
<FluentCard>
<FluentStack Orientation="Orientation.Horizontal">
<div>
<p>@Resources.IDS_HOME_LABEL_CONFIGURATIONS</p>
<h2>@ConfigurationItemCount<span>/</span>@ConfigurationCount</h2>
</div>
<FluentSpacer />
<div>
<FluentIcon Value="@(new Icons.Regular.Size28.Settings())" />
</div>
</FluentStack>
</FluentCard>
</FluentGridItem>
<FluentGridItem lg="4" md="4" sm="6">
<FluentCard>
<FluentStack Orientation="Orientation.Horizontal">
<div>
<p>@Resources.IDS_HOME_LABEL_TEAMS</p>
<h2>@TeamCount</h2>
</div>
<FluentSpacer />
<div>
<FluentIcon Value="@(new Icons.Regular.Size28.PeopleTeam())" />
</div>
</FluentStack>
</FluentCard>
</FluentGridItem>
</FluentGrid>

<FluentGrid>
<FluentGridItem lg="12">
<FluentCard>
<FluentDataGrid ItemsProvider="_provider" Pagination="Pagination" ItemSize="46"
GenerateHeader="GenerateHeaderOption.Sticky"
TGridItem="ConnectionInfoDto">
<PropertyColumn Class="data-grid-column" Title="@(Resources.IDS_HOME_COLUMN_CONNECTION_ID)" Property="@(c => c.ConnectionId)" />
@* <TemplateColumn Title="@(Resources.IDS_COMMON_COLUMN_ACTIONS)" Align="@Align.Center">
<FluentLabel>@context.ConfigurationId</FluentLabel>
</TemplateColumn> *@
<PropertyColumn Class="data-grid-column" Title="@(Resources.IDS_HOME_COLUMN_CONFIGURATION)" Property="@(c => c.ConfigurationId)" />
<PropertyColumn Class="data-grid-column" Title="@(Resources.IDS_HOME_COLUMN_CONNECTION_TYPE)" Property="@(c => c.ConnectionType)" />
<PropertyColumn Class="data-grid-column" Title="@(Resources.IDS_HOME_COLUMN_CONNECTED_TIME)" Property="@(c => c.ConnectedTime)" />
</FluentDataGrid>
</FluentCard>
</FluentGridItem>
</FluentGrid>

@code {

[CascadingParameter]
private Task<AuthenticationState> AuthenticationState { get; set; }

private UserPrincipal Identity { get; set; }

private int ConnectionCount { get; set; }

private int TeamCount { get; set; }

private int ConfigurationCount { get; set; }

private int ConfigurationItemCount { get; set; }

private GridItemsProvider<ConnectionInfoDto> _provider;

private PaginationState Pagination { get; } = new() { ItemsPerPage = Constants.Query.Count };

protected override async Task OnInitializedAsync()
{
var user = await AuthenticationState;

Identity = new UserPrincipal(user.User);

var tasks = new List<Task>
{
DashboardApi.GetConnectionCountAsync().ContinueWith(task => ConnectionCount= task.Result.EnsureSuccess()),
DashboardApi.GetTeamCountAsync().ContinueWith(task => TeamCount= task.Result.EnsureSuccess()),
DashboardApi.GetConfigurationCountAsync().ContinueWith(task=> ConfigurationCount = task.Result.EnsureSuccess()),
DashboardApi.GetConfigurationItemCountAsync().ContinueWith(task=> ConfigurationItemCount = task.Result.EnsureSuccess())
};
await Task.WhenAll(tasks).Guard();

_provider = async request =>
{
List<ConnectionInfoDto> items = null;
await DashboardApi.GetConnectionsListAsync(request.CancellationToken)
.EnsureSuccess(result => items = result, request.CancellationToken);
return GridItemsProviderResult.From(items, 0);
};
}

}
1 change: 0 additions & 1 deletion Source/Starfish.Webapp/Pages/User/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,4 @@
{
await DialogService.ShowDialogAsync<ResetPassword>(id, new DialogParameters { PreventDismissOnOverlayClick = true });
}

}
24 changes: 24 additions & 0 deletions Source/Starfish.Webapp/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,30 @@
<data name="IDS_CONFIG_SYNC_REDIS_DIALOG_TITLE" xml:space="preserve">
<value>Sync to Redis</value>
</data>
<data name="IDS_HOME_COLUMN_CONFIGURATION" xml:space="preserve">
<value>Configuration</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTED_TIME" xml:space="preserve">
<value>Connected Time</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTION_ID" xml:space="preserve">
<value>Connection Id</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTION_TYPE" xml:space="preserve">
<value>Connection Type</value>
</data>
<data name="IDS_HOME_LABEL_CONFIGURATIONS" xml:space="preserve">
<value>Configurations</value>
</data>
<data name="IDS_HOME_LABEL_CONFIGURATION_ITEMS" xml:space="preserve">
<value>Configuration items</value>
</data>
<data name="IDS_HOME_LABEL_CONNECTIONS" xml:space="preserve">
<value>Connections</value>
</data>
<data name="IDS_HOME_LABEL_TEAMS" xml:space="preserve">
<value>Teams</value>
</data>
<data name="IDS_LOGIN_BUTTON_TEXT_LOGIN" xml:space="preserve">
<value>Login</value>
</data>
Expand Down
24 changes: 24 additions & 0 deletions Source/Starfish.Webapp/Properties/Resources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,28 @@
<data name="IDS_CONFIG_DETAIL_DIALOG_LABEL_VERSION" xml:space="preserve">
<value>版本</value>
</data>
<data name="IDS_HOME_LABEL_CONFIGURATIONS" xml:space="preserve">
<value>配置</value>
</data>
<data name="IDS_HOME_LABEL_CONFIGURATION_ITEMS" xml:space="preserve">
<value>配置项</value>
</data>
<data name="IDS_HOME_LABEL_CONNECTIONS" xml:space="preserve">
<value>连接</value>
</data>
<data name="IDS_HOME_LABEL_TEAMS" xml:space="preserve">
<value>团队</value>
</data>
<data name="IDS_HOME_COLUMN_CONFIGURATION" xml:space="preserve">
<value>配置</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTED_TIME" xml:space="preserve">
<value>连接时间</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTION_TYPE" xml:space="preserve">
<value>连接方式</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTION_ID" xml:space="preserve">
<value>连接Id</value>
</data>
</root>
30 changes: 30 additions & 0 deletions Source/Starfish.Webapp/Properties/Resources.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,34 @@
<data name="IDS_CONFIG_INDEX_COLUMN_TEAM" xml:space="preserve">
<value>團隊</value>
</data>
<data name="IDS_HOME_LABEL_CONFIGURATIONS" xml:space="preserve">
<value>配置</value>
</data>
<data name="IDS_HOME_LABEL_CONFIGURATION_ITEMS" xml:space="preserve">
<value>配置項</value>
</data>
<data name="IDS_HOME_LABEL_CONNECTIONS" xml:space="preserve">
<value>連接</value>
</data>
<data name="IDS_HOME_LABEL_TEAMS" xml:space="preserve">
<value>團隊</value>
</data>
<data name="IDS_HOME_COLUMN_CONFIGURATION_ID" xml:space="preserve">
<value>配置Id</value>
</data>
<data name="IDS_HOME_COLUMN_CONFIGURATION_NAME" xml:space="preserve">
<value>配置名稱</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTION_ID" xml:space="preserve">
<value>連接Id</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTION_TYPE" xml:space="preserve">
<value>連接方式</value>
</data>
<data name="IDS_HOME_COLUMN_CONNECTED_TIME" xml:space="preserve">
<value>連接時間</value>
</data>
<data name="IDS_HOME_COLUMN_CONFIGURATION" xml:space="preserve">
<value>配置</value>
</data>
</root>
22 changes: 22 additions & 0 deletions Source/Starfish.Webapp/Rest/Defines/IDashboardApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Nerosoft.Starfish.Transit;
using Refit;

namespace Nerosoft.Starfish.Webapp.Rest;

public interface IDashboardApi
{
[Get("/api/dashboard/connections/count")]
Task<IApiResponse<int>> GetConnectionCountAsync(CancellationToken cancellationToken = default);

[Get("/api/dashboard/connections")]
Task<IApiResponse<List<ConnectionInfoDto>>> GetConnectionsListAsync(CancellationToken cancellationToken = default);

[Get("/api/dashboard/configurations/count")]
Task<IApiResponse<int>> GetConfigurationCountAsync(CancellationToken cancellationToken = default);

[Get("/api/dashboard/configurations/items/count")]
Task<IApiResponse<int>> GetConfigurationItemCountAsync(CancellationToken cancellationToken = default);

[Get("/api/dashboard/teams/count")]
Task<IApiResponse<int>> GetTeamCountAsync(CancellationToken cancellationToken = default);
}
3 changes: 2 additions & 1 deletion Source/Starfish.Webapp/Rest/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static IServiceCollection AddHttpClientApi(this IServiceCollection servic
.AddTransient(provider => provider.GetRestService<IUserApi>(HTTP_CLIENT_NAME))
.AddTransient(provider => provider.GetRestService<ITeamApi>(HTTP_CLIENT_NAME))
.AddTransient(provider => provider.GetRestService<IAdministratorApi>(HTTP_CLIENT_NAME))
.AddTransient(provider => provider.GetRestService<IConfigurationApi>(HTTP_CLIENT_NAME));
.AddTransient(provider => provider.GetRestService<IConfigurationApi>(HTTP_CLIENT_NAME))
.AddTransient(provider => provider.GetRestService<IDashboardApi>(HTTP_CLIENT_NAME));

services.AddHttpClient(HTTP_CLIENT_NAME, (provider, client) =>
{
Expand Down
6 changes: 3 additions & 3 deletions Source/Starfish.Webapp/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Starfish": {
"AppId": "starfish.webapp",
"AppSecret": "0oDjfcWJiO",
"Environment": "DEV",
"Id": "5lNc9zQGdG7",
"Name": "starfish/webapp/appsettings.dev",
"Secret": "0oDjfcWJiO",
"Host": "http://localhost:5229"
},
"Api": {
Expand Down

0 comments on commit e4cd204

Please sign in to comment.