[CHANGE] Adding accounts
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
<MudNavMenu>
|
<MudNavMenu>
|
||||||
<MudNavLink Href="/" Icon="@Icons.Material.Filled.Home" Match="NavLinkMatch.Prefix">Home</MudNavLink>
|
<MudNavLink Href="/" Icon="@Icons.Material.Filled.Home" Match="NavLinkMatch.All">Home</MudNavLink>
|
||||||
<MudNavLink Href="/Channels" Icon="@Icons.Material.Filled.SupervisorAccount" Match="NavLinkMatch.All">Channels</MudNavLink>
|
<MudNavLink Href="/Channels" Icon="@Icons.Material.Filled.SupervisorAccount" Match="NavLinkMatch.All">Channels</MudNavLink>
|
||||||
<MudNavLink Href="/Library" Icon="@Icons.Material.Filled.LocalLibrary" Match="NavLinkMatch.All">Library</MudNavLink>
|
<MudNavLink Href="/Library" Icon="@Icons.Material.Filled.LocalLibrary" Match="NavLinkMatch.All">Library</MudNavLink>
|
||||||
<MudNavLink Href="/Playlists" Icon="@Icons.Material.Filled.ViewList" Match="NavLinkMatch.All">Playlists</MudNavLink>
|
<MudNavLink Href="/Playlists" Icon="@Icons.Material.Filled.ViewList" Match="NavLinkMatch.All">Playlists</MudNavLink>
|
||||||
|
@@ -1,3 +1,86 @@
|
|||||||
@page "/Channels"
|
@page "/Channels"
|
||||||
|
@inject ILibraryService LibraryService
|
||||||
<PageTitle>Channels</PageTitle>
|
<PageTitle>Channels</PageTitle>
|
||||||
|
|
||||||
|
|
||||||
|
<MudDialog @bind-Visible="@_addAccountDialogVisible" Options="_dialogOptions">
|
||||||
|
<TitleContent>
|
||||||
|
<MudText Typo="Typo.h6">Add new account</MudText>
|
||||||
|
</TitleContent>
|
||||||
|
<DialogContent>
|
||||||
|
<MudDataGrid Items="_cookies" Dense Elevation="0" Outlined>
|
||||||
|
<Header>
|
||||||
|
<MudStack Class="ma-2">
|
||||||
|
<MudText>Cookies</MudText>
|
||||||
|
</MudStack>
|
||||||
|
<MudStack Row Spacing="2" Class="ma-1">
|
||||||
|
<MudTooltip Text="Add cookie">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Add" Size="Size.Small" Color="Color.Success" OnClick="() => _cookies.Add(new HttpCookie())"/>
|
||||||
|
</MudTooltip>
|
||||||
|
<MudTooltip Text="Add from text">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.InsertDriveFile" Size="Size.Small" Color="Color.Primary" Disabled/>
|
||||||
|
</MudTooltip>
|
||||||
|
</MudStack>
|
||||||
|
</Header>
|
||||||
|
<Columns>
|
||||||
|
<TemplateColumn Title="Name">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudTextField Variant="Variant.Text" @bind-Value="@context.Item.Name" Immediate/>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
<TemplateColumn Title="Value">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudTextField Variant="Variant.Text" @bind-Value="@context.Item.Value" Immediate/>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
|
||||||
|
<TemplateColumn>
|
||||||
|
<CellTemplate>
|
||||||
|
<MudTooltip Text="Remove">
|
||||||
|
<MudIconButton Size="Size.Small" Icon="@Icons.Material.Filled.Remove" Color="Color.Error" OnClick="() => _cookies.Remove(context.Item)"/>
|
||||||
|
</MudTooltip>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
</Columns>
|
||||||
|
</MudDataGrid>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<MudStack Spacing="2" Row>
|
||||||
|
<MudButton Color="Color.Error" OnClick="() => _addAccountDialogVisible = false" Variant="Variant.Outlined">Cancel</MudButton>
|
||||||
|
<MudButton Color="Color.Primary" Variant="Variant.Outlined" Disabled>Save</MudButton>
|
||||||
|
</MudStack>
|
||||||
|
</DialogActions>
|
||||||
|
</MudDialog>
|
||||||
|
|
||||||
|
<MudStack Spacing="2">
|
||||||
|
<MudPaper Elevation="0" Outlined>
|
||||||
|
<MudStack Row Class="ma-2">
|
||||||
|
<MudButton IconSize="Size.Small" StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Outlined" OnClick="() => _addAccountDialogVisible = true">Add account</MudButton>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudTable ServerData="ServerReload">
|
||||||
|
<ToolBarContent>
|
||||||
|
<MudText Typo="Typo.h6">Channels</MudText>
|
||||||
|
</ToolBarContent>
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Name</MudTh>
|
||||||
|
<MudTh>Channel id</MudTh>
|
||||||
|
<MudTh>Has login</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd>@context.Name</MudTd>
|
||||||
|
<MudTd>@context.Id</MudTd>
|
||||||
|
<MudTd>@(context.ClientAccount != null)</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
<NoRecordsContent>
|
||||||
|
<MudText>No channels found</MudText>
|
||||||
|
</NoRecordsContent>
|
||||||
|
<LoadingContent>
|
||||||
|
<MudText>Loading...</MudText>
|
||||||
|
</LoadingContent>
|
||||||
|
<PagerContent>
|
||||||
|
<MudTablePager/>
|
||||||
|
</PagerContent>
|
||||||
|
</MudTable>
|
||||||
|
</MudStack>
|
@@ -1,7 +1,28 @@
|
|||||||
|
using Manager.Data.Entities.LibraryContext;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using MudBlazor;
|
||||||
|
|
||||||
namespace Manager.App.Components.Pages;
|
namespace Manager.App.Components.Pages;
|
||||||
|
|
||||||
public partial class Channels : ComponentBase
|
public partial class Channels : ComponentBase
|
||||||
{
|
{
|
||||||
|
private bool _addAccountDialogVisible;
|
||||||
|
private DialogOptions _dialogOptions = new() { BackdropClick = false, CloseButton = true, FullWidth = true };
|
||||||
|
private List<HttpCookie> _cookies = [];
|
||||||
|
private async Task<TableData<ChannelEntity>> ServerReload(TableState state, CancellationToken token)
|
||||||
|
{
|
||||||
|
var results = await LibraryService.GetChannelAccountsAsync(state.Page * state.PageSize, state.PageSize, token);
|
||||||
|
if (!results.IsSuccess)
|
||||||
|
{
|
||||||
|
return new TableData<ChannelEntity>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TableData<ChannelEntity> { Items = results.Value, TotalItems = results.Total };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record HttpCookie()
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Value { get; set; }
|
||||||
}
|
}
|
@@ -1,9 +1,10 @@
|
|||||||
using Manager.App.Models.Library;
|
using Manager.App.Models.Library;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
using MudBlazor;
|
using MudBlazor;
|
||||||
|
|
||||||
namespace Manager.App.Components.Pages;
|
namespace Manager.App.Components.Pages;
|
||||||
|
|
||||||
public partial class Library
|
public partial class Library : ComponentBase
|
||||||
{
|
{
|
||||||
private LibraryInformation? _libraryInformation;
|
private LibraryInformation? _libraryInformation;
|
||||||
private bool _loading;
|
private bool _loading;
|
||||||
|
30
Manager.App/Models/System/ListResult.cs
Normal file
30
Manager.App/Models/System/ListResult.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using DotBased.Monads;
|
||||||
|
|
||||||
|
namespace Manager.App.Models.System;
|
||||||
|
|
||||||
|
public class ListResult<TResult> : Result<List<TResult>>
|
||||||
|
{
|
||||||
|
protected ListResult(List<TResult> result, int total) : base(result)
|
||||||
|
{
|
||||||
|
Total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ListResult(Exception exception) : base(exception)
|
||||||
|
{
|
||||||
|
Total = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ListResult(ResultError error) : base(error)
|
||||||
|
{
|
||||||
|
Total = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Total { get; set; }
|
||||||
|
|
||||||
|
public static implicit operator ListResult<TResult>(ResultError error) => new(error);
|
||||||
|
public static implicit operator ListResult<TResult>(Exception exception) => new(exception);
|
||||||
|
public static implicit operator ListResult<TResult>(List<TResult> result) => new(result, 0);
|
||||||
|
public static implicit operator ListResult<TResult>(ListResultReturn<TResult> result) => new(result.List, result.Total);
|
||||||
|
}
|
||||||
|
|
||||||
|
public record ListResultReturn<TResult>(List<TResult> List, int Total);
|
@@ -1,9 +1,13 @@
|
|||||||
using DotBased.Monads;
|
using DotBased.Monads;
|
||||||
using Manager.App.Models.Library;
|
using Manager.App.Models.Library;
|
||||||
|
using Manager.App.Models.System;
|
||||||
|
using Manager.Data.Entities.LibraryContext;
|
||||||
|
|
||||||
namespace Manager.App.Services;
|
namespace Manager.App.Services;
|
||||||
|
|
||||||
public interface ILibraryService
|
public interface ILibraryService
|
||||||
{
|
{
|
||||||
public Task<Result<LibraryInformation>> GetLibraryInfoAsync(CancellationToken cancellationToken = default);
|
public Task<Result<LibraryInformation>> GetLibraryInfoAsync(CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
public Task<ListResult<ChannelEntity>> GetChannelAccountsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
using DotBased.Monads;
|
using DotBased.Monads;
|
||||||
using Manager.App.Models.Library;
|
using Manager.App.Models.Library;
|
||||||
using Manager.App.Models.Settings;
|
using Manager.App.Models.Settings;
|
||||||
|
using Manager.App.Models.System;
|
||||||
using Manager.Data.Contexts;
|
using Manager.Data.Contexts;
|
||||||
using Manager.Data.Entities.LibraryContext;
|
using Manager.Data.Entities.LibraryContext;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -50,13 +51,13 @@ public class LibraryService : ILibraryService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Result<List<ChannelEntity>>> GetAccountsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default)
|
public async Task<ListResult<ChannelEntity>> GetChannelAccountsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
var orderedAccounts = context.Channels.Include(x => x.ClientAccount).Where(x => x.ClientAccount != null).OrderBy(x => x.Id).Skip(offset).Take(total);
|
var orderedAccounts = context.Channels.Include(x => x.ClientAccount).Where(x => x.ClientAccount != null).OrderBy(x => x.Id);
|
||||||
return orderedAccounts.ToList();
|
return new ListResultReturn<ChannelEntity>(orderedAccounts.Skip(offset).Take(total).ToList(), orderedAccounts.Count());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user