Skip to content

Commit

Permalink
Added interfaces
Browse files Browse the repository at this point in the history
Some minor changes
Added some basic tests
Added DI registration automation
Fixed frontend
  • Loading branch information
Aragas committed Feb 18, 2024
1 parent 44dd8ee commit 3db5f25
Show file tree
Hide file tree
Showing 103 changed files with 1,398 additions and 500 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup
uses: butr/actions-common-setup@v2.1
uses: butr/actions-common-setup@v2
with:
fetch-depth: 0
github-token: ${{secrets.GITHUB_TOKEN}}
Expand Down
32 changes: 16 additions & 16 deletions src/BUTR.Site.NexusMods.Client/BUTR.Site.NexusMods.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
-->

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
<PackageReference Include="Blazorise.Bootstrap5" Version="1.4.0" />
<PackageReference Include="Blazorise.Charts" Version="1.4.0" />
<PackageReference Include="Blazorise.Components" Version="1.4.0" />
<PackageReference Include="Blazorise.DataGrid" Version="1.4.0" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.4.0" />
<PackageReference Include="Blazorise.LoadingIndicator" Version="1.4.0" />
<PackageReference Include="Blazorise.QRCode" Version="1.4.0" />
<PackageReference Include="Blazorise.Snackbar" Version="1.4.0" />
<PackageReference Include="Blazorise.TreeView" Version="1.4.0" />
<PackageReference Include="BUTR.CrashReport.Models" Version="13.0.0.47" />
<PackageReference Include="BUTR.CrashReport.Bannerlord.Parser" Version="13.0.0.47" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.0" />
<PackageReference Include="Blazorise.Bootstrap5" Version="1.4.2" />
<PackageReference Include="Blazorise.Charts" Version="1.4.2" />
<PackageReference Include="Blazorise.Components" Version="1.4.2" />
<PackageReference Include="Blazorise.DataGrid" Version="1.4.2" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.4.2" />
<PackageReference Include="Blazorise.LoadingIndicator" Version="1.4.2" />
<PackageReference Include="Blazorise.QRCode" Version="1.4.2" />
<PackageReference Include="Blazorise.Snackbar" Version="1.4.2" />
<PackageReference Include="Blazorise.TreeView" Version="1.4.2" />
<PackageReference Include="BUTR.CrashReport.Models" Version="13.0.0.48" />
<PackageReference Include="BUTR.CrashReport.Bannerlord.Parser" Version="13.0.0.48" />
<PackageReference Include="CsvHelper" Version="31.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<DataGridColumn TItem="TItem" Field="@Field" Caption="@Caption" Filterable="@Filterable" SortField="@SortField" Sortable="@Sortable" DisplayTemplate="@DisplayTemplate" @attributes="@AdditionalAttributes">
<FilterTemplate>
<TextEdit ElementId="@ElementId" TextChanged="@(x => { context.TriggerFilterChange(x); })" Placeholder="@Placeholder" Debounce="true" DebounceInterval="500" />
<TextEdit ElementId="@ElementId" TextChanged="@(value => { OnInputChanged(value, context); })" Placeholder="@Placeholder" Debounce="true" DebounceInterval="500" />
</FilterTemplate>
</DataGridColumn>

Expand Down Expand Up @@ -35,4 +35,9 @@
[Parameter]
public RenderFragment<TItem>? DisplayTemplate { get; set; }

private void OnInputChanged(string value, FilterContext<TItem> context)
{
context.TriggerFilterChange(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@

private async Task LoadItems(int page, int pageSize, ICollection<Filtering> filterings, ICollection<Sorting> sortings, CancellationToken ct = default)
{
await using var progress = ProgressUtils.DoProgress(x => _progressValue = x, () => _progressValue, () => InvokeAsync(StateHasChanged));
await using var progress = ProgressUtils.DoProgress(x => _progressValue = x, () => _progressValue, () => InvokeAsync(StateHasChanged), ct);
var response = (GetItems is not null ? await GetItems(page, pageSize, filterings, sortings, ct) : null) ?? new(PagingMetadata.Empty, Array.Empty<TItem>(), PagingAdditionalMetadata.Empty);
Metadata = response.Metadata;
Values = response.Items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
Data="@Values"
SelectedRowChanged="@(model => { DataGridUtils.SelectDeselect(model, ref Value, ref _dataGridRef); })"
ReadData="@OnReadData"
TotalItems="@Metadata.TotalCount"
CurrentPage="@Metadata.CurrentPage"
PageSize="@Metadata.PageSize"
PageSizes="@PageSizes"
TotalItems="@Metadata.TotalCount"
SelectionMode="@DataGridSelectionMode.Single"
ShowPager
ShowPageSizes
PagerOptions="@(new DataGridPagerOptions { PaginationPosition = PagerElementPosition.Center, ButtonRowPosition = PagerElementPosition.Start, TotalItemsPosition = PagerElementPosition.End })"
PageSizes="@PageSizes"
Filterable="@Filterable"
CustomFilter="@OnCustomFilter"
Sortable="@Sortable"
SortChanged="@(async args => await OnSortChanged(args))"
Responsive
Editable="@Editable"
EditMode="@EditMode"
Expand All @@ -25,7 +26,8 @@
DataGridColumns="@DataGridColumns"
ButtonRowTemplate="@ButtonRowTemplate"
DetailRowTemplate="@DetailRowTemplate"
DetailRowTrigger="@DetailRowTrigger">
DetailRowTrigger="@DetailRowTrigger"
FixedHeader="@FixedHeader">
<TotalItemsTemplate>
@if (Metadata.TotalCount == 0)
{
Expand Down Expand Up @@ -67,6 +69,9 @@
[Parameter]
public bool Sortable { get; set; } = false;

[Parameter]
public bool FixedHeader { get; set; } = false;

[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object>? AdditionalAttributes { get; set; }

Expand Down Expand Up @@ -110,6 +115,7 @@

private DataGrid<TItem> _dataGridRef = default!;
private Progress _progressRef = default!;
private CancellationTokenSource _loadCancellationTokenSource = new();

public DataGridStreamingPaging()
{
Expand All @@ -122,28 +128,37 @@
Metadata = new(1, 0, await GetPageSizeInternal(), 0);
}

public Task Reload() => _dataGridRef.Reload();
public async Task Reload()
{
await _dataGridRef.Reload();
}

private async Task OnReadData(DataGridReadDataEventArgs<TItem> e)
{
if (e.CancellationToken.IsCancellationRequested)
return;

_loadCancellationTokenSource.Dispose();
_loadCancellationTokenSource = new();
var cts = CancellationTokenSource.CreateLinkedTokenSource(e.CancellationToken, _loadCancellationTokenSource.Token);
cts.Token.Register(() => _loadCancellationTokenSource.Dispose());

var sortings = e.Columns
.Where(x => x.SortIndex != -1)
.OrderBy(x => x.SortIndex)
.Select(x => new Sorting(x.SortField, x.SortDirection.ToSortingType()))
.ToArray();
var filterings = GetFilters is not null ? GetFilters(e.Columns).ToArray() : Array.Empty<Filtering>();

await LoadItems(e.Page, e.PageSize, filterings, sortings, e.CancellationToken);
Metadata = Metadata with { CurrentPage = e.Page, PageSize = e.PageSize };
await LoadItems(e.Page, e.PageSize, filterings, sortings, cts.Token);
}

private async Task LoadItems(int page, int pageSize, ICollection<Filtering> filterings, ICollection<Sorting> sortings, CancellationToken ct = default)
{
try
{
await using var progress = ProgressUtils.DoProgress(x => _progressValue = x, () => _progressValue, () => InvokeAsync(StateHasChanged));
await using var progress = ProgressUtils.DoProgress(x => _progressValue = x, () => _progressValue, () => InvokeAsync(StateHasChanged), ct);

Values.Clear();
StateHasChanged();
Expand Down Expand Up @@ -179,6 +194,11 @@
return GetPageSize?.Invoke(userSettings) ?? userSettings.PageSize;
}

private static bool OnCustomFilter(TItem model) => true;
private async Task OnSortChanged(DataGridSortChangedEventArgs args)
{
await _loadCancellationTokenSource.CancelAsync();
await Task.Delay(300);
await _dataGridRef.Reload();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

private async Task<DataGridPaging<QuartzExecutionLogEntity>.ItemsResponse?> Paging(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct)
{
var response = await _quartzClient.HistoryPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), cancellationToken: ct);
var response = await _quartzClient.HistoryPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), cancellationToken: ct);
return response is { Value: { } data } ? new(data.Metadata, data.Items, data.AdditionalMetadata) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

private async Task<DataGridPaging<NexusModsUserToModuleManualLinkModel>.ItemsResponse?> GetAllowUserMods(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct)
{
var response = await _userClient.ToModuleManualLinkPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), cancellationToken: ct);
var response = await _userClient.ToModuleManualLinkPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), cancellationToken: ct);
return response is { Value: { } data } ? new(data.Metadata, data.Items, data.AdditionalMetadata) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

private async Task<DataGridPaging<NexusModsModToModuleModel>.ItemsResponse?> GetManualLinks(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct)
{
var response = await _modClient.ToModuleManualLinkPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), cancellationToken: ct);
var response = await _modClient.ToModuleManualLinkPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), cancellationToken: ct);
return response is { Value: { } data } ? new(data.Metadata, data.Items, data.AdditionalMetadata) : null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/BUTR.Site.NexusMods.Client/Pages/Tools/Articles.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

private async Task<DataGridPaging<NexusModsArticleModel>.ItemsResponse?> GetArticles(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct = default)
{
var response = await _articlesClient.PaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), cancellationToken: ct);
var response = await _articlesClient.PaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), cancellationToken: ct);
return response is { Value: { } data } ? new(data.Metadata, data.Items, data.AdditionalMetadata) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

private async Task<DataGridPaging<ExposedNexusModsModModel>.ItemsResponse?> GetExposedMods(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct = default)
{
var response = await _exposedModsClient.PaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), cancellationToken: ct);
var response = await _exposedModsClient.PaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), cancellationToken: ct);
return response is { Value: { } data } ? new(data.Metadata, data.Items, data.AdditionalMetadata) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

private async Task<DataGridPaging<NexusModsUserToNexusModsModManualLinkModel>.ItemsResponse?> GetAllowUserMods(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct)
{
var response = await _userClient.ToNexusModsModManualLinkPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), cancellationToken: ct);
var response = await _userClient.ToNexusModsModManualLinkPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), cancellationToken: ct);
return response is { Value: { } data } ? new(data.Metadata, data.Items, data.AdditionalMetadata) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@inject ICrashReportsClient _crashReportsClient
@inject IJSRuntime _jsRuntime;

<Modal @ref="_modalRef">
<Modal @ref="@_modalRef">
<ModalContent Size="@ModalSize.ExtraLarge" Centered>
<ModalHeader>
<ModalTitle>Crash Report Entry</ModalTitle>
Expand Down Expand Up @@ -57,15 +57,15 @@

<Card Margin="@Margin.Is4" Overflow="@Overflow.Auto">
<CardHeader>
<CardTitle Size="4" Position="Position.Relative" Margin="@Margin.Is0">
<CardTitle Size="4" Position="@Position.Relative" Margin="@Margin.Is0">
Crash Reports
<Button Position="@Position.Absolute.Bottom.Is0.End.Is0.Translate.MiddleX" Clicked="@Refresh" Padding="@Padding.Is0" >
<Icon Name="@Enum.GetName(IconName.Sync)" />
</Button>
</CardTitle>
</CardHeader>
<CardBody>
<DataGridStreamingPaging @ref="@_datagridPagingRef" TItem="CrashReportModel2" GetFilters="@GetFilters" GetItems="@GetCrashReports" Sortable Filterable DefaultPageSize="@UserSettings.DefaultCrashReportPageSize" PageSizes="@UserSettings.AvailableCrashReportPageSizes" GetPageSize="@(x => x.CrashReportPageSize)">
<DataGridStreamingPaging @ref="@_datagridPagingRef" TItem="CrashReportModel2" GetFilters="@GetFilters" GetItems="@GetCrashReports" Sortable Filterable DefaultPageSize="@UserSettings.DefaultCrashReportPageSize" PageSizes="@UserSettings.AvailableCrashReportPageSizes" GetPageSize="@(x => x.CrashReportPageSize)" FixedHeader>
<DataGridColumns>
<DataGridColumnText TItem="CrashReportModel2" ElementId="game-version" Field="@nameof(CrashReportModel2.GameVersion)" Caption="Game Version" Filterable Placeholder="v1.0.0" Sortable SortField="@nameof(EntityFields.GameVersion)"/>
<DataGridColumnTextAutocomplete TItem="CrashReportModel2" Field="@nameof(CrashReportModel2.InvolvedModules)" Caption="Top Involved Module" Filterable Sortable SortField="@nameof(EntityFields.TopInvolvedModuleId)" MinLength="3" GetAutocompleteValues="@GetAutocompleteValues">
Expand Down Expand Up @@ -114,11 +114,11 @@
var updatedCrashReport = _datagridPagingRef.Value with { };
if (await _crashReportsClient.UpdateAsync(updatedCrashReport) is { Error: not null })
{
await _notificationService.Success($"Saved Crash Report!", "Success!");
await _notificationService.Success("Saved Crash Report!", "Success!");
}
else
{
await _notificationService.Error($"Failed to save Crash Report!", "Error!");
await _notificationService.Error("Failed to save Crash Report!", "Error!");
}
}
}
Expand All @@ -131,7 +131,7 @@

private async Task<PagingStreamingData<CrashReportModel2>?> GetCrashReports(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct = default)
{
return await _crashReportsClient.PaginatedStreamingAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), ct);
return await _crashReportsClient.PaginatedStreamingAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), ct);
}

private async Task<ICollection<string>> GetAutocompleteValues(string filter, CancellationToken ct) => await _crashReportsClient.AutocompleteAsync(new(filter), ct) is { Value: { } data } ? data : Array.Empty<string>();
Expand Down
4 changes: 2 additions & 2 deletions src/BUTR.Site.NexusMods.Client/Pages/User/Mods.razor
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@

private async Task<DataGridPaging<NexusModsModModel>.ItemsResponse?> GetMods(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct = default)
{
var response = await _userClient.ToNexusModsModPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), cancellationToken: ct);
var response = await _userClient.ToNexusModsModPaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), cancellationToken: ct);
return response is { Value: { } data } ? new(data.Metadata, data.Items, data.AdditionalMetadata) : null;
}

private async Task<DataGridPaging<NexusModsModAvailableModel>.ItemsResponse?> GetAllowedMods(int page, int pageSize, ICollection<Filtering> filters, ICollection<Sorting> sortings, CancellationToken ct = default)
{
var response = await _modClient.AvailablePaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sotings: sortings), cancellationToken: ct);
var response = await _modClient.AvailablePaginatedAsync(new(page: page, pageSize: pageSize, filters: filters, sortings: sortings), cancellationToken: ct);
return response is { Value: { } data } ? new(data.Metadata, data.Items, data.AdditionalMetadata) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<PagingStreamingData<CrashReportModel2>> PaginatedStreamingAsyn
return PagingStreamingData<CrashReportModel2>.Create(new PagingMetadata(1, (int) Math.Ceiling((double) crashReports.Count / body.PageSize), body.PageSize, crashReports.Count), crashReports.ToAsyncEnumerable(), PagingAdditionalMetadata.Empty);
}

return await _implementation.PaginatedStreamingAsync(new PaginatedQuery(body.Page, body.PageSize, body.Filters, body.Sotings), ct);
return await _implementation.PaginatedStreamingAsync(new PaginatedQuery(body.Page, body.PageSize, body.Filters, body.Sortings), ct);
}

public async Task<CrashReportModel2PagingDataApiResultModel> PaginatedAsync(PaginatedQuery? body, CancellationToken ct)
Expand All @@ -64,7 +64,7 @@ public async Task<CrashReportModel2PagingDataApiResultModel> PaginatedAsync(Pagi
return new CrashReportModel2PagingDataApiResultModel(new CrashReportModel2PagingData(PagingAdditionalMetadata.Empty, crashReports, new PagingMetadata(1, (int) Math.Ceiling((double) crashReports.Count / body.PageSize), body.PageSize, crashReports.Count)), null!);
}

return await _implementation.PaginatedAsync(new PaginatedQuery(body.Page, body.PageSize, body.Filters, body.Sotings), ct);
return await _implementation.PaginatedAsync(new PaginatedQuery(body.Page, body.PageSize, body.Filters, body.Sortings), ct);
}

public async Task<StringIQueryableApiResultModel> AutocompleteAsync(string? modId, CancellationToken ct)
Expand Down
Loading

0 comments on commit 3db5f25

Please sign in to comment.