77 lines
2.9 KiB
Plaintext
77 lines
2.9 KiB
Plaintext
@page "/media/collections"
|
|
@using ErsatzTV.Application.MediaCollections
|
|
@using ErsatzTV.Application.MediaCollections.Commands
|
|
@using ErsatzTV.Application.MediaCollections.Queries
|
|
@using ErsatzTV.Application.MediaCards
|
|
@inject IDialogService Dialog
|
|
@inject IMediator Mediator
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<MudTable Hover="true" Items="_data" Dense="true">
|
|
<ToolBarContent>
|
|
<MudText Typo="Typo.h6">Collections</MudText>
|
|
</ToolBarContent>
|
|
<ColGroup>
|
|
<col/>
|
|
<col style="width: 120px;"/>
|
|
</ColGroup>
|
|
<HeaderContent>
|
|
<MudTh>
|
|
<MudTableSortLabel SortBy="new Func<MediaCollectionViewModel, object>(x => x.Name)">
|
|
Name
|
|
</MudTableSortLabel>
|
|
</MudTh>
|
|
<MudTh/>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Name">@context.Name</MudTd>
|
|
<MudTd>
|
|
<div style="align-items: center; display: flex;">
|
|
<MudTooltip Text="Edit Collection">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit"
|
|
Link="@($"/media/collections/{context.Id}")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Delete Collection">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
|
OnClick="@(_ => DeleteMediaCollection(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
</div>
|
|
</MudTd>
|
|
</RowTemplate>
|
|
<PagerContent>
|
|
<MudTablePager/>
|
|
</PagerContent>
|
|
</MudTable>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Link="/media/collections/add" Class="mt-4">
|
|
Add Collection
|
|
</MudButton>
|
|
</MudContainer>
|
|
|
|
@code {
|
|
private List<MediaCollectionViewModel> _data;
|
|
|
|
protected override Task OnParametersSetAsync() => RefreshData();
|
|
|
|
private async Task RefreshData() =>
|
|
_data = await Mediator.Send(new GetAllCollections()).Map(list => list.OrderBy(vm => vm.Name).ToList());
|
|
|
|
private async Task DeleteMediaCollection(MediaCardViewModel vm)
|
|
{
|
|
if (vm is MediaCollectionViewModel collection)
|
|
{
|
|
var parameters = new DialogParameters { { "EntityType", "collection" }, { "EntityName", collection.Name } };
|
|
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall };
|
|
|
|
IDialogReference dialog = Dialog.Show<DeleteDialog>("Delete Collection", parameters, options);
|
|
DialogResult result = await dialog.Result;
|
|
if (!result.Cancelled)
|
|
{
|
|
await Mediator.Send(new DeleteCollection(collection.Id));
|
|
await RefreshData();
|
|
}
|
|
}
|
|
}
|
|
|
|
} |