add smart collection editor to support renaming (#2253)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
<MudForm @ref="_form" @bind-IsValid="@_success" Style="max-height: 100%">
|
||||
<MudPaper Square="true" Style="display: flex; height: 64px; min-height: 64px; width: 100%; z-index: 100; align-items: center">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="ml-6" OnClick="HandleSubmitAsync" StartIcon="@(IsEdit ? Icons.Material.Filled.Save : Icons.Material.Filled.Add)">@(IsEdit ? "Save Collection" : "Add Collection")</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="ml-6" OnClick="@HandleSubmitAsync" StartIcon="@(IsEdit ? Icons.Material.Filled.Save : Icons.Material.Filled.Add)">@(IsEdit ? "Save Collection" : "Add Collection")</MudButton>
|
||||
</MudPaper>
|
||||
<div class="d-flex flex-column" style="height: 100vh; overflow-x: auto">
|
||||
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
||||
@@ -19,7 +19,7 @@
|
||||
<div class="d-flex">
|
||||
<MudText>Name</MudText>
|
||||
</div>
|
||||
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Required="true" RequiredError="Schedule name is required!"/>
|
||||
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Required="true" RequiredError="Collection name is required!"/>
|
||||
</MudStack>
|
||||
</MudContainer>
|
||||
</div>
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
<ColGroup>
|
||||
<MudHidden Breakpoint="Breakpoint.Xs">
|
||||
<col/>
|
||||
<col style="width: 120px;"/>
|
||||
<col style="width: 180px;"/>
|
||||
</MudHidden>
|
||||
</ColGroup>
|
||||
<HeaderContent>
|
||||
@@ -125,12 +125,17 @@
|
||||
<MudTd DataLabel="Name">@context.Name</MudTd>
|
||||
<MudTd>
|
||||
<div style="align-items: center; display: flex;">
|
||||
<MudTooltip Text="Edit Collection">
|
||||
<MudTooltip Text="Edit Smart Collection">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit"
|
||||
Href="@($"/media/smart-collections/{context.Id}/edit")">
|
||||
</MudIconButton>
|
||||
</MudTooltip>
|
||||
<MudTooltip Text="Search Smart Collection">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Search"
|
||||
Href="@context.Query.GetRelativeSearchQuery()">
|
||||
</MudIconButton>
|
||||
</MudTooltip>
|
||||
<MudTooltip Text="Delete Collection">
|
||||
<MudTooltip Text="Delete Smart Collection">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||
OnClick="@(_ => DeleteSmartCollection(context))">
|
||||
</MudIconButton>
|
||||
|
||||
@@ -950,6 +950,7 @@
|
||||
{
|
||||
var request = new UpdateSmartCollection(
|
||||
collectionResult.Item1.Id,
|
||||
collectionResult.Item1.Name,
|
||||
_query);
|
||||
|
||||
Either<BaseError, Unit> updateResult = await Mediator.Send(request, CancellationToken);
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
@page "/media/smart-collections/{Id:int}/edit"
|
||||
@using ErsatzTV.Application.MediaCollections
|
||||
@implements IDisposable
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject ILogger<CollectionEditor> Logger
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IMediator Mediator
|
||||
|
||||
<MudForm @ref="_form" @bind-IsValid="@_success" Style="max-height: 100%">
|
||||
<MudPaper Square="true" Style="display: flex; height: 64px; min-height: 64px; width: 100%; z-index: 100; align-items: center">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="ml-6" OnClick="@HandleSubmitAsync" StartIcon="@Icons.Material.Filled.Save">
|
||||
Save Smart Collection
|
||||
</MudButton>
|
||||
</MudPaper>
|
||||
<div class="d-flex flex-column" style="height: 100vh; overflow-x: auto">
|
||||
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
||||
<MudText Typo="Typo.h5" Class="mb-2">Smart Collection</MudText>
|
||||
<MudDivider Class="mb-6"/>
|
||||
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
|
||||
<div class="d-flex">
|
||||
<MudText>Name</MudText>
|
||||
</div>
|
||||
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Required="true" RequiredError="Smart collection name is required!"/>
|
||||
</MudStack>
|
||||
</MudContainer>
|
||||
</div>
|
||||
</MudForm>
|
||||
|
||||
@code {
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
private readonly SmartCollectionEditViewModel _model = new();
|
||||
private MudForm _form;
|
||||
private bool _success;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_cts.Cancel();
|
||||
_cts.Dispose();
|
||||
}
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
Option<SmartCollectionViewModel> maybeSmartCollection = await Mediator.Send(new GetSmartCollectionById(Id), _cts.Token);
|
||||
foreach (var smartCollection in maybeSmartCollection)
|
||||
{
|
||||
_model.Id = smartCollection.Id;
|
||||
_model.Name = smartCollection.Name;
|
||||
_model.Query = smartCollection.Query;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleSubmitAsync()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (_success)
|
||||
{
|
||||
Either<BaseError, Unit> result = await Mediator.Send(new UpdateSmartCollection(Id, _model.Name, _model.Query), _cts.Token);
|
||||
result.Match(
|
||||
_ => NavigationManager.NavigateTo("media/collections"),
|
||||
error =>
|
||||
{
|
||||
Snackbar.Add(error.Value, Severity.Error);
|
||||
Logger.LogError("Error saving smart collection: {Error}", error.Value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace ErsatzTV.ViewModels;
|
||||
|
||||
public class SmartCollectionEditViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Query { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user