Skip to content

Commit 1ca2b86

Browse files
authored
Merge pull request #209 from pticostaricags/development
Adding localization for MyVideoPlans. Converting to code-behind
2 parents 2565070 + cddba35 commit 1ca2b86

File tree

2 files changed

+76
-43
lines changed

2 files changed

+76
-43
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@page "/Creator/MyVideoPlans"
2-
@implements IDisposable
2+
@implements IAsyncDisposable
33

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

@@ -9,62 +9,31 @@
99
@using FairPlayCombined.Interfaces.FairPlayTube
1010
@using FairPlayCombined.Models.FairPlayTube.VideoInfo
1111
@using FairPlayCombined.Models.FairPlayTube.VideoPlan
12+
@using FairPlayTube.SharedUI.Components.Paginators
1213
@using FairPlayTube.SharedUI.Components.Spinners
1314
@using Google.Apis.YouTube.v3.Data
1415

15-
@inject IVideoPlanService videoPlanService
16-
@inject IToastService toastService
17-
@inject IUserProviderService userProviderService
18-
@inject ILogger<MyVideoPlans> logger
16+
<PageTitle>
17+
@Localizer![MyVideoPlansTextKey]
18+
</PageTitle>
1919

2020
<FluentLabel Typo="Typography.H3">
21-
My Video Plans
21+
@Localizer![MyVideoPlansTextKey]
2222
</FluentLabel>
2323
<LoadingIndicator ShowSpinners="this.IsBusy"></LoadingIndicator>
2424

2525

2626
<FluentDataGrid ItemsProvider="this.itemsProvider">
2727
<TemplateColumn>
2828
<FluentAnchor data-enhance-nav="false"
29-
data-bs-toggle="tooltip" data-bs-placement="top" title="Edit"
29+
data-bs-toggle="tooltip" data-bs-placement="top" title="@Localizer![EditTextKey]"
3030
IconStart="@(new Icons.Regular.Size20.Edit())"
3131
Href="@($"/Creator/UpdateVideoPlan/{context.VideoPlanId}")">
32-
Edit
32+
@Localizer![EditTextKey]
3333
</FluentAnchor>
3434
</TemplateColumn>
35-
<PropertyColumn Property="@(p=>p.VideoName)"></PropertyColumn>
36-
<PropertyColumn Property="@(p=>p.VideoDescription)"></PropertyColumn>
37-
<PropertyColumn Property="@(p=>p.VideoScript)"></PropertyColumn>
35+
<PropertyColumn Property="@(p=>p.VideoName)" Title="@Localizer![VideoNameTextKey]"></PropertyColumn>
36+
<PropertyColumn Property="@(p=>p.VideoDescription)" Title="@Localizer![VideoDescriptionTextKey]"></PropertyColumn>
37+
<PropertyColumn Property="@(p=>p.VideoScript)" Title="@Localizer![VideoScriptTextKey]"></PropertyColumn>
3838
</FluentDataGrid>
39-
<FluentPaginator State="this.paginationState"></FluentPaginator>
40-
@code {
41-
private readonly CancellationTokenSource cancellationTokenSource = new();
42-
private bool IsBusy { get; set; }
43-
private readonly PaginationState paginationState = new()
44-
{
45-
ItemsPerPage = Constants.Pagination.PageSize
46-
};
47-
private GridItemsProvider<VideoPlanModel>? itemsProvider;
48-
49-
protected override void OnInitialized()
50-
{
51-
this.itemsProvider = async req =>
52-
{
53-
this.IsBusy = true;
54-
StateHasChanged();
55-
var items = await this.videoPlanService.GetPaginatedVideoPlanAsync(paginationRequest: new()
56-
{
57-
PageSize = paginationState.ItemsPerPage
58-
}, cancellationToken:this.cancellationTokenSource.Token);
59-
this.IsBusy = false;
60-
StateHasChanged();
61-
var result = GridItemsProviderResult.From<VideoPlanModel>(items!.Items!, items.TotalItems);
62-
return result;
63-
};
64-
}
65-
66-
void IDisposable.Dispose()
67-
{
68-
this.cancellationTokenSource.Dispose();
69-
}
70-
}
39+
<CustomFluentPaginator State="@this.paginationState"></CustomFluentPaginator>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using FairPlayCombined.Common;
2+
using FairPlayCombined.Common.CustomAttributes;
3+
using FairPlayCombined.Interfaces;
4+
using FairPlayCombined.Interfaces.FairPlayTube;
5+
using FairPlayCombined.Models.FairPlayTube.VideoPlan;
6+
using Microsoft.AspNetCore.Components;
7+
using Microsoft.Extensions.Localization;
8+
using Microsoft.Extensions.Logging;
9+
using Microsoft.FluentUI.AspNetCore.Components;
10+
11+
namespace FairPlayTube.SharedUI.Components.Pages.Creator
12+
{
13+
public partial class MyVideoPlans
14+
{
15+
[Inject] IVideoPlanService? VideoPlanService { get; set; }
16+
[Inject] IToastService? ToastService { get; set; }
17+
[Inject] IUserProviderService? UserProviderService { get; set; }
18+
[Inject] ILogger<MyVideoPlans>? Logger { get; set; }
19+
[Inject] IStringLocalizer<MyVideoPlans>? Localizer { get; set; }
20+
private readonly CancellationTokenSource cancellationTokenSource = new();
21+
private bool IsBusy { get; set; }
22+
private readonly PaginationState paginationState = new()
23+
{
24+
ItemsPerPage = Constants.Pagination.PageSize
25+
};
26+
private GridItemsProvider<VideoPlanModel>? itemsProvider;
27+
28+
protected override void OnInitialized()
29+
{
30+
this.itemsProvider = async req =>
31+
{
32+
this.IsBusy = true;
33+
StateHasChanged();
34+
var items = await this.VideoPlanService!.GetPaginatedVideoPlanAsync(paginationRequest: new()
35+
{
36+
PageSize = paginationState.ItemsPerPage
37+
}, cancellationToken: this.cancellationTokenSource.Token);
38+
this.IsBusy = false;
39+
StateHasChanged();
40+
var result = GridItemsProviderResult.From<VideoPlanModel>(items!.Items!, items.TotalItems);
41+
return result;
42+
};
43+
}
44+
45+
public async ValueTask DisposeAsync()
46+
{
47+
await this.cancellationTokenSource.CancelAsync();
48+
this.cancellationTokenSource.Dispose();
49+
}
50+
51+
#region Resource Keys
52+
[ResourceKey(defaultValue: "My Video Plans")]
53+
public const string MyVideoPlansTextKey = "MyVideoPlansText";
54+
[ResourceKey(defaultValue: "Edit")]
55+
public const string EditTextKey = "EditText";
56+
[ResourceKey(defaultValue: "Video Name")]
57+
public const string VideoNameTextKey = "VideoNameText";
58+
[ResourceKey(defaultValue: "Video Description")]
59+
public const string VideoDescriptionTextKey = "VideoDescriptionText";
60+
[ResourceKey(defaultValue: "Video Script")]
61+
public const string VideoScriptTextKey = "VideoScriptText";
62+
#endregion Resource Keys
63+
}
64+
}

0 commit comments

Comments
 (0)