feat: added GlobalEntity Edit

This commit is contained in:
2026-07-09 00:00:36 +02:00
parent e4d392c535
commit 4b90abd58a
6 changed files with 383 additions and 26 deletions
@@ -1,9 +1,11 @@
@using CouchLog.Data
<MudCard>
<MudPaper Elevation="0" Style="position: relative;">
<MudCardMedia Image="@GlobalEntity.PicturePath" Height="400" Style="object-fit: contain;"/>
<MudIconButton Icon="@Icons.Material.Rounded.Edit" Style="position: absolute; top: 8px; right: 8px; z-index: 1; background: black" Color="Color.Primary" />
<MudPaper Elevation="0" Style="position: relative;" @onmouseenter="@(() => _showEditOverlay = true)" @onmouseleave="@(() => _showEditOverlay = false)">
<MudCardMedia Image="@($"{GlobalEntity.PicturePath}?v={DateTime.Now.Ticks}")" Height="400" Style="object-fit: contain;"/>
<MudOverlay Visible="@_showEditOverlay" DarkBackground="true" Absolute="true">
<MudIconButton Icon="@Icons.Material.Rounded.Edit" Color="Color.Primary" OnClick="@(()=> OnEdit.InvokeAsync(GlobalEntity))" />
</MudOverlay>
</MudPaper>
<MudCardContent>
<MudTooltip Text="@GlobalEntity.Title">
@@ -37,4 +39,7 @@
[Parameter] public EventCallback<GlobalEntity> OnAddToPrivate { get; set; }
[Parameter] public EventCallback<GlobalEntity> OnAddToShared { get; set; }
[Parameter] public EventCallback<GlobalEntity> OnEdit { get; set; }
private bool _showEditOverlay;
}
@@ -22,10 +22,10 @@
</TitleContent>
<DialogContent>
<EditForm EditContext="_editContext" OnSubmit="HandleSubmit">
<EditForm EditContext="_editContext" OnSubmit="HandleSubmit" id="New-Global-Entity-Form">
<DataAnnotationsValidator />
<MudStack Row="true" Spacing="3" AlignItems="AlignItems.Start" Style="min-height: 400px;">
<MudStack Row="true" Spacing="3" AlignItems="AlignItems.Start" Style="min-height: 400px;" Breakpoint="Breakpoint.SmAndDown">
<!--<editor-fold desc="Picture-Upload">-->
<MudPaper Class="pa-0" Elevation="0" Width="280px" MinWidth="280px">
@if (!string.IsNullOrWhiteSpace(_imagePreview))
@@ -43,13 +43,12 @@
Accept="image/*"
InputClass="null"
Class="mud-file-upload-dragarea">
<SelectedTemplate Context="SelectedTemplateContext"/>
<SelectedTemplate Context="selectedTemplateContext"/>
</MudFileUpload>
}
</MudPaper>
<!--</editor-fold>-->
<MudPaper Class="flex-grow-1" Elevation="0">
<MudPaper Class="flex-grow-1" Elevation="0" MinWidth="200px">
<MudStack Spacing="3">
<MudTextField @bind-Value="_form.Title"
@@ -78,7 +77,15 @@
}
</MudSelect>
<MudCheckBox @bind-Value="_isPrivate" Label="Is Private" Color="Color.Primary" />
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Success" Disabled="_isSaving" Class="mt-3">
</MudStack>
</MudPaper>
</MudStack>
</EditForm>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel" Variant="Variant.Filled" Color="Color.Error" Disabled="_isSaving" Class="mt-3">Cancel</MudButton>
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Success" Disabled="_isSaving" Class="mt-3" form="New-Global-Entity-Form">
@if (_isSaving)
{
<MudProgressCircular Indeterminate="true" Size="Size.Small" Class="mr-2"/>
@@ -89,14 +96,6 @@
<span>Create Global Entity</span>
}
</MudButton>
</MudStack>
</MudPaper>
</MudStack>
</EditForm>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel" Variant="Variant.Text" Disabled="_isSaving">Cancel</MudButton>
</DialogActions>
</MudDialog>
File diff suppressed because one or more lines are too long
@@ -82,7 +82,8 @@
<GlobalEntityCard GlobalEntity="globalEntity"
UserPrivateEntityIds="_userPrivateEntityIds"
OnAddToPrivate="AddGlobalEntityToPrivateList"
OnAddToShared="AddGlobalEntityToSharedList"/>
OnAddToShared="AddGlobalEntityToSharedList"
OnEdit="OpenEditGlobalEntityDialog"/>
</MudItem>
}
</MudGrid>
@@ -166,6 +167,44 @@
}
}
private async Task OpenEditGlobalEntityDialog(GlobalEntity globalEntity)
{
var parameters = new DialogParameters<EditGlobalEntityDialog>
{
{ x => x.GlobalEntity, globalEntity },
{ x => x.AppUser, _appUser}
};
var dialog = await DialogService.ShowAsync<EditGlobalEntityDialog>("Edit Global Entity", parameters);
var result = await dialog.Result;
if (!result!.Canceled && result.Data is ValueTuple<GlobalEntity, bool> data)
{
if (data.Item2)
{
CouchLogDb.GlobalEntities.Remove(data.Item1);
await CouchLogDb.SaveChangesAsync();
_globalEntities.RemoveAll(x => x.Id == data.Item1.Id);
if (_currentPage > TotalPages)
_currentPage = Math.Max(1, TotalPages);
StateHasChanged();
}
if (!data.Item2)
{
int index = _globalEntities.FindIndex(x => x.Id == data.Item1.Id);
if (index >= 0)
{
_globalEntities[index] = data.Item1;
}
StateHasChanged();
}
}
}
public async Task AddGlobalEntityToPrivateList(GlobalEntity globalEntity)
{
if(_appUser is null) { Snackbar.Add("Not logged in!", Severity.Error); return;}
@@ -17,7 +17,9 @@
<MudStack Class="pa-3" Spacing="2">
<!--<editor-fold desc="Options">-->
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.h6" Style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap">@PrivateEntity.GlobalEntity.Title</MudText>
<MudTooltip Text="@PrivateEntity.GlobalEntity.Title">
<MudText Typo="Typo.h6" Style="display: block; max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">@PrivateEntity.GlobalEntity.Title</MudText>
</MudTooltip>
<MudMenu Icon="@Icons.Material.Filled.MoreVert" Color="Color.Default" Dense="true">
<MudMenuItem>Edit</MudMenuItem>
<MudMenuItem OnClick="@(() => OnRemove.InvokeAsync())">Remove</MudMenuItem>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 KiB