Enhance ConfirmDialog with customizable button styles and add PDF opening functionality in AccountDetail

This commit is contained in:
2026-03-31 19:21:14 +02:00
parent 68e4e1aa4b
commit c376c70fec
4 changed files with 64 additions and 2 deletions

View File

@@ -4,7 +4,7 @@
<p>@Message</p> <p>@Message</p>
<div class="d-flex justify-content-end gap-2"> <div class="d-flex justify-content-end gap-2">
<button class="btn btn-outline-secondary" @onclick="Cancel"><i class="bi bi-x-lg"></i> @CancelText</button> <button class="btn btn-outline-secondary" @onclick="Cancel"><i class="bi bi-x-lg"></i> @CancelText</button>
<button class="btn btn-danger" @onclick="Confirm"><i class="bi bi-trash"></i> @ConfirmText</button> <button class="@ConfirmButtonClass" @onclick="Confirm"><i class="@ConfirmIconClass"></i> @ConfirmText</button>
</div> </div>
</div> </div>
</div> </div>
@@ -14,6 +14,8 @@
[Parameter] public string Message { get; set; } = "Sind Sie sicher?"; [Parameter] public string Message { get; set; } = "Sind Sie sicher?";
[Parameter] public string ConfirmText { get; set; } = "Ja, bestätigen"; [Parameter] public string ConfirmText { get; set; } = "Ja, bestätigen";
[Parameter] public string CancelText { get; set; } = "Nein, abbrechen"; [Parameter] public string CancelText { get; set; } = "Nein, abbrechen";
[Parameter] public string ConfirmButtonClass { get; set; } = "btn btn-danger";
[Parameter] public string ConfirmIconClass { get; set; } = "bi bi-trash";
[Parameter] public EventCallback OnConfirm { get; set; } [Parameter] public EventCallback OnConfirm { get; set; }
[Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnCancel { get; set; }

View File

@@ -144,6 +144,18 @@
OnCancel="CancelRestoreConfirm" /> OnCancel="CancelRestoreConfirm" />
} }
@if (!string.IsNullOrWhiteSpace(savedPdfPath))
{
<ConfirmDialog Title="PDF öffnen"
Message="Die PDF wurde gespeichert. Möchten Sie sie jetzt öffnen?"
ConfirmText="Ja, öffnen"
CancelText="Nein"
ConfirmButtonClass="btn btn-primary"
ConfirmIconClass="bi bi-box-arrow-up-right"
OnConfirm="HandleOpenSavedPdf"
OnCancel="CancelOpenSavedPdf" />
}
@if (editingEntry != null) @if (editingEntry != null)
{ {
<AddEntryDialog AccountId="AccountId" <AddEntryDialog AccountId="AccountId"
@@ -176,6 +188,8 @@
private int? confirmRestoreEntryId; private int? confirmRestoreEntryId;
private string? confirmRestoreEntryTitle; private string? confirmRestoreEntryTitle;
private string? savedPdfPath;
private EntryDto? editingEntry; private EntryDto? editingEntry;
private EntryDto? editingTransferEntry; private EntryDto? editingTransferEntry;
@@ -291,7 +305,22 @@
{ {
var pdf = await PdfStatementService.GenerateStatementAsync(AccountId, showCurrentYearOnly); var pdf = await PdfStatementService.GenerateStatementAsync(AccountId, showCurrentYearOnly);
var suffix = showCurrentYearOnly ? $"_{DateTime.Now.Year}" : "_Gesamt"; var suffix = showCurrentYearOnly ? $"_{DateTime.Now.Year}" : "_Gesamt";
await FileSaveService.SaveFileAsync(pdf, $"{account?.Name}{suffix}.pdf"); savedPdfPath = await FileSaveService.SaveFileAsync(pdf, $"{account?.Name}{suffix}.pdf");
}
private async Task HandleOpenSavedPdf()
{
if (!string.IsNullOrWhiteSpace(savedPdfPath))
{
await FileSaveService.OpenFileAsync(savedPdfPath);
}
savedPdfPath = null;
}
private void CancelOpenSavedPdf()
{
savedPdfPath = null;
} }
private static string FormatAmount(decimal amount) => $"{amount:N2} €"; private static string FormatAmount(decimal amount) => $"{amount:N2} €";

View File

@@ -3,4 +3,5 @@ namespace Duempelkas.App.Services;
public interface IFileSaveService public interface IFileSaveService
{ {
Task<string?> SaveFileAsync(byte[] content, string suggestedFileName); Task<string?> SaveFileAsync(byte[] content, string suggestedFileName);
Task OpenFileAsync(string filePath);
} }

View File

@@ -15,6 +15,36 @@ public class FileSaveService : IFileSaveService
return filePath; return filePath;
} }
public Task OpenFileAsync(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
{
return Task.CompletedTask;
}
return Task.Run(() =>
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.Start(new ProcessStartInfo
{
FileName = filePath,
UseShellExecute = true
});
return;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", filePath);
return;
}
Process.Start("xdg-open", filePath);
});
}
private static Task<string?> ShowSaveDialogAsync(string suggestedFileName) private static Task<string?> ShowSaveDialogAsync(string suggestedFileName)
{ {
return Task.Run(() => return Task.Run(() =>