-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ability to list and update existent Video Plans
- Loading branch information
Showing
7 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/FairPlayCombinedSln/FairPlayTube/Components/Pages/Creator/MyVideoPlans.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
@page "/Creator/MyVideoPlans" | ||
@implements IDisposable | ||
|
||
@using FairPlayCombined.Common | ||
@using FairPlayCombined.Common.FairPlayTube.Enums | ||
@using FairPlayCombined.Interfaces | ||
@using FairPlayCombined.Models.FairPlayTube.VideoInfo | ||
@using FairPlayCombined.Models.FairPlayTube.VideoPlan | ||
@using FairPlayCombined.Services.Common | ||
@using FairPlayCombined.Services.FairPlayTube | ||
@using FairPlayTube.Components.Spinners | ||
@using Google.Apis.YouTube.v3.Data | ||
|
||
@attribute [Authorize] | ||
@rendermode RenderMode.InteractiveServer | ||
|
||
@inject VideoPlanService videoPlanService | ||
@inject IToastService toastService | ||
@inject IUserProviderService userProviderService | ||
@inject ILogger<MyVideoPlans> logger | ||
|
||
<FluentLabel Typo="Typography.H3"> | ||
My Video Plans | ||
</FluentLabel> | ||
<LoadingIndicator ShowSpinners="this.IsBusy"></LoadingIndicator> | ||
|
||
|
||
<FluentDataGrid ItemsProvider="this.itemsProvider"> | ||
<TemplateColumn> | ||
<FluentAnchor data-enhance-nav="false" | ||
data-bs-toggle="tooltip" data-bs-placement="top" title="Edit" | ||
IconStart="@(new Icons.Regular.Size20.Edit())" | ||
Href="@($"/Creator/UpdateVideoPlan/{context.VideoPlanId}")"> | ||
Edit | ||
</FluentAnchor> | ||
</TemplateColumn> | ||
<PropertyColumn Property="@(p=>p.VideoName)"></PropertyColumn> | ||
<PropertyColumn Property="@(p=>p.VideoDescription)"></PropertyColumn> | ||
<PropertyColumn Property="@(p=>p.VideoScript)"></PropertyColumn> | ||
</FluentDataGrid> | ||
<FluentPaginator State="this.paginationState"></FluentPaginator> | ||
@code { | ||
private readonly CancellationTokenSource cancellationTokenSource = new(); | ||
private bool IsBusy { get; set; } | ||
private PaginationState paginationState = new() | ||
{ | ||
ItemsPerPage = Constants.Pagination.PageSize | ||
}; | ||
private GridItemsProvider<VideoPlanModel>? itemsProvider; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
this.itemsProvider = async req => | ||
{ | ||
this.IsBusy = true; | ||
StateHasChanged(); | ||
var items = await this.videoPlanService.GetPaginatedVideoPlanAsync(paginationRequest: new() | ||
{ | ||
PageSize = paginationState.ItemsPerPage | ||
}, cancellationToken:this.cancellationTokenSource.Token); | ||
this.IsBusy = false; | ||
StateHasChanged(); | ||
var result = GridItemsProviderResult.From<VideoPlanModel>(items!.Items!, items.TotalItems); | ||
return result; | ||
}; | ||
} | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
this.cancellationTokenSource.Dispose(); | ||
} | ||
} |
164 changes: 164 additions & 0 deletions
164
src/FairPlayCombinedSln/FairPlayTube/Components/Pages/Creator/UpdateVideoPlan.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
@page "/Creator/UpdateVideoPlan/{VideoPlanId:long}" | ||
@implements IDisposable | ||
|
||
@using FairPlayCombined.Common | ||
@using FairPlayCombined.Common.FairPlayTube.Enums | ||
@using FairPlayCombined.Interfaces | ||
@using FairPlayCombined.Models.FairPlayTube.VideoInfo | ||
@using FairPlayCombined.Models.FairPlayTube.VideoPlan | ||
@using FairPlayCombined.Services.Common | ||
@using FairPlayCombined.Services.FairPlayTube | ||
@using FairPlayTube.Components.Spinners | ||
@using Google.Apis.YouTube.v3.Data | ||
@attribute [Authorize] | ||
@rendermode RenderMode.InteractiveServer | ||
|
||
@inject PromptGeneratorService promptGeneratorService | ||
@inject OpenAIService openAIService | ||
@inject AzureVideoIndexerServiceConfiguration azureVideoIndexerServiceConfiguration | ||
@inject AzureVideoIndexerService azureVideoIndexerService | ||
@inject VideoPlanService videoPlanService | ||
@inject IToastService toastService | ||
@inject IUserProviderService userProviderService | ||
@inject YouTubeClientService youTubeClientService | ||
@inject ILogger<CreateVideoPlan> logger | ||
@inject NavigationManager navigationManager | ||
|
||
<FluentLabel Typo="Typography.H3"> | ||
Update Video Plan | ||
</FluentLabel> | ||
<LoadingIndicator ShowSpinners="this.IsBusy"></LoadingIndicator> | ||
|
||
<FluentEditForm FormName="frmUpdateVideoPlan" Model="this.updateVideoPlanModel" | ||
OnValidSubmit="OnValidSubmitAsync"> | ||
<div> | ||
<DataAnnotationsValidator></DataAnnotationsValidator> | ||
<FluentValidationSummary></FluentValidationSummary> | ||
</div> | ||
<div> | ||
<FluentLabel Typo="Typography.Body">Name</FluentLabel> | ||
<FluentTextField @bind-Value="this.updateVideoPlanModel.VideoName" Maxlength="50" style="width:100%;"></FluentTextField> | ||
</div> | ||
<div> | ||
<FluentAccordion> | ||
<FluentAccordionItem Heading="Description" Expanded="true"> | ||
<FluentTextArea @bind-Value="this.updateVideoPlanModel.VideoDescription" Rows="10" Maxlength="500" style="width:100%;"></FluentTextArea> | ||
</FluentAccordionItem> | ||
</FluentAccordion> | ||
</div> | ||
<div> | ||
<FluentAccordion> | ||
<FluentAccordionItem Heading="Video Script" Expanded="true"> | ||
<FluentTextArea @bind-Value="this.updateVideoPlanModel.VideoScript" Rows="40" Maxlength="3000" style="width:100%;"></FluentTextArea> | ||
</FluentAccordionItem> | ||
</FluentAccordion> | ||
</div> | ||
<div> | ||
@if (!this.IsPlanCreated) | ||
{ | ||
<FluentButton Type="ButtonType.Submit">Save</FluentButton> | ||
} | ||
else | ||
{ | ||
<FluentLabel Typo="Typography.Body">Your Plan has been updated</FluentLabel> | ||
} | ||
</div> | ||
</FluentEditForm> | ||
|
||
<div> | ||
@if (!String.IsNullOrWhiteSpace(this.GeneratedYouTubeThumbnailUri)) | ||
{ | ||
<a data-enhance-nav="false" href="@this.GeneratedYouTubeThumbnailUri" target="_blank"> | ||
<img class="@ThemeConfiguration.Images.ThumbnailDefaultCss" src="@this.GeneratedYouTubeThumbnailUri" /> | ||
</a> | ||
<p> | ||
<FluentLabel Typo="Typography.Body"> | ||
@this.RevisedPrompt | ||
</FluentLabel> | ||
</p> | ||
} | ||
</div> | ||
|
||
@code { | ||
[Parameter] | ||
public long? VideoPlanId { get; set; } | ||
[SupplyParameterFromForm] | ||
private UpdateVideoPlanModel updateVideoPlanModel { get; set; } = new(); | ||
private readonly CancellationTokenSource cancellationTokenSource = new(); | ||
private bool IsBusy { get; set; } | ||
private string? GeneratedYouTubeThumbnailUri { get; set; } | ||
private string? RevisedPrompt { get; set; } | ||
private bool IsPlanCreated { get; set; } | ||
private VideoPlanModel? originalVideoPlan { get; set; } | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
try | ||
{ | ||
this.IsBusy = true; | ||
StateHasChanged(); | ||
this.updateVideoPlanModel.ApplicationUserId = this.userProviderService.GetCurrentUserId(); | ||
if (this.originalVideoPlan is null) | ||
{ | ||
this.originalVideoPlan = await this.videoPlanService.GetVideoPlanByIdAsync(this.VideoPlanId!.Value, this.cancellationTokenSource.Token); | ||
this.updateVideoPlanModel.VideoPlanId = this.VideoPlanId.Value; | ||
this.updateVideoPlanModel.VideoName = this.originalVideoPlan.VideoName; | ||
this.updateVideoPlanModel.VideoDescription = this.originalVideoPlan.VideoDescription; | ||
this.updateVideoPlanModel.VideoScript = this.originalVideoPlan.VideoScript; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
this.toastService.ShowError(ex.Message); | ||
} | ||
finally | ||
{ | ||
this.IsBusy = false; | ||
StateHasChanged(); | ||
} | ||
} | ||
|
||
private async Task OnValidSubmitAsync() | ||
{ | ||
try | ||
{ | ||
this.IsBusy = true; | ||
StateHasChanged(); | ||
await this.videoPlanService.UpdateVideoPlanAsync( | ||
this.updateVideoPlanModel, this.cancellationTokenSource.Token); | ||
this.toastService.ShowSuccess("Your Plan has been updated"); | ||
StateHasChanged(); | ||
this.IsPlanCreated = true; | ||
var promptInfo = await this.promptGeneratorService.GetPromptCompleteInfoAsync(promptName: | ||
"YouTubeThumbnail", cancellationToken: this.cancellationTokenSource.Token); | ||
string prompt = $"{promptInfo!.BaseText}. Video Title: {this.updateVideoPlanModel.VideoName}. Video Description: {this.updateVideoPlanModel.VideoDescription}. Video Script: {this.updateVideoPlanModel.VideoScript}"; | ||
if (prompt.Length > 4000) | ||
prompt = prompt.Substring(0, 4000); | ||
var result = await this.openAIService.GenerateDallE3ImageAsync(prompt, this.cancellationTokenSource.Token); | ||
if (result != null) | ||
{ | ||
this.GeneratedYouTubeThumbnailUri = result!.data![0]!.url!; | ||
this.RevisedPrompt = result!.data[0]!.revised_prompt; | ||
this.toastService.ShowSuccess("Your thumbnail has been created"); | ||
} | ||
else | ||
{ | ||
this.toastService.ShowError("Your thumbnail could not be created"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
this.toastService.ShowError(ex.Message); | ||
} | ||
finally | ||
{ | ||
this.IsBusy = false; | ||
StateHasChanged(); | ||
} | ||
} | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
this.cancellationTokenSource.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters