Improvement of the ReviewAttachmentsDialog: add delete function and check for existence of the file

This commit is contained in:
hart_s3 2025-12-16 12:24:12 +01:00
parent a3deec9e5c
commit ca141e3ebd
2 changed files with 37 additions and 4 deletions

View File

@ -7,10 +7,35 @@
<DialogContent> <DialogContent>
@foreach (var filePath in this.DocumentPaths) @foreach (var filePath in this.DocumentPaths)
{ {
<MudMenuItem @if (File.Exists(filePath))
Icon="@Icons.Material.Filled.AttachFile" {
Label="@Path.GetFileName(filePath)"> <MudStack Row Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Class="mb-2">
</MudMenuItem> <MudIcon Icon="@Icons.Material.Filled.AttachFile" Class="mr-2"/>
<MudText Class="flex-grow-1 overflow-hidden text-ellipsis" Style="white-space: nowrap;">
@Path.GetFileName(filePath)
</MudText>
<MudIconButton Icon="@Icons.Material.Filled.Delete"
Color="Color.Error"
Class="ml-2"
OnClick="@(() => DeleteAttachment(filePath))"/>
</MudStack>
}
else
{
<MudStack Row Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Class="mb-2">
<MudText Class="flex-grow-1 overflow-hidden text-ellipsis" Style="white-space: nowrap;">
<s>@Path.GetFileName(filePath)</s>
</MudText>
<MudIconButton Icon="@Icons.Material.Filled.Delete"
Color="Color.Error"
Class="ml-2"
OnClick="@(() => DeleteAttachment(filePath))"/>
</MudStack>
}
} }
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>

View File

@ -33,4 +33,12 @@ public partial class ReviewAttachmentsDialog : MSGComponentBase
return dialogResult.Data as HashSet<string> ?? documentPaths; return dialogResult.Data as HashSet<string> ?? documentPaths;
} }
private void DeleteAttachment(string filePath)
{
if (this.DocumentPaths.Remove(filePath))
{
this.StateHasChanged();
}
}
} }