Most Changes for v0.1.0-beta #51
@@ -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();
|
await CouchLogDB.SaveChangesAsync();
|
||||||
|
|
||||||
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));
|
||||||
NavigationManager.NavigateTo(NavigationManager.Uri, true);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using CouchLog.Components.Pages.GlobalList.Dialogs
|
@using CouchLog.Components.Pages.GlobalList.Dialogs
|
||||||
|
@using CouchLog.Components.Pages.GlobalList.Components
|
||||||
|
|
||||||
@inject ApplicationDbContext CouchLogDb
|
@inject ApplicationDbContext CouchLogDb
|
||||||
@inject UserManager<ApplicationUser> UserManager
|
@inject UserManager<ApplicationUser> UserManager
|
||||||
@@ -16,11 +17,6 @@
|
|||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
|
|
||||||
<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*@
|
||||||
@@ -44,6 +40,7 @@ TODO: Make Search work
|
|||||||
<MudContainer>
|
<MudContainer>
|
||||||
<MudPaper Class="pa-2" Elevation="1">
|
<MudPaper Class="pa-2" Elevation="1">
|
||||||
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
|
||||||
|
@*Search bar*@
|
||||||
<MudTextField @bind-Value="_searchString"
|
<MudTextField @bind-Value="_searchString"
|
||||||
Placeholder="Search..."
|
Placeholder="Search..."
|
||||||
Adornment="Adornment.Start"
|
Adornment="Adornment.Start"
|
||||||
@@ -52,18 +49,25 @@ TODO: Make Search work
|
|||||||
Variant="Variant.Outlined"
|
Variant="Variant.Outlined"
|
||||||
Margin="Margin.Dense"
|
Margin="Margin.Dense"
|
||||||
Style="max-width: 300px;"/>
|
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">
|
<MudTooltip Text="More filters">
|
||||||
<MudIconButton Icon="@(_showFilters
|
<MudIconButton Icon="@(_showFilters
|
||||||
? Icons.Material.Filled.ExpandLess
|
? Icons.Material.Filled.ExpandLess
|
||||||
: Icons.Material.Filled.FilterList)"
|
: Icons.Material.Filled.FilterList)"
|
||||||
OnClick="@(() => _showFilters = !_showFilters)"
|
OnClick="@(() => _showFilters = !_showFilters)"
|
||||||
Color="Color.Default" />
|
Color="Color.Default"/>
|
||||||
</MudTooltip>
|
</MudTooltip>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
<MudCollapse Expanded="_showFilters">
|
<MudCollapse Expanded="_showFilters">
|
||||||
|
@*Entity allready added*@
|
||||||
<MudSwitch @bind-Value="_showAlreadyAddedEntities" Color="Color.Primary">
|
<MudSwitch @bind-Value="_showAlreadyAddedEntities" Color="Color.Primary">
|
||||||
Show already added Entities
|
Show already added Entities
|
||||||
</MudSwitch>
|
</MudSwitch>
|
||||||
|
@*To be exstendet*@
|
||||||
</MudCollapse>
|
</MudCollapse>
|
||||||
</MudPaper>
|
</MudPaper>
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
@@ -72,64 +76,52 @@ TODO: Make Search work
|
|||||||
|
|
||||||
<MudContainer MaxWidth="MaxWidth.False">
|
<MudContainer MaxWidth="MaxWidth.False">
|
||||||
<MudGrid Spacing="6" Justify="Justify.Center">
|
<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)))
|
<MudItem xs="12" sm="6" md="4" lg="3" xl="2">
|
||||||
{
|
<GlobalEntityCard GlobalEntity="globalEntity"
|
||||||
if (_showAlreadyAddedEntities || !_userPrivateEntityIds.Contains(globalEntity.Id))
|
UserPrivateEntityIds="_userPrivateEntityIds"
|
||||||
{
|
OnAddToPrivate="AddGlobalEntityToPrivateList"
|
||||||
<MudItem xs="12" sm="6" md="4" lg="3" xl="2">
|
OnAddToShared="AddGlobalEntityToSharedList"/>
|
||||||
<MudCard>
|
</MudItem>
|
||||||
<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>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</MudGrid>
|
</MudGrid>
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<MudContainer>
|
||||||
|
<MudStack AlignItems="AlignItems.Center">
|
||||||
|
<MudPagination Count="@TotalPages" @bind-Selected="_currentPage"/>
|
||||||
|
</MudStack>
|
||||||
|
</MudContainer>
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
//Search
|
//Filter
|
||||||
private string _searchString;
|
private string? _searchString;
|
||||||
|
|
||||||
//Filter Variables
|
|
||||||
private bool _showFilters;
|
private bool _showFilters;
|
||||||
private bool _showAlreadyAddedEntities = false;
|
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 ApplicationUser? _appUser;
|
||||||
private List<GlobalEntity> _globalEntities = [];
|
private List<GlobalEntity> _globalEntities = [];
|
||||||
private HashSet<int> _userPrivateEntityIds = [];
|
private HashSet<int> _userPrivateEntityIds = [];
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
_globalEntities = await CouchLogDb.GlobalEntities.OrderByDescending(entity => entity.CreationTime).ToListAsync();
|
|
||||||
|
|
||||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
_appUser = await UserManager.GetUserAsync(authState.User);
|
_appUser = await UserManager.GetUserAsync(authState.User);
|
||||||
|
|
||||||
@@ -138,30 +130,42 @@ TODO: Make Search work
|
|||||||
Snackbar.Add("Not authenticated.", Severity.Error);
|
Snackbar.Add("Not authenticated.", Severity.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_globalEntities = await CouchLogDb.GlobalEntities
|
||||||
|
.OrderByDescending(entity => entity.CreationTime)
|
||||||
|
.Where(entity => !entity.IsPrivate || (entity.IsPrivate && entity.CreatorId == _appUser.Id))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
_userPrivateEntityIds = await CouchLogDb.PrivateEntities
|
_userPrivateEntityIds = await CouchLogDb.PrivateEntities
|
||||||
.Where(entity => entity.UserId == _appUser.Id)
|
.Where(entity => entity.UserId == _appUser.Id)
|
||||||
.Select(p => p.GlobalEntityId)
|
.Select(p => p.GlobalEntityId)
|
||||||
.ToHashSetAsync();
|
.ToHashSetAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task RefreshPage()
|
||||||
|
{
|
||||||
|
_currentPage = 1;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnNewEntity(GlobalEntity entity)
|
||||||
|
{
|
||||||
|
_globalEntities.Add(entity);
|
||||||
|
await RefreshPage();
|
||||||
|
}
|
||||||
|
|
||||||
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");
|
||||||
}
|
var result = await dialog.Result;
|
||||||
|
if (!result!.Canceled)
|
||||||
private async Task<bool> IsFilterValid(GlobalEntity globalEntity)
|
|
||||||
{
|
|
||||||
if (!_showAlreadyAddedEntities && await IsInPrivateList(globalEntity.Id))
|
|
||||||
{
|
{
|
||||||
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;}
|
if(_appUser is null) { Snackbar.Add("Not logged in!", Severity.Error); return;}
|
||||||
|
|
||||||
@@ -178,6 +182,7 @@ TODO: Make Search work
|
|||||||
CouchLogDb.PrivateEntities.Add(privateEntity);
|
CouchLogDb.PrivateEntities.Add(privateEntity);
|
||||||
await CouchLogDb.SaveChangesAsync();
|
await CouchLogDb.SaveChangesAsync();
|
||||||
|
|
||||||
|
_userPrivateEntityIds.Add(globalEntity.Id);
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
Snackbar.Add("Added Entity to private List", Severity.Success);
|
Snackbar.Add("Added Entity to private List", Severity.Success);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,11 +48,11 @@
|
|||||||
<MudGrid Spacing="6" Justify="Justify.Center">
|
<MudGrid Spacing="6" Justify="Justify.Center">
|
||||||
@foreach (var privateEntity in ActiveWatchingEntities)
|
@foreach (var privateEntity in ActiveWatchingEntities)
|
||||||
{
|
{
|
||||||
<EntityCard PrivateEntity="privateEntity" />
|
<PrivateEntityCard PrivateEntity="privateEntity" />
|
||||||
}
|
}
|
||||||
@foreach (var privateEntity in LibraryEntities)
|
@foreach (var privateEntity in LibraryEntities)
|
||||||
{
|
{
|
||||||
<EntityCard PrivateEntity="privateEntity" />
|
<PrivateEntityCard PrivateEntity="privateEntity" />
|
||||||
}
|
}
|
||||||
</MudGrid>
|
</MudGrid>
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user