Save Changes

This commit is contained in:
2026-05-23 13:08:12 +02:00
parent 352a7dbfde
commit 8e615c15f0
2 changed files with 124 additions and 23 deletions
@@ -85,8 +85,7 @@
</ActivatorContent> </ActivatorContent>
</MudFileUpload> </MudFileUpload>
</MudItem> </MudItem>
<!-- ═══ Rechte Spalte: Formular ═══ -->
<MudItem xs="7"> <MudItem xs="7">
<MudStack Spacing="3"> <MudStack Spacing="3">
@@ -198,8 +197,7 @@
private async Task OnPictureUploaded(IBrowserFile file) private async Task OnPictureUploaded(IBrowserFile file)
{ {
_picture = file; _picture = file;
// Base64-Vorschau generieren (max. 5 MB)
const long maxPreviewSize = 5 * 1024 * 1024; const long maxPreviewSize = 5 * 1024 * 1024;
await using var stream = file.OpenReadStream(maxPreviewSize); await using var stream = file.OpenReadStream(maxPreviewSize);
using var ms = new MemoryStream(); using var ms = new MemoryStream();
@@ -266,6 +264,7 @@
Snackbar.Add("Global Entity created!", Severity.Success); Snackbar.Add("Global Entity created!", Severity.Success);
MudDialog.Close(DialogResult.Ok(entity.Id)); MudDialog.Close(DialogResult.Ok(entity.Id));
NavigationManager.NavigateTo(NavigationManager.Uri, true);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -1,6 +1,7 @@
@page "/GlobalList" @page "/GlobalList"
@rendermode InteractiveServer @rendermode InteractiveServer
@using System.Security.Claims
@using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Authorization
@using CouchLog.Data @using CouchLog.Data
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@@ -18,6 +19,10 @@
<PageTitle>GlobalList</PageTitle> <PageTitle>GlobalList</PageTitle>
TODO: Add Paging
TODO: Add only reload for the pages
TODO: Make Search work
<MudContainer MaxWidth="MaxWidth.False"> <MudContainer MaxWidth="MaxWidth.False">
@*Top of the Page*@ @*Top of the Page*@
<MudContainer> <MudContainer>
@@ -34,29 +39,75 @@
</MudTooltip> </MudTooltip>
</MudStack> </MudStack>
</MudContainer> </MudContainer>
<br/> <br/>
<MudContainer>
<MudPaper Class="pa-2" Elevation="1">
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
<MudTextField @bind-Value="_searchString"
Placeholder="Search..."
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
Immediate="true"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Style="max-width: 300px;"/>
<MudTooltip Text="More filters">
<MudIconButton Icon="@(_showFilters
? Icons.Material.Filled.ExpandLess
: Icons.Material.Filled.FilterList)"
OnClick="@(() => _showFilters = !_showFilters)"
Color="Color.Default" />
</MudTooltip>
</MudStack>
<MudCollapse Expanded="_showFilters">
<MudSwitch @bind-Value="_showAlreadyAddedEntities" Color="Color.Primary">
Show already added Entities
</MudSwitch>
</MudCollapse>
</MudPaper>
</MudContainer>
<br/>
<MudContainer MaxWidth="MaxWidth.False"> <MudContainer MaxWidth="MaxWidth.False">
<MudGrid Spacing="6" Justify="Justify.Center"> <MudGrid Spacing="6" Justify="Justify.Center">
@foreach (var entity in _globalEntities) @foreach (var globalEntity in _globalEntities)
{ {
if (!entity.IsPrivate || (entity.IsPrivate && (entity.CreatorId == _appUser?.Id))) if (!globalEntity.IsPrivate || (globalEntity.IsPrivate && (globalEntity.CreatorId == _appUser?.Id)))
{ {
<MudItem xs="12" sm="6" md="4" lg="2"> if (_showAlreadyAddedEntities || !_userPrivateEntityIds.Contains(globalEntity.Id))
<MudCard> {
<MudCardMedia Image="@entity.PicturePath" /> <MudItem xs="12" sm="6" md="4" lg="3" xl="2">
<MudCardContent> <MudCard>
<MudText Typo="Typo.h5">@entity.Title</MudText> <MudPaper Elevation="0">
</MudCardContent> <MudCardMedia Image="@globalEntity.PicturePath" Height="400" Style="object-fit: contain;"/>
<MudCardActions> </MudPaper>
<MudTooltip Text="Add to shared List"> <MudCardContent>
<MudIconButton Icon="@Icons.Material.Rounded.People" Color="Color.Primary" OnClick="AddGlobalEntityToSharedList"/> <MudText Typo="Typo.h5">@globalEntity.Title</MudText>
</MudTooltip> </MudCardContent>
<MudTooltip Text="Add to private List"> <MudCardActions>
<MudIconButton Icon="@Icons.Material.Rounded.Lock" Color="Color.Primary" /> <MudTooltip Text="Add to shared List">
</MudTooltip> <MudIconButton Icon="@Icons.Material.Rounded.People" Color="Color.Primary" OnClick="AddGlobalEntityToSharedList"/>
</MudCardActions> </MudTooltip>
</MudCard> <MudSpacer/>
</MudItem> @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>
}
} }
} }
</MudGrid> </MudGrid>
@@ -65,6 +116,13 @@
@code @code
{ {
//Search
private string _searchString;
//Filter Variables
private bool _showFilters;
private bool _showAlreadyAddedEntities = false;
private ApplicationUser? _appUser; private ApplicationUser? _appUser;
private List<GlobalEntity> _globalEntities = []; private List<GlobalEntity> _globalEntities = [];
private HashSet<int> _userPrivateEntityIds = []; private HashSet<int> _userPrivateEntityIds = [];
@@ -88,12 +146,56 @@
.ToHashSetAsync(); .ToHashSetAsync();
} }
private async Task OpenAddNewGlobalEntityDialog() private async Task OpenAddNewGlobalEntityDialog()
{ {
var dialog = await DialogService.ShowAsync<AddNewGlobalEntityDialog>("Add new Global Entity"); var dialog = await DialogService.ShowAsync<AddNewGlobalEntityDialog>("Add new Global Entity");
} }
private async Task AddGlobalEntityToSharedList() private async Task<bool> IsFilterValid(GlobalEntity globalEntity)
{
if (!_showAlreadyAddedEntities && await IsInPrivateList(globalEntity.Id))
{
return false;
}
return true;
}
private async Task AddGlobalEntityToPrivateList(GlobalEntity globalEntity)
{
if(_appUser is null) { Snackbar.Add("Not logged in!", Severity.Error); return;}
if (!await IsInPrivateList(globalEntity.Id))
{
PrivateEntity privateEntity = new()
{
UserId = _appUser.Id,
CreationTime = DateTime.Now,
GlobalEntityId = globalEntity.Id,
UserWatchStatusId = 1,
};
CouchLogDb.PrivateEntities.Add(privateEntity);
await CouchLogDb.SaveChangesAsync();
StateHasChanged();
Snackbar.Add("Added Entity to private List", Severity.Success);
}
else
{
Snackbar.Add("Entity already in private List!", Severity.Warning);
}
}
private async Task<bool> IsInPrivateList(int globalEntityId)
{
if (_appUser is null) return false;
return await CouchLogDb.PrivateEntities.Where(entity => entity.UserId == _appUser.Id).AnyAsync(entity => entity.GlobalEntityId == globalEntityId);
}
private void AddGlobalEntityToSharedList()
{ {
Snackbar.Add("Feature not implemented yet!", Severity.Error); Snackbar.Add("Feature not implemented yet!", Severity.Error);
} }