diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0e1afa8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "terminal.explorerKind": "integrated" +} \ No newline at end of file diff --git a/CouchLog/Components/Pages/GlobalList.razor b/CouchLog/Components/Pages/GlobalList.razor deleted file mode 100644 index e7ae57a..0000000 --- a/CouchLog/Components/Pages/GlobalList.razor +++ /dev/null @@ -1,351 +0,0 @@ -@page "/GlobalList" -@rendermode InteractiveServer - -@using Microsoft.AspNetCore.Authorization -@using CouchLog.Data -@using Microsoft.AspNetCore.Identity -@using Microsoft.EntityFrameworkCore - -@inject ApplicationDbContext CouchLogDB -@inject UserManager UserManager -@inject AuthenticationStateProvider AuthenticationStateProvider -@inject NavigationManager NavigationManager - -@attribute [Authorize] - -GlobalList - - - @*Top of the Page*@ - - @*Page Title*@ - Global List - - @*Spacer*@ - - - @*Button for adding GlobalEntity*@ - - - - - - -
- -
-

Global List

- -
-
-
- - - - -
- - - -
-
- - -
-
- - - @if (!string.IsNullOrEmpty(ImageString)) - { - - } -
-
- - @foreach(Genre Genre in Genres) - { - - } -
-
- -
- -
-
-
- - - -
- @foreach (var Entity in GlobalEntities) - { - if (!Entity.IsPrivate || (Entity.IsPrivate && (Entity.CreatorId == AppUser.Id))) - { -
-
- - - - - - -
- - - -
-
-

@Entity.Title

-
-
- - -
-
-
- - - } - } -
- -
- -@code -{ - private List MediaTypes = new List(); - private List Genres = new List(); - private List GlobalEntities = new List(); - private List GenreIds = new List(); - private HashSet UserPrivateEntityIds = new(); - private IBrowserFile? Picture; - System.Security.Claims.ClaimsPrincipal User = new(); - ApplicationUser AppUser = null!; - private GlobalEntity GlobalEntity = new(); - private bool isCollapseNewGlobalEntityOpen = false; - private int SelectedMediaTypeId; - private bool isPrivate = false; - private string ImageString = string.Empty; - - /// - /// - /// - /// - /// - protected override async Task OnInitializedAsync() - { - GlobalEntities = await CouchLogDB.GlobalEntities.OrderByDescending(Entity => Entity.CreationTime).ToListAsync(); - MediaTypes = await CouchLogDB.MediaType.OrderBy(Type => Type.Id).ToListAsync(); - Genres = await CouchLogDB.Genres.OrderBy(Genre => Genre.Name).ToListAsync(); - - var AuthState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); - User = AuthState.User; - - AppUser = (await UserManager.GetUserAsync(User))!; - - if (AppUser == null) - { - throw new NotImplementedException(); - } - - var TempUserPrivateEntityIds = await CouchLogDB.PrivateEntities - .Where(p => p.UserId == AppUser.Id) - .Select(p => p.GlobalEntityId) - .ToListAsync(); - - UserPrivateEntityIds = TempUserPrivateEntityIds.ToHashSet(); - } - - private async Task LoadImage(InputFileChangeEventArgs e) - { - Picture = e.File; - - foreach(var file in e.GetMultipleFiles()) - { - using var stream = file.OpenReadStream(); - using var ms = new MemoryStream(); - await stream.CopyToAsync(ms); - ImageString = $"data:{file.ContentType};base64,{Convert.ToBase64String(ms.ToArray())}"; - } - } - - /// - /// - /// - /// - /// - private async Task LoadFiles(InputFileChangeEventArgs eventArgs) - { - Picture = eventArgs.File; - - //Byte[] Buffer = new byte[Picture.Size]; - //await Picture.OpenReadStream().ReadAsync(Buffer); - //await Picture.OpenReadStream(maxAllowedSize: 10_000_000).ReadAsync(Buffer); - - //string Base64 = Convert.ToBase64String(Buffer); - //ImagePreviewUrl = $"data:{Picture.ContentType};base64,{Base64}"; - } - - /// - /// - /// - private void ToogleCollapseNewGlobalEntity() - { - isCollapseNewGlobalEntityOpen = !isCollapseNewGlobalEntityOpen; - StateHasChanged(); - } - - /// - /// - /// - /// - private async Task CreateNewGlobalEntity() - { - if (Picture is null) - { - throw new InvalidOperationException("No Picture selected."); - } - - if (AppUser is null) - { - throw new InvalidOperationException("User not loaded or not logged in."); - } - - //Save Picture and Name it - string NewFileName = $"{GlobalEntity.Title.Replace(" ", "-")}-{Guid.NewGuid()}{Path.GetExtension(Picture.Name)}"; - string PicturePath = Path.Combine("wwwroot", "Pictures", NewFileName); - using FileStream FileStream = File.Create(PicturePath); - await Picture.OpenReadStream().CopyToAsync(FileStream); - //await Picture.OpenReadStream(maxAllowedSize: 10_000_000).CopyToAsync(FileStream); - - GlobalEntity.PicturePath = $"Pictures/{NewFileName}"; - GlobalEntity.CreatorId = AppUser.Id; - GlobalEntity.TypeId = SelectedMediaTypeId; - GlobalEntity.CreationTime = DateTime.Now; - GlobalEntity.IsPrivate = isPrivate; - - CouchLogDB.Add(GlobalEntity); - await CouchLogDB.SaveChangesAsync(); - - foreach(int GenreId in GenreIds) - { - LinkTableGlobalGenre LinkTableGlobalGenre = new() { GenreId = GenreId, GlobalEntityId = GlobalEntity.Id }; - CouchLogDB.Add(LinkTableGlobalGenre); - } - - await CouchLogDB.SaveChangesAsync(); - NavigationManager.NavigateTo(NavigationManager.Uri, true); - } - - /// - /// - /// - /// - /// - private bool IsInPrivateList(int GolbalEntityId) - { - return UserPrivateEntityIds.Contains(GolbalEntityId); - } - - /// - /// - /// - /// - /// - private async Task AddToPrivateList(GlobalEntity GlobalEntity) - { - if(User.Identity?.IsAuthenticated == true) - { - if(!IsInPrivateList(GlobalEntity.Id)) - { - if (AppUser is null) - { - throw new InvalidOperationException("User not loaded or not logged in."); - } - - PrivateEntity PrivateEntity = new() - { - UserId = AppUser.Id, - CreationTime = DateTime.Now, - GlobalEntityId = GlobalEntity.Id, - UserWatchStatusId = 1, - }; - - CouchLogDB.PrivateEntities.Add(PrivateEntity); - await CouchLogDB.SaveChangesAsync(); - - UserPrivateEntityIds.Add(GlobalEntity.Id); - StateHasChanged(); - } - } - } - - private void AddGenreToList(int GenreId) - { - if (!GenreIds.Contains(GenreId)) - { - GenreIds.Add(GenreId); - } - } - - private async Task DeleteEntity(GlobalEntity entity) - { - if(entity.PicturePath != null) - { - try - { - File.Delete(Path.Combine("wwwroot", entity.PicturePath)); - } - catch(Exception) - { - } - } - - CouchLogDB.GlobalEntities.Remove(entity); - - await CouchLogDB.SaveChangesAsync(); - - NavigationManager.NavigateTo(NavigationManager.Uri, true); - } -} \ No newline at end of file diff --git a/CouchLog/Components/Pages/GlobalList.razor.css b/CouchLog/Components/Pages/GlobalList.razor.css deleted file mode 100644 index 344f6d3..0000000 --- a/CouchLog/Components/Pages/GlobalList.razor.css +++ /dev/null @@ -1,88 +0,0 @@ -/*For Development*/ -/** { - outline: 1px solid red !important; -}*/ - -.Entity-Container { - color:aliceblue -} - - .Entity-Container:hover { - color: rgba(0,255,255,0.5); - } - -.Entity-Container-Card { - position: relative; - max-width: 275px; - background: #111; - display: flex; - flex-direction: column; - align-items: center; - overflow: hidden; - border-radius: 15px; - transition: all 0.5s ease; - text-align: center; - gap: 0.75rem; - padding-top: 10px; - padding-bottom: 24px; -} - - - .Entity-Container-Card h2 { - color: #0ff; - font-size: 2rem; - position: relative; - z-index: 2; - margin: 0; - } - - .Entity-Container-Card::before { - content: ''; - position: absolute; - top: -50%; - left: -50%; - width: 200%; - height: 200%; - background: linear-gradient( 0deg, transparent, transparent 30%, rgba(0,255,255,0.3) ); - transform: rotate(-45deg); - transition: all 0.5s ease; - opacity: 0; - } - - .Entity-Container-Card:hover { - transform: scale(1.05); - box-shadow: 0 0 20px rgba(0,255,255,0.5); - } - - .Entity-Container-Card:hover::before { - opacity: 1; - transform: rotate(-45deg) translateY(100%); - } - -.Entity-Container-Image { - margin: 4px; - margin-top: 6px; - max-width: 256px; - max-height: 256px; -} - -.Entity-Container-Button { - display: flex; - flex-direction: column -} - -.CreateNewGlobalEntity-Container { - background: #111; - border-radius: 15px; -} - -.Entity-Container-Menu-Button { - position: absolute; - top: 2px; - right: 7.5px; - background: transparent; - border: none; - color: #0dcaf0; - font-size: 2.5rem; - cursor: pointer; -} \ No newline at end of file diff --git a/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor b/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor new file mode 100644 index 0000000..7b3515f --- /dev/null +++ b/CouchLog/Components/Pages/GlobalList/Dialogs/AddNewGlobalEntityDialog.razor @@ -0,0 +1,146 @@ +@using CouchLog.Data +@using Microsoft.EntityFrameworkCore + +@using Microsoft.AspNetCore.Authorization +@using CouchLog.Data +@using Microsoft.AspNetCore.Identity +@using Microsoft.EntityFrameworkCore + +@inject ApplicationDbContext CouchLogDB +@inject UserManager UserManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@inject NavigationManager NavigationManager + + + + + Add Global Entity + + + + + + + +
+ + + +
+
+ + +
+ @*
+ + + @if (!string.IsNullOrEmpty(ImageString)) + { + + } +
*@ +
+ + @foreach(Genre Genre in Genres) + { + + } +
+
+ +
+ +
+
+ + @*Dialog Footer*@ + + Cancel + +
+ +@code { + private ApplicationUser AppUser = null!; + + [CascadingParameter] + private IMudDialogInstance MudDialog { get; set; } + private void Cancel() => MudDialog.Cancel(); + + + private List MediaTypes = new(); + private List Genres = new(); + + #region ForNewGlobalEntity + private GlobalEntity newGlobalEntity = new(); + private IBrowserFile? Picture; + private int SelectedMediaTypeId; + private bool IsPrivate; + private List GenreIds = new (); + #endregion + + protected override async Task OnInitializedAsync() + { + var AuthState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + var User = AuthState.User; + AppUser = (await UserManager.GetUserAsync(User))!; + + if(AppUser == null) + { + throw new Exception("Not Authenticated"); + } + + MediaTypes = await CouchLogDB.MediaType.OrderBy(Type => Type.Id).ToListAsync(); + Genres = await CouchLogDB.Genres.OrderBy(Type => Type.Id).ToListAsync(); + } + + private async Task CreateNewGlobalEntity() + { + if (Picture is null) + { + throw new InvalidOperationException("No Picture selected."); + } + + if (AppUser is null) + { + throw new InvalidOperationException("User not loaded or not logged in."); + } + + //Save Picture and Name it + string NewFileName = $"{newGlobalEntity.Title.Replace(" ", "-")}-{Guid.NewGuid()}{Path.GetExtension(Picture.Name)}"; + string PicturePath = Path.Combine("wwwroot", "Pictures", NewFileName); + using FileStream FileStream = File.Create(PicturePath); + await Picture.OpenReadStream().CopyToAsync(FileStream); + //await Picture.OpenReadStream(maxAllowedSize: 10_000_000).CopyToAsync(FileStream); + + newGlobalEntity.PicturePath = $"Pictures/{NewFileName}"; + newGlobalEntity.CreatorId = AppUser.Id; + newGlobalEntity.TypeId = SelectedMediaTypeId; + newGlobalEntity.CreationTime = DateTime.Now; + newGlobalEntity.IsPrivate = IsPrivate; + + CouchLogDB.Add(newGlobalEntity); + await CouchLogDB.SaveChangesAsync(); + + foreach(int GenreId in GenreIds) + { + LinkTableGlobalGenre LinkTableGlobalGenre = new() { GenreId = GenreId, GlobalEntityId = newGlobalEntity.Id }; + CouchLogDB.Add(LinkTableGlobalGenre); + } + + await CouchLogDB.SaveChangesAsync(); + NavigationManager.NavigateTo(NavigationManager.Uri, true); + } + + private void AddGenreIdToGenreIdList(int GenreId) + { + if (!GenreIds.Contains(GenreId)) + { + GenreIds.Add(GenreId); + } + } +} \ No newline at end of file diff --git a/CouchLog/Components/Pages/GlobalList/GlobalList.razor b/CouchLog/Components/Pages/GlobalList/GlobalList.razor new file mode 100644 index 0000000..53927f2 --- /dev/null +++ b/CouchLog/Components/Pages/GlobalList/GlobalList.razor @@ -0,0 +1,45 @@ +@page "/GlobalList" +@rendermode InteractiveServer + +@using Microsoft.AspNetCore.Authorization +@using CouchLog.Data +@using Microsoft.AspNetCore.Identity +@using Microsoft.EntityFrameworkCore +@using CouchLog.Components.Pages.GlobalList.Dialogs + +@inject ApplicationDbContext CouchLogDB +@inject UserManager UserManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@inject NavigationManager NavigationManager +@inject IDialogService DialogService + +@attribute [Authorize] + +GlobalList + + + @*Top of the Page*@ + + + @*Page Title*@ + Global List + + @*Spacer*@ + + + @*Button for adding GlobalEntity*@ + + + + + + + + +@code +{ + private async Task OpenAddNewGlobalEntityDialog() + { + var dialog = await DialogService.ShowAsync("Add new Global Entity"); + } +} \ No newline at end of file diff --git a/CouchLog/appsettings.json b/CouchLog/appsettings.json index 2a4260b..20cf621 100644 --- a/CouchLog/appsettings.json +++ b/CouchLog/appsettings.json @@ -6,6 +6,13 @@ "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" + }, + "Console": { + "FormatterName": "simple", + "FormatterOptions": { + "TimestampFormat": "[HH:mm:ss]", + "SingleLine": true + } } }, "AllowedHosts": "*"