Most Changes for v0.1.0-beta #51

Merged
Penry merged 24 commits from v0.1.0-beta into main 2026-06-07 16:46:15 +02:00
5 changed files with 102 additions and 61 deletions
Showing only changes of commit dcbff4e30d - Show all commits
@@ -0,0 +1,37 @@
@using CouchLog.Data
<MudCard>
<MudPaper Elevation="0">
<MudCardMedia Image="@GlobalEntity.PicturePath" Height="400" Style="object-fit: contain;"/>
</MudPaper>
<MudCardContent>
<MudText Typo="Typo.h5">@GlobalEntity.Title</MudText>
</MudCardContent>
<MudCardActions>
<MudTooltip Text="Add to shared List">
<MudIconButton Icon="@Icons.Material.Rounded.People" Color="Color.Primary" OnClick="@(() => OnAddToShared.InvokeAsync(GlobalEntity))" />
</MudTooltip>
<MudSpacer/>
@if (UserPrivateEntityIds.Contains(GlobalEntity.Id))
{
<MudTooltip Text="Already added to Private List">
<MudIconButton Icon="@Icons.Material.Rounded.Check" Color="Color.Primary"/>
</MudTooltip>
}
else
{
<MudTooltip Text="Add to private List">
<MudIconButton Icon="@Icons.Material.Rounded.Lock" Color="Color.Primary" OnClick="@(() => OnAddToPrivate.InvokeAsync(GlobalEntity))" />
</MudTooltip>
}
</MudCardActions>
</MudCard>
@code
{
[Parameter] public GlobalEntity GlobalEntity { get; set; } = null!;
[Parameter] public HashSet<int> UserPrivateEntityIds { get; set; } = null!;
[Parameter] public EventCallback<GlobalEntity> OnAddToPrivate { get; set; }
[Parameter] public EventCallback<GlobalEntity> OnAddToShared { get; set; }
}
@@ -263,8 +263,7 @@
await CouchLogDB.SaveChangesAsync();
Snackbar.Add("Global Entity created!", Severity.Success);
MudDialog.Close(DialogResult.Ok(entity.Id));
NavigationManager.NavigateTo(NavigationManager.Uri, true);
MudDialog.Close(DialogResult.Ok(entity));
}
catch (Exception ex)
{
@@ -6,6 +6,7 @@
@using Microsoft.AspNetCore.Identity
@using Microsoft.EntityFrameworkCore
@using CouchLog.Components.Pages.GlobalList.Dialogs
@using CouchLog.Components.Pages.GlobalList.Components
@inject ApplicationDbContext CouchLogDb
@inject UserManager<ApplicationUser> UserManager
@@ -16,11 +17,6 @@
@attribute [Authorize]
<PageTitle>GlobalList</PageTitle>
@*
TODO: Add Paging
TODO: Add only reload for the pages
TODO: Make Search work
*@
<MudContainer MaxWidth="MaxWidth.False">
@*Top of the Page*@
@@ -44,6 +40,7 @@ TODO: Make Search work
<MudContainer>
<MudPaper Class="pa-2" Elevation="1">
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
@*Search bar*@
<MudTextField @bind-Value="_searchString"
Placeholder="Search..."
Adornment="Adornment.Start"
@@ -52,18 +49,25 @@ TODO: Make Search work
Variant="Variant.Outlined"
Margin="Margin.Dense"
Style="max-width: 300px;"/>
@*Refresh button*@
@*<MudTooltip Text="Refresh Entities">
<MudIconButton Icon="@Icons.Material.Filled.Refresh" OnClick="RefreshPage"/>
</MudTooltip>*@
@*More Filters button*@
<MudTooltip Text="More filters">
<MudIconButton Icon="@(_showFilters
? Icons.Material.Filled.ExpandLess
: Icons.Material.Filled.FilterList)"
OnClick="@(() => _showFilters = !_showFilters)"
Color="Color.Default" />
Color="Color.Default"/>
</MudTooltip>
</MudStack>
<MudCollapse Expanded="_showFilters">
@*Entity allready added*@
<MudSwitch @bind-Value="_showAlreadyAddedEntities" Color="Color.Primary">
Show already added Entities
</MudSwitch>
@*To be exstendet*@
</MudCollapse>
</MudPaper>
</MudContainer>
@@ -72,64 +76,52 @@ TODO: Make Search work
<MudContainer MaxWidth="MaxWidth.False">
<MudGrid Spacing="6" Justify="Justify.Center">
@foreach (var globalEntity in _globalEntities)
@foreach (var globalEntity in VisibleGlobalEntities)
{
if (!globalEntity.IsPrivate || (globalEntity.IsPrivate && (globalEntity.CreatorId == _appUser?.Id)))
{
if (_showAlreadyAddedEntities || !_userPrivateEntityIds.Contains(globalEntity.Id))
{
<MudItem xs="12" sm="6" md="4" lg="3" xl="2">
<MudCard>
<MudPaper Elevation="0">
<MudCardMedia Image="@globalEntity.PicturePath" Height="400" Style="object-fit: contain;"/>
</MudPaper>
<MudCardContent>
<MudText Typo="Typo.h5">@globalEntity.Title</MudText>
</MudCardContent>
<MudCardActions>
<MudTooltip Text="Add to shared List">
<MudIconButton Icon="@Icons.Material.Rounded.People" Color="Color.Primary" OnClick="AddGlobalEntityToSharedList"/>
</MudTooltip>
<MudSpacer/>
@if (_userPrivateEntityIds.Contains(globalEntity.Id))
{
<MudTooltip Text="Already added to Private List">
<MudIconButton Icon="@Icons.Material.Rounded.Check" Color="Color.Primary"/>
</MudTooltip>
}
else
{
<MudTooltip Text="Add to private List">
<MudIconButton Icon="@Icons.Material.Rounded.Lock" Color="Color.Primary" OnClick="() => AddGlobalEntityToPrivateList(globalEntity)"/>
</MudTooltip>
}
</MudCardActions>
</MudCard>
</MudItem>
}
}
<MudItem xs="12" sm="6" md="4" lg="3" xl="2">
<GlobalEntityCard GlobalEntity="globalEntity"
UserPrivateEntityIds="_userPrivateEntityIds"
OnAddToPrivate="AddGlobalEntityToPrivateList"
OnAddToShared="AddGlobalEntityToSharedList"/>
</MudItem>
}
</MudGrid>
</MudContainer>
<br/>
<MudContainer>
<MudStack AlignItems="AlignItems.Center">
<MudPagination Count="@TotalPages" @bind-Selected="_currentPage"/>
</MudStack>
</MudContainer>
</MudContainer>
@code
{
//Search
private string _searchString;
//Filter Variables
//Filter
private string? _searchString;
private bool _showFilters;
private bool _showAlreadyAddedEntities = false;
private IEnumerable<GlobalEntity> FiltertGlobalEntities => _globalEntities.Where(entity =>
(string.IsNullOrWhiteSpace(_searchString) || entity.Title.Contains(_searchString, StringComparison.OrdinalIgnoreCase)) && //Search bar
(_showAlreadyAddedEntities || !_userPrivateEntityIds.Contains(entity.Id)) //Filter for already added Entitys
);
//Paging
private int _currentPage = 1;
private int _pageSize = 12;
private int TotalPages => (int)Math.Ceiling(FiltertGlobalEntities.Count() / (double)_pageSize);
private IEnumerable<GlobalEntity> VisibleGlobalEntities => FiltertGlobalEntities.Skip((_currentPage - 1) * _pageSize).Take(_pageSize);
//Core
private ApplicationUser? _appUser;
private List<GlobalEntity> _globalEntities = [];
private HashSet<int> _userPrivateEntityIds = [];
protected override async Task OnInitializedAsync()
{
_globalEntities = await CouchLogDb.GlobalEntities.OrderByDescending(entity => entity.CreationTime).ToListAsync();
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
_appUser = await UserManager.GetUserAsync(authState.User);
@@ -139,29 +131,41 @@ TODO: Make Search work
return;
}
_globalEntities = await CouchLogDb.GlobalEntities
.OrderByDescending(entity => entity.CreationTime)
.Where(entity => !entity.IsPrivate || (entity.IsPrivate && entity.CreatorId == _appUser.Id))
.ToListAsync();
_userPrivateEntityIds = await CouchLogDb.PrivateEntities
.Where(entity => entity.UserId == _appUser.Id)
.Select(p => p.GlobalEntityId)
.ToHashSetAsync();
}
private async Task RefreshPage()
{
_currentPage = 1;
StateHasChanged();
}
private async Task OnNewEntity(GlobalEntity entity)
{
_globalEntities.Add(entity);
await RefreshPage();
}
private async Task OpenAddNewGlobalEntityDialog()
{
var dialog = await DialogService.ShowAsync<AddNewGlobalEntityDialog>("Add new Global Entity");
}
private async Task<bool> IsFilterValid(GlobalEntity globalEntity)
{
if (!_showAlreadyAddedEntities && await IsInPrivateList(globalEntity.Id))
var result = await dialog.Result;
if (!result!.Canceled)
{
return false;
var entity = (GlobalEntity)result.Data!;
await OnNewEntity(entity);
}
return true;
}
private async Task AddGlobalEntityToPrivateList(GlobalEntity globalEntity)
public async Task AddGlobalEntityToPrivateList(GlobalEntity globalEntity)
{
if(_appUser is null) { Snackbar.Add("Not logged in!", Severity.Error); return;}
@@ -178,6 +182,7 @@ TODO: Make Search work
CouchLogDb.PrivateEntities.Add(privateEntity);
await CouchLogDb.SaveChangesAsync();
_userPrivateEntityIds.Add(globalEntity.Id);
StateHasChanged();
Snackbar.Add("Added Entity to private List", Severity.Success);
}
@@ -48,11 +48,11 @@
<MudGrid Spacing="6" Justify="Justify.Center">
@foreach (var privateEntity in ActiveWatchingEntities)
{
<EntityCard PrivateEntity="privateEntity" />
<PrivateEntityCard PrivateEntity="privateEntity" />
}
@foreach (var privateEntity in LibraryEntities)
{
<EntityCard PrivateEntity="privateEntity" />
<PrivateEntityCard PrivateEntity="privateEntity" />
}
</MudGrid>
</MudContainer>