Skip to content

Commit de0bde6

Browse files
authored
Merge pull request #207 from pticostaricags/development
Adding localization for MyVideoViewers. Converting to code-behind.
2 parents 3364bb3 + f13bca0 commit de0bde6

File tree

2 files changed

+79
-50
lines changed

2 files changed

+79
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@attribute [Route($"{Constants.Routes.FairPlayTubeRoutes.CreatorRoutes.MyVideoViewers}/{{VideoId}}")]
2-
@implements IDisposable
2+
@implements IAsyncDisposable
33

44
@attribute [Authorize(Roles = FairPlayCombined.Common.Constants.RoleName.BasicPlanUser)]
55

@@ -9,71 +9,30 @@
99
@using FairPlayCombined.Models.FairPlayTube.VideoInfo
1010
@using FairPlayCombined.Models.FairPlayTube.VideoViewer
1111
@using FairPlayCombined.Models.Pagination
12+
@using FairPlayTube.SharedUI.Components.Paginators
1213
@using FairPlayTube.SharedUI.Components.Spinners
1314

14-
@inject IVideoViewerService videoViewerService
15-
@inject IUserProviderService userProviderService
16-
<PageTitle>My Video Viewers</PageTitle>
15+
16+
<PageTitle>@Localizer![MyVideoViewersTextKey]</PageTitle>
1717

1818
<LoadingIndicator ShowSpinners="this.IsBusy"></LoadingIndicator>
1919

2020
<div class="@ThemeConfiguration.Grids.GridContainerCss">
2121
<FluentDataGrid ItemsProvider="ItemsProvider" Pagination="this.paginationState">
22-
<TemplateColumn Class="multiline-text">
22+
<TemplateColumn Class="multiline-text" Title="@Localizer![UserTextKey]">
2323
@if (String.IsNullOrWhiteSpace(context.Username))
2424
{
25-
<FluentLabel>Anonymous</FluentLabel>
25+
<FluentLabel>@Localizer![AnonymousTextKey]</FluentLabel>
2626
}
2727
else
2828
{
2929
<FluentLabel>@context.Username</FluentLabel>
3030
}
3131
</TemplateColumn>
32-
<TemplateColumn Title="@nameof(VideoViewerModel.TotalTimeWatched)">
32+
<TemplateColumn Title="@Localizer![TotalTimeWatchedTextKey]">
3333
@TimeSpan.FromSeconds(context.TotalTimeWatched)
3434
</TemplateColumn>
35-
<PropertyColumn Property="@( p=> p.TotalSessions)"></PropertyColumn>
35+
<PropertyColumn Property="@( p=> p.TotalSessions)" Title="@Localizer![TotalSessionsTextKey]"></PropertyColumn>
3636
</FluentDataGrid>
3737
</div>
38-
<FluentPaginator State="this.paginationState"></FluentPaginator>
39-
40-
@code
41-
{
42-
[Parameter]
43-
public string? VideoId { get; set; }
44-
private bool IsBusy { get; set; }
45-
private GridItemsProvider<VideoViewerModel>? ItemsProvider;
46-
private readonly PaginationState paginationState = new()
47-
{
48-
ItemsPerPage = Constants.Pagination.PageSize
49-
};
50-
private readonly CancellationTokenSource cancellationTokenSource = new();
51-
52-
protected override void OnInitialized()
53-
{
54-
this.IsBusy = true;
55-
ItemsProvider = async req =>
56-
{
57-
StateHasChanged();
58-
PaginationRequest paginationRequest = new()
59-
{
60-
PageSize = paginationState.ItemsPerPage,
61-
StartIndex = req.StartIndex
62-
};
63-
var items = await videoViewerService
64-
.GetPaginatedVideoViewerInfoForUserIdAsync(paginationRequest,
65-
videoId: this.VideoId!,
66-
userId: this.userProviderService!.GetCurrentUserId()!,
67-
this.cancellationTokenSource.Token);
68-
StateHasChanged();
69-
var result = GridItemsProviderResult.From<VideoViewerModel>(items!.Items!, items.TotalItems);
70-
return result;
71-
};
72-
this.IsBusy = false;
73-
}
74-
75-
void IDisposable.Dispose()
76-
{
77-
this.cancellationTokenSource.Dispose();
78-
}
79-
}
38+
<CustomFluentPaginator State="@this.paginationState"></CustomFluentPaginator>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using FairPlayCombined.Common;
2+
using FairPlayCombined.Common.CustomAttributes;
3+
using FairPlayCombined.Interfaces;
4+
using FairPlayCombined.Interfaces.FairPlayTube;
5+
using FairPlayCombined.Models.FairPlayTube.VideoViewer;
6+
using FairPlayCombined.Models.Pagination;
7+
using Microsoft.AspNetCore.Components;
8+
using Microsoft.Extensions.Localization;
9+
using Microsoft.FluentUI.AspNetCore.Components;
10+
11+
namespace FairPlayTube.SharedUI.Components.Pages.Creator
12+
{
13+
public partial class MyVideoViewers
14+
{
15+
[Parameter]
16+
public string? VideoId { get; set; }
17+
[Inject] IVideoViewerService? VideoViewerService { get; set; }
18+
[Inject] IUserProviderService? UserProviderService { get; set; }
19+
[Inject] IStringLocalizer<MyVideoViewers>? Localizer { get; set; }
20+
private bool IsBusy { get; set; }
21+
private GridItemsProvider<VideoViewerModel>? ItemsProvider;
22+
private readonly PaginationState paginationState = new()
23+
{
24+
ItemsPerPage = Constants.Pagination.PageSize
25+
};
26+
private readonly CancellationTokenSource cancellationTokenSource = new();
27+
28+
protected override void OnInitialized()
29+
{
30+
this.IsBusy = true;
31+
ItemsProvider = async req =>
32+
{
33+
StateHasChanged();
34+
PaginationRequest paginationRequest = new()
35+
{
36+
PageSize = paginationState.ItemsPerPage,
37+
StartIndex = req.StartIndex
38+
};
39+
var items = await VideoViewerService!
40+
.GetPaginatedVideoViewerInfoForUserIdAsync(paginationRequest,
41+
videoId: this.VideoId!,
42+
userId: this.UserProviderService!.GetCurrentUserId()!,
43+
this.cancellationTokenSource.Token);
44+
StateHasChanged();
45+
var result = GridItemsProviderResult.From<VideoViewerModel>(items!.Items!, items.TotalItems);
46+
return result;
47+
};
48+
this.IsBusy = false;
49+
}
50+
51+
public async ValueTask DisposeAsync()
52+
{
53+
await this.cancellationTokenSource.CancelAsync();
54+
this.cancellationTokenSource.Dispose();
55+
}
56+
57+
#region Resource Keys
58+
[ResourceKey(defaultValue: "My Video Viewers")]
59+
public const string MyVideoViewersTextKey = "MyVideoViewersText";
60+
[ResourceKey(defaultValue: "User")]
61+
public const string UserTextKey = "UserText";
62+
[ResourceKey(defaultValue: "Anonymous")]
63+
public const string AnonymousTextKey = "AnonymousText";
64+
[ResourceKey(defaultValue: "Total Time Watched")]
65+
public const string TotalTimeWatchedTextKey = "TotalTimeWatchedText";
66+
[ResourceKey(defaultValue: "Total Sessions")]
67+
public const string TotalSessionsTextKey = "TotalSessionsText";
68+
#endregion Resource Keys
69+
}
70+
}

0 commit comments

Comments
 (0)