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 @using CouchLog.Data
<MudCard> <MudCard>
<MudPaper Elevation="0" Style="position: relative;"> <MudPaper Elevation="0" Style="position: relative;" @onmouseenter="@(() => _showEditOverlay = true)" @onmouseleave="@(() => _showEditOverlay = false)">
<MudCardMedia Image="@GlobalEntity.PicturePath" Height="400" Style="object-fit: contain;"/> <MudCardMedia Image="@($"{GlobalEntity.PicturePath}?v={DateTime.Now.Ticks}")" 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" /> <MudOverlay Visible="@_showEditOverlay" DarkBackground="true" Absolute="true">
<MudIconButton Icon="@Icons.Material.Rounded.Edit" Color="Color.Primary" OnClick="@(()=> OnEdit.InvokeAsync(GlobalEntity))" />
</MudOverlay>
</MudPaper> </MudPaper>
<MudCardContent> <MudCardContent>
<MudTooltip Text="@GlobalEntity.Title"> <MudTooltip Text="@GlobalEntity.Title">
@@ -37,4 +39,7 @@
[Parameter] public EventCallback<GlobalEntity> OnAddToPrivate { get; set; } [Parameter] public EventCallback<GlobalEntity> OnAddToPrivate { get; set; }
[Parameter] public EventCallback<GlobalEntity> OnAddToShared { get; set; } [Parameter] public EventCallback<GlobalEntity> OnAddToShared { get; set; }
[Parameter] public EventCallback<GlobalEntity> OnEdit { get; set; }
private bool _showEditOverlay;
} }
@@ -22,10 +22,10 @@
</TitleContent> </TitleContent>
<DialogContent> <DialogContent>
<EditForm EditContext="_editContext" OnSubmit="HandleSubmit"> <EditForm EditContext="_editContext" OnSubmit="HandleSubmit" id="New-Global-Entity-Form">
<DataAnnotationsValidator /> <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">--> <!--<editor-fold desc="Picture-Upload">-->
<MudPaper Class="pa-0" Elevation="0" Width="280px" MinWidth="280px"> <MudPaper Class="pa-0" Elevation="0" Width="280px" MinWidth="280px">
@if (!string.IsNullOrWhiteSpace(_imagePreview)) @if (!string.IsNullOrWhiteSpace(_imagePreview))
@@ -43,13 +43,12 @@
Accept="image/*" Accept="image/*"
InputClass="null" InputClass="null"
Class="mud-file-upload-dragarea"> Class="mud-file-upload-dragarea">
<SelectedTemplate Context="SelectedTemplateContext"/> <SelectedTemplate Context="selectedTemplateContext"/>
</MudFileUpload> </MudFileUpload>
} }
</MudPaper> </MudPaper>
<!--</editor-fold>--> <!--</editor-fold>-->
<MudPaper Class="flex-grow-1" Elevation="0" MinWidth="200px">
<MudPaper Class="flex-grow-1" Elevation="0">
<MudStack Spacing="3"> <MudStack Spacing="3">
<MudTextField @bind-Value="_form.Title" <MudTextField @bind-Value="_form.Title"
@@ -78,17 +77,6 @@
} }
</MudSelect> </MudSelect>
<MudCheckBox @bind-Value="_isPrivate" Label="Is Private" Color="Color.Primary" /> <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">
@if (_isSaving)
{
<MudProgressCircular Indeterminate="true" Size="Size.Small" Class="mr-2" />
<span>Saving...</span>
}
else
{
<span>Create Global Entity</span>
}
</MudButton>
</MudStack> </MudStack>
</MudPaper> </MudPaper>
</MudStack> </MudStack>
@@ -96,7 +84,18 @@
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<MudButton OnClick="Cancel" Variant="Variant.Text" Disabled="_isSaving">Cancel</MudButton> <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"/>
<span>Saving...</span>
}
else
{
<span>Create Global Entity</span>
}
</MudButton>
</DialogActions> </DialogActions>
</MudDialog> </MudDialog>
File diff suppressed because one or more lines are too long
@@ -82,7 +82,8 @@
<GlobalEntityCard GlobalEntity="globalEntity" <GlobalEntityCard GlobalEntity="globalEntity"
UserPrivateEntityIds="_userPrivateEntityIds" UserPrivateEntityIds="_userPrivateEntityIds"
OnAddToPrivate="AddGlobalEntityToPrivateList" OnAddToPrivate="AddGlobalEntityToPrivateList"
OnAddToShared="AddGlobalEntityToSharedList"/> OnAddToShared="AddGlobalEntityToSharedList"
OnEdit="OpenEditGlobalEntityDialog"/>
</MudItem> </MudItem>
} }
</MudGrid> </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) 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;}
@@ -17,7 +17,9 @@
<MudStack Class="pa-3" Spacing="2"> <MudStack Class="pa-3" Spacing="2">
<!--<editor-fold desc="Options">--> <!--<editor-fold desc="Options">-->
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween"> <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"> <MudMenu Icon="@Icons.Material.Filled.MoreVert" Color="Color.Default" Dense="true">
<MudMenuItem>Edit</MudMenuItem> <MudMenuItem>Edit</MudMenuItem>
<MudMenuItem OnClick="@(() => OnRemove.InvokeAsync())">Remove</MudMenuItem> <MudMenuItem OnClick="@(() => OnRemove.InvokeAsync())">Remove</MudMenuItem>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 KiB