91 lines
3.5 KiB
Plaintext
91 lines
3.5 KiB
Plaintext
@page "/media/collections"
|
|
@using Microsoft.Extensions.Caching.Memory
|
|
@using Blazored.LocalStorage
|
|
@using ErsatzTV.Application.MediaCollections
|
|
@using ErsatzTV.Application.MediaCollections.Commands
|
|
@using ErsatzTV.Application.MediaCollections.Queries
|
|
@using ErsatzTV.Application.MediaCards
|
|
@inject IDialogService Dialog
|
|
@inject IMediator Mediator
|
|
@inject IMemoryCache MemoryCache
|
|
@inject ILocalStorageService LocalStorage
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<MudTable Hover="true"
|
|
ServerData="@(new Func<TableState, Task<TableData<MediaCollectionViewModel>>>(ServerReload))"
|
|
Dense="true"
|
|
@ref=" _table">
|
|
<ToolBarContent>
|
|
<MudText Typo="Typo.h6">Collections</MudText>
|
|
</ToolBarContent>
|
|
<ColGroup>
|
|
<col/>
|
|
<col style="width: 120px;"/>
|
|
</ColGroup>
|
|
<HeaderContent>
|
|
<MudTh>Name</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 MudTable<MediaCollectionViewModel> _table;
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
int rowsPerPage = await LocalStorage.GetItemAsync<int?>("pages.collections.rows_per_page") ?? 10;
|
|
_table.RowsPerPage = rowsPerPage;
|
|
await _table.ReloadServerData();
|
|
}
|
|
|
|
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 _table.ReloadServerData();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private async Task<TableData<MediaCollectionViewModel>> ServerReload(TableState state)
|
|
{
|
|
await LocalStorage.SetItemAsync<int?>("pages.collections.rows_per_page", state.PageSize);
|
|
|
|
PagedMediaCollectionsViewModel data = await Mediator.Send(new GetPagedCollections(state.Page, state.PageSize));
|
|
return new TableData<MediaCollectionViewModel> { TotalItems = data.TotalCount, Items = data.Page };
|
|
}
|
|
|
|
} |