|
|
|
@ -1,6 +1,5 @@
@@ -1,6 +1,5 @@
|
|
|
|
|
@page "/media/playlists" |
|
|
|
|
@using ErsatzTV.Application.MediaCollections |
|
|
|
|
@using S = System.Collections.Generic |
|
|
|
|
@implements IDisposable |
|
|
|
|
@inject ILogger<Playlists> Logger |
|
|
|
|
@inject ISnackbar Snackbar |
|
|
|
@ -48,28 +47,28 @@
@@ -48,28 +47,28 @@
|
|
|
|
|
</MudItem> |
|
|
|
|
<MudItem xs="8"> |
|
|
|
|
<MudCard> |
|
|
|
|
<MudTreeView ServerData="LoadServerData" Items="@TreeItems" Hover="true" ExpandOnClick="true"> |
|
|
|
|
<MudTreeView T="PlaylistTreeItemViewModel" ServerData="LoadServerData" Items="@TreeItems" Hover="true" ExpandOnClick="true"> |
|
|
|
|
<ItemTemplate Context="item"> |
|
|
|
|
<MudTreeViewItem Items="@item.TreeItems" Icon="@item.Icon" CanExpand="@item.CanExpand" Value="@item"> |
|
|
|
|
<MudTreeViewItem T="PlaylistTreeItemViewModel" Items="@item.Value!.TreeItems" Icon="@item.Value.Icon" CanExpand="@item.Value.CanExpand" Value="@item.Value"> |
|
|
|
|
<BodyContent> |
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%"> |
|
|
|
|
<MudGrid Justify="Justify.FlexStart"> |
|
|
|
|
<MudItem xs="5"> |
|
|
|
|
<MudText>@item.Text</MudText> |
|
|
|
|
<MudText>@item.Value.Text</MudText> |
|
|
|
|
</MudItem> |
|
|
|
|
@if (!string.IsNullOrWhiteSpace(item.EndText)) |
|
|
|
|
@if (!string.IsNullOrWhiteSpace(item.Value.EndText)) |
|
|
|
|
{ |
|
|
|
|
<MudItem xs="6"> |
|
|
|
|
<MudText>@item.EndText</MudText> |
|
|
|
|
<MudText>@item.Value.EndText</MudText> |
|
|
|
|
</MudItem> |
|
|
|
|
} |
|
|
|
|
</MudGrid> |
|
|
|
|
<div style="justify-self: end;"> |
|
|
|
|
@foreach (int playlistId in Optional(item.PlaylistId)) |
|
|
|
|
@foreach (int playlistId in Optional(item.Value.PlaylistId)) |
|
|
|
|
{ |
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Medium" Color="Color.Inherit" Href="@($"media/playlists/{playlistId}")"/> |
|
|
|
|
} |
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" Color="Color.Inherit" OnClick="@(_ => DeleteItem(item))"/> |
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" Color="Color.Inherit" OnClick="@(_ => DeleteItem(item.Value))"/> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</BodyContent> |
|
|
|
@ -83,7 +82,7 @@
@@ -83,7 +82,7 @@
|
|
|
|
|
|
|
|
|
|
@code { |
|
|
|
|
private readonly CancellationTokenSource _cts = new(); |
|
|
|
|
private S.HashSet<PlaylistTreeItemViewModel> TreeItems { get; set; } = []; |
|
|
|
|
private List<TreeItemData<PlaylistTreeItemViewModel>> TreeItems { get; set; } = []; |
|
|
|
|
private List<PlaylistGroupViewModel> _playlistGroups = []; |
|
|
|
|
private PlaylistGroupViewModel _selectedPlaylistGroup; |
|
|
|
|
private string _playlistGroupName; |
|
|
|
@ -104,7 +103,7 @@
@@ -104,7 +103,7 @@
|
|
|
|
|
private async Task ReloadPlaylistGroups() |
|
|
|
|
{ |
|
|
|
|
_playlistGroups = await Mediator.Send(new GetAllPlaylistGroups(), _cts.Token); |
|
|
|
|
TreeItems = _playlistGroups.Map(g => new PlaylistTreeItemViewModel(g)).ToHashSet(); |
|
|
|
|
TreeItems = _playlistGroups.Map(g => new TreeItemData<PlaylistTreeItemViewModel> { Value = new PlaylistTreeItemViewModel(g) }).ToList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async Task AddPlaylistGroup() |
|
|
|
@ -121,7 +120,7 @@
@@ -121,7 +120,7 @@
|
|
|
|
|
|
|
|
|
|
foreach (PlaylistGroupViewModel playlistGroup in result.RightToSeq()) |
|
|
|
|
{ |
|
|
|
|
TreeItems.Add(new PlaylistTreeItemViewModel(playlistGroup)); |
|
|
|
|
TreeItems.Add(new TreeItemData<PlaylistTreeItemViewModel> { Value = new PlaylistTreeItemViewModel(playlistGroup) }); |
|
|
|
|
_playlistGroupName = null; |
|
|
|
|
|
|
|
|
|
_playlistGroups = await Mediator.Send(new GetAllPlaylistGroups(), _cts.Token); |
|
|
|
@ -144,9 +143,9 @@
@@ -144,9 +143,9 @@
|
|
|
|
|
|
|
|
|
|
foreach (PlaylistViewModel playlist in result.RightToSeq()) |
|
|
|
|
{ |
|
|
|
|
foreach (PlaylistTreeItemViewModel item in TreeItems.Where(item => item.PlaylistGroupId == _selectedPlaylistGroup.Id)) |
|
|
|
|
foreach (PlaylistTreeItemViewModel item in TreeItems.Map(i => i.Value).Where(item => item.PlaylistGroupId == _selectedPlaylistGroup.Id)) |
|
|
|
|
{ |
|
|
|
|
item.TreeItems.Add(new PlaylistTreeItemViewModel(playlist)); |
|
|
|
|
item.TreeItems.Add(new TreeItemData<PlaylistTreeItemViewModel> { Value = new PlaylistTreeItemViewModel(playlist) }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_playlistName = null; |
|
|
|
@ -155,14 +154,14 @@
@@ -155,14 +154,14 @@
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async Task<S.HashSet<PlaylistTreeItemViewModel>> LoadServerData(PlaylistTreeItemViewModel parentNode) |
|
|
|
|
private async Task<IReadOnlyCollection<TreeItemData<PlaylistTreeItemViewModel>>> LoadServerData(PlaylistTreeItemViewModel parentNode) |
|
|
|
|
{ |
|
|
|
|
foreach (int playlistGroupId in Optional(parentNode.PlaylistGroupId)) |
|
|
|
|
{ |
|
|
|
|
List<PlaylistViewModel> result = await Mediator.Send(new GetPlaylistsByPlaylistGroupId(playlistGroupId), _cts.Token); |
|
|
|
|
foreach (PlaylistViewModel playlist in result) |
|
|
|
|
{ |
|
|
|
|
parentNode.TreeItems.Add(new PlaylistTreeItemViewModel(playlist)); |
|
|
|
|
parentNode.TreeItems.Add(new TreeItemData<PlaylistTreeItemViewModel> { Value = new PlaylistTreeItemViewModel(playlist) }); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -178,10 +177,10 @@
@@ -178,10 +177,10 @@
|
|
|
|
|
|
|
|
|
|
IDialogReference dialog = await Dialog.ShowAsync<DeleteDialog>("Delete Playlist Group", parameters, options); |
|
|
|
|
DialogResult result = await dialog.Result; |
|
|
|
|
if (!result.Canceled) |
|
|
|
|
if (result is not null && !result.Canceled) |
|
|
|
|
{ |
|
|
|
|
await Mediator.Send(new DeletePlaylistGroup(playlistGroupId), _cts.Token); |
|
|
|
|
TreeItems.RemoveWhere(i => i.PlaylistGroupId == playlistGroupId); |
|
|
|
|
TreeItems.RemoveAll(i => i.Value?.PlaylistGroupId == playlistGroupId); |
|
|
|
|
|
|
|
|
|
_playlistGroups = await Mediator.Send(new GetAllPlaylistGroups(), _cts.Token); |
|
|
|
|
await InvokeAsync(StateHasChanged); |
|
|
|
@ -195,12 +194,12 @@
@@ -195,12 +194,12 @@
|
|
|
|
|
|
|
|
|
|
IDialogReference dialog = await Dialog.ShowAsync<DeleteDialog>("Delete Playlist", parameters, options); |
|
|
|
|
DialogResult result = await dialog.Result; |
|
|
|
|
if (!result.Canceled) |
|
|
|
|
if (result is not null && !result.Canceled) |
|
|
|
|
{ |
|
|
|
|
await Mediator.Send(new DeletePlaylist(playlistId), _cts.Token); |
|
|
|
|
foreach (PlaylistTreeItemViewModel parent in TreeItems) |
|
|
|
|
foreach (PlaylistTreeItemViewModel parent in TreeItems.Map(i => i.Value)) |
|
|
|
|
{ |
|
|
|
|
parent.TreeItems.Remove(treeItem); |
|
|
|
|
parent.TreeItems.RemoveAll(i => i.Value == treeItem); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged); |
|
|
|
|