@page "/media/collections" @using ErsatzTV.Application.MediaCollections @using ErsatzTV.Application.MediaCollections.Commands @using ErsatzTV.Application.MediaCollections.Queries @using ErsatzTV.Application.Configuration.Queries @using ErsatzTV.Application.Configuration.Commands @using ErsatzTV.Extensions @inject IDialogService _dialog @inject IMediator _mediator
Add Collection Add Multi Collection
Collections Name @context.Name
Multi Collections Name @context.Name
Smart Collections Name @context.Name
@code { private MudTable _collectionsTable; private MudTable _multiCollectionsTable; private MudTable _smartCollectionsTable; private int _collectionsRowsPerPage; private int _multiCollectionsRowsPerPage; private int _smartCollectionsRowsPerPage; protected override async Task OnParametersSetAsync() { _collectionsRowsPerPage = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.CollectionsPageSize)) .Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10)); _multiCollectionsRowsPerPage = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.MultiCollectionsPageSize)) .Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10)); _smartCollectionsRowsPerPage = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.SmartCollectionsPageSize)) .Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10)); } private async Task DeleteMediaCollection(MediaCollectionViewModel collection) { var parameters = new DialogParameters { { "EntityType", "collection" }, { "EntityName", collection.Name } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = _dialog.Show("Delete Collection", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled) { await _mediator.Send(new DeleteCollection(collection.Id)); await _collectionsTable.ReloadServerData(); } } private async Task DeleteMultiCollection(MultiCollectionViewModel collection) { var parameters = new DialogParameters { { "EntityType", "multi collection" }, { "EntityName", collection.Name } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = _dialog.Show("Delete Multi Collection", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled) { await _mediator.Send(new DeleteMultiCollection(collection.Id)); await _multiCollectionsTable.ReloadServerData(); } } private async Task DeleteSmartCollection(SmartCollectionViewModel collection) { var parameters = new DialogParameters { { "EntityType", "smart collection" }, { "EntityName", collection.Name } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = _dialog.Show("Delete Smart Collection", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled) { await _mediator.Send(new DeleteSmartCollection(collection.Id)); await _smartCollectionsTable.ReloadServerData(); } } private async Task> ServerReloadCollections(TableState state) { await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.CollectionsPageSize, state.PageSize.ToString())); PagedMediaCollectionsViewModel data = await _mediator.Send(new GetPagedCollections(state.Page, state.PageSize)); return new TableData { TotalItems = data.TotalCount, Items = data.Page }; } private async Task> ServerReloadMultiCollections(TableState state) { await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.MultiCollectionsPageSize, state.PageSize.ToString())); PagedMultiCollectionsViewModel data = await _mediator.Send(new GetPagedMultiCollections(state.Page, state.PageSize)); return new TableData { TotalItems = data.TotalCount, Items = data.Page }; } private async Task> ServerReloadSmartCollections(TableState state) { await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.SmartCollectionsPageSize, state.PageSize.ToString())); PagedSmartCollectionsViewModel data = await _mediator.Send(new GetPagedSmartCollections(state.Page, state.PageSize)); return new TableData { TotalItems = data.TotalCount, Items = data.Page }; } }