Most Changes for v0.1.0-beta #51
@@ -86,7 +86,6 @@
|
||||
</MudFileUpload>
|
||||
</MudItem>
|
||||
|
||||
<!-- ═══ Rechte Spalte: Formular ═══ -->
|
||||
<MudItem xs="7">
|
||||
<MudStack Spacing="3">
|
||||
|
||||
@@ -199,7 +198,6 @@
|
||||
{
|
||||
_picture = file;
|
||||
|
||||
// Base64-Vorschau generieren (max. 5 MB)
|
||||
const long maxPreviewSize = 5 * 1024 * 1024;
|
||||
await using var stream = file.OpenReadStream(maxPreviewSize);
|
||||
using var ms = new MemoryStream();
|
||||
@@ -266,6 +264,7 @@
|
||||
|
||||
Snackbar.Add("Global Entity created!", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(entity.Id));
|
||||
NavigationManager.NavigateTo(NavigationManager.Uri, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@page "/GlobalList"
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@using System.Security.Claims
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using CouchLog.Data
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@@ -18,6 +19,10 @@
|
||||
|
||||
<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*@
|
||||
<MudContainer>
|
||||
@@ -34,37 +39,90 @@
|
||||
</MudTooltip>
|
||||
</MudStack>
|
||||
</MudContainer>
|
||||
|
||||
<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">
|
||||
<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))
|
||||
{
|
||||
<MudItem xs="12" sm="6" md="4" lg="3" xl="2">
|
||||
<MudCard>
|
||||
<MudCardMedia Image="@entity.PicturePath" />
|
||||
<MudPaper Elevation="0">
|
||||
<MudCardMedia Image="@globalEntity.PicturePath" Height="400" Style="object-fit: contain;"/>
|
||||
</MudPaper>
|
||||
<MudCardContent>
|
||||
<MudText Typo="Typo.h5">@entity.Title</MudText>
|
||||
<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>
|
||||
<MudTooltip Text="Add to private List">
|
||||
<MudIconButton Icon="@Icons.Material.Rounded.Lock" Color="Color.Primary" />
|
||||
<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>
|
||||
}
|
||||
}
|
||||
}
|
||||
</MudGrid>
|
||||
</MudContainer>
|
||||
</MudContainer>
|
||||
|
||||
@code
|
||||
{
|
||||
//Search
|
||||
private string _searchString;
|
||||
|
||||
//Filter Variables
|
||||
private bool _showFilters;
|
||||
private bool _showAlreadyAddedEntities = false;
|
||||
|
||||
private ApplicationUser? _appUser;
|
||||
private List<GlobalEntity> _globalEntities = [];
|
||||
private HashSet<int> _userPrivateEntityIds = [];
|
||||
@@ -88,12 +146,56 @@
|
||||
.ToHashSetAsync();
|
||||
}
|
||||
|
||||
|
||||
private async Task OpenAddNewGlobalEntityDialog()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user