From b8b1c74a841d8cdbe97f1cdf06fc4db3971cfc54 Mon Sep 17 00:00:00 2001 From: troogs Date: Fri, 3 Apr 2026 12:59:11 +0200 Subject: [PATCH] refactor(app): extract dialog component logic to code-behind --- .../Components/Dialogs/AddAccountDialog.razor | 14 ---- .../Dialogs/AddAccountDialog.razor.cs | 36 +++++++++ .../Components/Dialogs/AddEntryDialog.razor | 33 -------- .../Dialogs/AddEntryDialog.razor.cs | 68 ++++++++++++++++ .../Dialogs/AddTransferDialog.razor | 39 --------- .../Dialogs/AddTransferDialog.razor.cs | 79 +++++++++++++++++++ .../Components/Dialogs/ConfirmDialog.razor | 13 --- .../Components/Dialogs/ConfirmDialog.razor.cs | 42 ++++++++++ .../Dialogs/EditCarryoverDialog.razor | 13 --- .../Dialogs/EditCarryoverDialog.razor.cs | 39 +++++++++ .../Components/Dialogs/EditNameDialog.razor | 19 ----- .../Dialogs/EditNameDialog.razor.cs | 51 ++++++++++++ 12 files changed, 315 insertions(+), 131 deletions(-) create mode 100644 src/Duempelkas.App/Components/Dialogs/AddAccountDialog.razor.cs create mode 100644 src/Duempelkas.App/Components/Dialogs/AddEntryDialog.razor.cs create mode 100644 src/Duempelkas.App/Components/Dialogs/AddTransferDialog.razor.cs create mode 100644 src/Duempelkas.App/Components/Dialogs/ConfirmDialog.razor.cs create mode 100644 src/Duempelkas.App/Components/Dialogs/EditCarryoverDialog.razor.cs create mode 100644 src/Duempelkas.App/Components/Dialogs/EditNameDialog.razor.cs diff --git a/src/Duempelkas.App/Components/Dialogs/AddAccountDialog.razor b/src/Duempelkas.App/Components/Dialogs/AddAccountDialog.razor index e0200a9..86758ae 100644 --- a/src/Duempelkas.App/Components/Dialogs/AddAccountDialog.razor +++ b/src/Duempelkas.App/Components/Dialogs/AddAccountDialog.razor @@ -13,17 +13,3 @@ -@code { - [Parameter] public EventCallback OnSave { get; set; } - [Parameter] public EventCallback OnCancel { get; set; } - - private string name = string.Empty; - - private async Task Save() - { - if (!string.IsNullOrWhiteSpace(name)) - await OnSave.InvokeAsync(name.Trim()); - } - - private async Task Cancel() => await OnCancel.InvokeAsync(); -} diff --git a/src/Duempelkas.App/Components/Dialogs/AddAccountDialog.razor.cs b/src/Duempelkas.App/Components/Dialogs/AddAccountDialog.razor.cs new file mode 100644 index 0000000..1ea57cd --- /dev/null +++ b/src/Duempelkas.App/Components/Dialogs/AddAccountDialog.razor.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.Components; + +namespace Duempelkas.App.Components.Dialogs; + +public partial class AddAccountDialog +{ + #region Parameters + + [Parameter] + public EventCallback OnSave { get; set; } + + [Parameter] + public EventCallback OnCancel { get; set; } + + #endregion + + #region Fields + + private string name = string.Empty; + + #endregion + + #region Actions + + private async Task Save() + { + if (!string.IsNullOrWhiteSpace(name)) + { + await OnSave.InvokeAsync(name.Trim()); + } + } + + private async Task Cancel() => await OnCancel.InvokeAsync(); + + #endregion +} diff --git a/src/Duempelkas.App/Components/Dialogs/AddEntryDialog.razor b/src/Duempelkas.App/Components/Dialogs/AddEntryDialog.razor index 2258098..bfda88b 100644 --- a/src/Duempelkas.App/Components/Dialogs/AddEntryDialog.razor +++ b/src/Duempelkas.App/Components/Dialogs/AddEntryDialog.razor @@ -34,36 +34,3 @@ -@code { - [Parameter] public int AccountId { get; set; } - [Parameter] public EntryDto? EditEntry { get; set; } - [Parameter] public EventCallback OnSave { get; set; } - [Parameter] public EventCallback OnCancel { get; set; } - - private EntryType entryType = EntryType.Income; - private DateTime date = DateTime.Today; - private string title = string.Empty; - private decimal amount; - - protected override void OnParametersSet() - { - if (EditEntry != null) - { - entryType = EditEntry.Type; - date = EditEntry.Date; - title = EditEntry.Title; - amount = EditEntry.Amount; - } - } - - private async Task Save() - { - if (EditEntry != null) - await EntryService.UpdateEntryAsync(EditEntry.Id, date, title.Trim(), amount); - else - await EntryService.CreateEntryAsync(AccountId, entryType, date, title.Trim(), amount); - await OnSave.InvokeAsync(); - } - - private async Task Cancel() => await OnCancel.InvokeAsync(); -} diff --git a/src/Duempelkas.App/Components/Dialogs/AddEntryDialog.razor.cs b/src/Duempelkas.App/Components/Dialogs/AddEntryDialog.razor.cs new file mode 100644 index 0000000..327dbbd --- /dev/null +++ b/src/Duempelkas.App/Components/Dialogs/AddEntryDialog.razor.cs @@ -0,0 +1,68 @@ +using Duempelkas.App.Services.Models; +using Duempelkas.Domain.Enums; +using Microsoft.AspNetCore.Components; + +namespace Duempelkas.App.Components.Dialogs; + +public partial class AddEntryDialog +{ + #region Parameters + + [Parameter] + public int AccountId { get; set; } + + [Parameter] + public EntryDto? EditEntry { get; set; } + + [Parameter] + public EventCallback OnSave { get; set; } + + [Parameter] + public EventCallback OnCancel { get; set; } + + #endregion + + #region Fields + + private EntryType entryType = EntryType.Income; + private DateTime date = DateTime.Today; + private string title = string.Empty; + private decimal amount; + + #endregion + + #region Lifecycle + + protected override void OnParametersSet() + { + if (EditEntry != null) + { + entryType = EditEntry.Type; + date = EditEntry.Date; + title = EditEntry.Title; + amount = EditEntry.Amount; + } + } + + #endregion + + #region Actions + + private async Task Save() + { + if (EditEntry != null) + { + await EntryService.UpdateEntryAsync(EditEntry.Id, date, title.Trim(), amount); + } + else + { + await EntryService.CreateEntryAsync(AccountId, entryType, date, title.Trim(), amount); + } + + await OnSave.InvokeAsync(); + } + + private async Task Cancel() => await OnCancel.InvokeAsync(); + + #endregion +} diff --git a/src/Duempelkas.App/Components/Dialogs/AddTransferDialog.razor b/src/Duempelkas.App/Components/Dialogs/AddTransferDialog.razor index 150f00d..7af9882 100644 --- a/src/Duempelkas.App/Components/Dialogs/AddTransferDialog.razor +++ b/src/Duempelkas.App/Components/Dialogs/AddTransferDialog.razor @@ -33,42 +33,3 @@ -@code { - [Parameter] public int SourceAccountId { get; set; } - [Parameter] public EntryDto? EditEntry { get; set; } - [Parameter] public EventCallback OnSave { get; set; } - [Parameter] public EventCallback OnCancel { get; set; } - - private List accounts = new(); - private int targetAccountId; - private DateTime date = DateTime.Today; - private string title = string.Empty; - private decimal amount; - - private bool CanSave => targetAccountId > 0 && !string.IsNullOrWhiteSpace(title) && amount > 0; - - protected override async Task OnParametersSetAsync() - { - if (!accounts.Any()) - accounts = await AccountService.GetAllAccountsAsync(); - - if (EditEntry != null) - { - targetAccountId = EditEntry.LinkedAccountId ?? 0; - date = EditEntry.Date; - title = EditEntry.Title; - amount = EditEntry.Amount; - } - } - - private async Task Save() - { - if (EditEntry != null) - await EntryService.UpdateTransferAsync(EditEntry.Id, targetAccountId, date, title.Trim(), amount); - else - await EntryService.CreateTransferAsync(SourceAccountId, targetAccountId, date, title.Trim(), amount); - await OnSave.InvokeAsync(); - } - - private async Task Cancel() => await OnCancel.InvokeAsync(); -} diff --git a/src/Duempelkas.App/Components/Dialogs/AddTransferDialog.razor.cs b/src/Duempelkas.App/Components/Dialogs/AddTransferDialog.razor.cs new file mode 100644 index 0000000..28bb846 --- /dev/null +++ b/src/Duempelkas.App/Components/Dialogs/AddTransferDialog.razor.cs @@ -0,0 +1,79 @@ +using Duempelkas.App.Services.Models; +using Microsoft.AspNetCore.Components; + +namespace Duempelkas.App.Components.Dialogs; + +public partial class AddTransferDialog +{ + #region Parameters + + [Parameter] + public int SourceAccountId { get; set; } + + [Parameter] + public EntryDto? EditEntry { get; set; } + + [Parameter] + public EventCallback OnSave { get; set; } + + [Parameter] + public EventCallback OnCancel { get; set; } + + #endregion + + #region Fields + + private List accounts = new(); + private int targetAccountId; + private DateTime date = DateTime.Today; + private string title = string.Empty; + private decimal amount; + + #endregion + + #region Properties + + private bool CanSave => targetAccountId > 0 && !string.IsNullOrWhiteSpace(title) && amount > 0; + + #endregion + + #region Lifecycle + + protected override async Task OnParametersSetAsync() + { + if (!accounts.Any()) + { + accounts = await AccountService.GetAllAccountsAsync(); + } + + if (EditEntry != null) + { + targetAccountId = EditEntry.LinkedAccountId ?? 0; + date = EditEntry.Date; + title = EditEntry.Title; + amount = EditEntry.Amount; + } + } + + #endregion + + #region Actions + + private async Task Save() + { + if (EditEntry != null) + { + await EntryService.UpdateTransferAsync(EditEntry.Id, targetAccountId, date, title.Trim(), amount); + } + else + { + await EntryService.CreateTransferAsync(SourceAccountId, targetAccountId, date, title.Trim(), amount); + } + + await OnSave.InvokeAsync(); + } + + private async Task Cancel() => await OnCancel.InvokeAsync(); + + #endregion +} diff --git a/src/Duempelkas.App/Components/Dialogs/ConfirmDialog.razor b/src/Duempelkas.App/Components/Dialogs/ConfirmDialog.razor index 6f36c13..38cfe92 100644 --- a/src/Duempelkas.App/Components/Dialogs/ConfirmDialog.razor +++ b/src/Duempelkas.App/Components/Dialogs/ConfirmDialog.razor @@ -9,16 +9,3 @@ -@code { - [Parameter] public string Title { get; set; } = "Bestätigung"; - [Parameter] public string Message { get; set; } = "Sind Sie sicher?"; - [Parameter] public string ConfirmText { get; set; } = "Ja, bestätigen"; - [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 OnCancel { get; set; } - - private async Task Confirm() => await OnConfirm.InvokeAsync(); - private async Task Cancel() => await OnCancel.InvokeAsync(); -} diff --git a/src/Duempelkas.App/Components/Dialogs/ConfirmDialog.razor.cs b/src/Duempelkas.App/Components/Dialogs/ConfirmDialog.razor.cs new file mode 100644 index 0000000..0516e86 --- /dev/null +++ b/src/Duempelkas.App/Components/Dialogs/ConfirmDialog.razor.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Components; + +namespace Duempelkas.App.Components.Dialogs; + +public partial class ConfirmDialog +{ + #region Parameters + + [Parameter] + public string Title { get; set; } = "Bestätigung"; + + [Parameter] + public string Message { get; set; } = "Sind Sie sicher?"; + + [Parameter] + public string ConfirmText { get; set; } = "Ja, bestätigen"; + + [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 OnCancel { get; set; } + + #endregion + + #region Actions + + private async Task Confirm() => await OnConfirm.InvokeAsync(); + + private async Task Cancel() => await OnCancel.InvokeAsync(); + + #endregion +} diff --git a/src/Duempelkas.App/Components/Dialogs/EditCarryoverDialog.razor b/src/Duempelkas.App/Components/Dialogs/EditCarryoverDialog.razor index 2f8f97a..f74e34c 100644 --- a/src/Duempelkas.App/Components/Dialogs/EditCarryoverDialog.razor +++ b/src/Duempelkas.App/Components/Dialogs/EditCarryoverDialog.razor @@ -12,16 +12,3 @@ -@code { - [Parameter] public decimal CurrentAmount { get; set; } - [Parameter] public EventCallback OnSave { get; set; } - [Parameter] public EventCallback OnCancel { get; set; } - - private decimal amount; - - protected override void OnParametersSet() => amount = CurrentAmount; - - private async Task Save() => await OnSave.InvokeAsync(amount); - - private async Task Cancel() => await OnCancel.InvokeAsync(); -} diff --git a/src/Duempelkas.App/Components/Dialogs/EditCarryoverDialog.razor.cs b/src/Duempelkas.App/Components/Dialogs/EditCarryoverDialog.razor.cs new file mode 100644 index 0000000..9ba813a --- /dev/null +++ b/src/Duempelkas.App/Components/Dialogs/EditCarryoverDialog.razor.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Components; + +namespace Duempelkas.App.Components.Dialogs; + +public partial class EditCarryoverDialog +{ + #region Parameters + + [Parameter] + public decimal CurrentAmount { get; set; } + + [Parameter] + public EventCallback OnSave { get; set; } + + [Parameter] + public EventCallback OnCancel { get; set; } + + #endregion + + #region Fields + + private decimal amount; + + #endregion + + #region Lifecycle + + protected override void OnParametersSet() => amount = CurrentAmount; + + #endregion + + #region Actions + + private async Task Save() => await OnSave.InvokeAsync(amount); + + private async Task Cancel() => await OnCancel.InvokeAsync(); + + #endregion +} diff --git a/src/Duempelkas.App/Components/Dialogs/EditNameDialog.razor b/src/Duempelkas.App/Components/Dialogs/EditNameDialog.razor index f66ca09..b998bf7 100644 --- a/src/Duempelkas.App/Components/Dialogs/EditNameDialog.razor +++ b/src/Duempelkas.App/Components/Dialogs/EditNameDialog.razor @@ -12,22 +12,3 @@ -@code { - [Parameter] public string CurrentName { get; set; } = string.Empty; - [Parameter] public string DialogTitle { get; set; } = "Kontoname bearbeiten"; - [Parameter] public string NameLabel { get; set; } = "Kontoname"; - [Parameter] public EventCallback OnSave { get; set; } - [Parameter] public EventCallback OnCancel { get; set; } - - private string name = string.Empty; - - protected override void OnParametersSet() => name = CurrentName; - - private async Task Save() - { - if (!string.IsNullOrWhiteSpace(name)) - await OnSave.InvokeAsync(name.Trim()); - } - - private async Task Cancel() => await OnCancel.InvokeAsync(); -} diff --git a/src/Duempelkas.App/Components/Dialogs/EditNameDialog.razor.cs b/src/Duempelkas.App/Components/Dialogs/EditNameDialog.razor.cs new file mode 100644 index 0000000..cef5344 --- /dev/null +++ b/src/Duempelkas.App/Components/Dialogs/EditNameDialog.razor.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Components; + +namespace Duempelkas.App.Components.Dialogs; + +public partial class EditNameDialog +{ + #region Parameters + + [Parameter] + public string CurrentName { get; set; } = string.Empty; + + [Parameter] + public string DialogTitle { get; set; } = "Kontoname bearbeiten"; + + [Parameter] + public string NameLabel { get; set; } = "Kontoname"; + + [Parameter] + public EventCallback OnSave { get; set; } + + [Parameter] + public EventCallback OnCancel { get; set; } + + #endregion + + #region Fields + + private string name = string.Empty; + + #endregion + + #region Lifecycle + + protected override void OnParametersSet() => name = CurrentName; + + #endregion + + #region Actions + + private async Task Save() + { + if (!string.IsNullOrWhiteSpace(name)) + { + await OnSave.InvokeAsync(name.Trim()); + } + } + + private async Task Cancel() => await OnCancel.InvokeAsync(); + + #endregion +}