diff --git a/CouchLog/Components/Pages/GlobalList/Components/GlobalEntityCard.razor b/CouchLog/Components/Pages/GlobalList/Components/GlobalEntityCard.razor new file mode 100644 index 0000000..331cc85 --- /dev/null +++ b/CouchLog/Components/Pages/GlobalList/Components/GlobalEntityCard.razor @@ -0,0 +1,37 @@ +@using CouchLog.Data + + + + + + + @GlobalEntity.Title + + + + + + + @if (UserPrivateEntityIds.Contains(GlobalEntity.Id)) + { + + + + } + else + { + + + + } + + + +@code +{ + [Parameter] public GlobalEntity GlobalEntity { get; set; } = null!; + [Parameter] public HashSet UserPrivateEntityIds { get; set; } = null!; + + [Parameter] public EventCallback OnAddToPrivate { get; set; } + [Parameter] public EventCallback OnAddToShared { get; set; } +} diff --git a/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor b/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor index 8f16d64..53a185e 100644 --- a/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor +++ b/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor @@ -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) { diff --git a/CouchLog/Components/Pages/GlobalList/GlobalList.razor b/CouchLog/Components/Pages/GlobalList/GlobalList.razor index ded1ba3..f2e6c18 100644 --- a/CouchLog/Components/Pages/GlobalList/GlobalList.razor +++ b/CouchLog/Components/Pages/GlobalList/GlobalList.razor @@ -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 UserManager @@ -16,11 +17,6 @@ @attribute [Authorize] GlobalList -@* -TODO: Add Paging -TODO: Add only reload for the pages -TODO: Make Search work -*@ @*Top of the Page*@ @@ -44,6 +40,7 @@ TODO: Make Search work + @*Search bar*@ + @*Refresh button*@ + @* + + *@ + @*More Filters button*@ + Color="Color.Default"/> + @*Entity allready added*@ Show already added Entities + @*To be exstendet*@ @@ -72,64 +76,52 @@ TODO: Make Search work - @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)) - { - - - - - - - @globalEntity.Title - - - - - - - @if (_userPrivateEntityIds.Contains(globalEntity.Id)) - { - - - - } - else - { - - - - } - - - - } - } + + + } + +
+ + + + + +
@code { - //Search - private string _searchString; - - //Filter Variables + //Filter + private string? _searchString; private bool _showFilters; private bool _showAlreadyAddedEntities = false; + + private IEnumerable 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 VisibleGlobalEntities => FiltertGlobalEntities.Skip((_currentPage - 1) * _pageSize).Take(_pageSize); + + //Core private ApplicationUser? _appUser; private List _globalEntities = []; private HashSet _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); @@ -138,30 +130,42 @@ TODO: Make Search work Snackbar.Add("Not authenticated.", Severity.Error); 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("Add new Global Entity"); - } - - private async Task 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); } diff --git a/CouchLog/Components/Pages/PrivateList/Components/EntityCard.razor b/CouchLog/Components/Pages/PrivateList/Components/PrivateEntityCard.razor similarity index 100% rename from CouchLog/Components/Pages/PrivateList/Components/EntityCard.razor rename to CouchLog/Components/Pages/PrivateList/Components/PrivateEntityCard.razor diff --git a/CouchLog/Components/Pages/PrivateList/PrivateList.razor b/CouchLog/Components/Pages/PrivateList/PrivateList.razor index e1e4602..b233252 100644 --- a/CouchLog/Components/Pages/PrivateList/PrivateList.razor +++ b/CouchLog/Components/Pages/PrivateList/PrivateList.razor @@ -48,11 +48,11 @@ @foreach (var privateEntity in ActiveWatchingEntities) { - + } @foreach (var privateEntity in LibraryEntities) { - + }