refactor(app): move account razor inline code to partial classes
This commit is contained in:
@@ -9,8 +9,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public AccountSummaryDto Account { get; set; } = default!;
|
|
||||||
|
|
||||||
private void Navigate() => Navigation.NavigateTo($"/accounts/{Account.Id}");
|
|
||||||
}
|
|
||||||
|
|||||||
20
src/Duempelkas.App/Components/Accounts/AccountCard.razor.cs
Normal file
20
src/Duempelkas.App/Components/Accounts/AccountCard.razor.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Duempelkas.App.Services.Models;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Duempelkas.App.Components.Accounts;
|
||||||
|
|
||||||
|
public partial class AccountCard
|
||||||
|
{
|
||||||
|
#region Parameters
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public AccountSummaryDto Account { get; set; } = default!;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Actions
|
||||||
|
|
||||||
|
private void Navigate() => Navigation.NavigateTo($"/accounts/{Account.Id}");
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -7,6 +7,3 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public List<AccountSummaryDto> Accounts { get; set; } = new();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Duempelkas.App.Services.Models;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Duempelkas.App.Components.Accounts;
|
||||||
|
|
||||||
|
public partial class AccountCardList
|
||||||
|
{
|
||||||
|
#region Parameters
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public List<AccountSummaryDto> Accounts { get; set; } = new();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -34,17 +34,3 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public EntryDto Entry { get; set; } = default!;
|
|
||||||
[Parameter] public EventCallback<int> OnDelete { get; set; }
|
|
||||||
[Parameter] public EventCallback<int> OnRestore { get; set; }
|
|
||||||
[Parameter] public EventCallback<int> OnEdit { get; set; }
|
|
||||||
|
|
||||||
private string GetRowClass()
|
|
||||||
{
|
|
||||||
var classes = new List<string>();
|
|
||||||
if (Entry.IsTransfer) classes.Add("entry-row-transfer");
|
|
||||||
if (Entry.IsDeleted) classes.Add("entry-deleted");
|
|
||||||
return string.Join(" ", classes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
43
src/Duempelkas.App/Components/Accounts/EntryRow.razor.cs
Normal file
43
src/Duempelkas.App/Components/Accounts/EntryRow.razor.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using Duempelkas.App.Services.Models;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Duempelkas.App.Components.Accounts;
|
||||||
|
|
||||||
|
public partial class EntryRow
|
||||||
|
{
|
||||||
|
#region Parameters
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EntryDto Entry { get; set; } = default!;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<int> OnDelete { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<int> OnRestore { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<int> OnEdit { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Helpers
|
||||||
|
|
||||||
|
private string GetRowClass()
|
||||||
|
{
|
||||||
|
var classes = new List<string>();
|
||||||
|
if (Entry.IsTransfer)
|
||||||
|
{
|
||||||
|
classes.Add("entry-row-transfer");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Entry.IsDeleted)
|
||||||
|
{
|
||||||
|
classes.Add("entry-deleted");
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(" ", classes);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -23,9 +23,3 @@
|
|||||||
<div class="text-center py-3 text-muted">Keine Buchungen vorhanden.</div>
|
<div class="text-center py-3 text-muted">Keine Buchungen vorhanden.</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public List<EntryDto> Entries { get; set; } = new();
|
|
||||||
[Parameter] public EventCallback<int> OnDeleteEntry { get; set; }
|
|
||||||
[Parameter] public EventCallback<int> OnRestoreEntry { get; set; }
|
|
||||||
[Parameter] public EventCallback<int> OnEditEntry { get; set; }
|
|
||||||
}
|
|
||||||
|
|||||||
23
src/Duempelkas.App/Components/Accounts/EntryTable.razor.cs
Normal file
23
src/Duempelkas.App/Components/Accounts/EntryTable.razor.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using Duempelkas.App.Services.Models;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Duempelkas.App.Components.Accounts;
|
||||||
|
|
||||||
|
public partial class EntryTable
|
||||||
|
{
|
||||||
|
#region Parameters
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public List<EntryDto> Entries { get; set; } = new();
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<int> OnDeleteEntry { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<int> OnRestoreEntry { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<int> OnEditEntry { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -179,156 +179,3 @@
|
|||||||
OnCancel="() => editingTransferEntry = null" />
|
OnCancel="() => editingTransferEntry = null" />
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public int AccountId { get; set; }
|
|
||||||
|
|
||||||
private AccountSummaryDto? account;
|
|
||||||
private AccountBalanceDto? balance;
|
|
||||||
private List<EntryDto>? entries;
|
|
||||||
private bool showAddEntry, showAddTransfer;
|
|
||||||
private bool showEditName, showEditCarryover;
|
|
||||||
private bool showCurrentYearOnly = true;
|
|
||||||
|
|
||||||
private int? confirmDeleteEntryId;
|
|
||||||
private string? confirmDeleteEntryTitle;
|
|
||||||
|
|
||||||
private int? confirmRestoreEntryId;
|
|
||||||
private string? confirmRestoreEntryTitle;
|
|
||||||
|
|
||||||
private string? savedPdfPath;
|
|
||||||
|
|
||||||
private EntryDto? editingEntry;
|
|
||||||
private EntryDto? editingTransferEntry;
|
|
||||||
|
|
||||||
private void NavigateBack() => Navigation.NavigateTo("/");
|
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
|
||||||
{
|
|
||||||
await LoadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task LoadAll()
|
|
||||||
{
|
|
||||||
account = await AccountService.GetAccountAsync(AccountId);
|
|
||||||
balance = await BalanceQueryService.GetAccountBalanceAsync(AccountId);
|
|
||||||
entries = await EntryService.GetEntriesAsync(AccountId, showCurrentYearOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ToggleYearFilter()
|
|
||||||
{
|
|
||||||
showCurrentYearOnly = !showCurrentYearOnly;
|
|
||||||
entries = await EntryService.GetEntriesAsync(AccountId, showCurrentYearOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleSaveName(string newName)
|
|
||||||
{
|
|
||||||
await AccountService.RenameAccountAsync(AccountId, newName);
|
|
||||||
showEditName = false;
|
|
||||||
await LoadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleSaveCarryover(decimal newAmount)
|
|
||||||
{
|
|
||||||
await AccountService.UpdateCarryoverAsync(AccountId, newAmount);
|
|
||||||
showEditCarryover = false;
|
|
||||||
await LoadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleEntryCreated()
|
|
||||||
{
|
|
||||||
showAddEntry = false;
|
|
||||||
await LoadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleTransferCreated()
|
|
||||||
{
|
|
||||||
showAddTransfer = false;
|
|
||||||
await LoadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RequestDeleteEntry(int entryId)
|
|
||||||
{
|
|
||||||
confirmDeleteEntryId = entryId;
|
|
||||||
confirmDeleteEntryTitle = entries?.FirstOrDefault(e => e.Id == entryId)?.Title;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CancelDeleteConfirm()
|
|
||||||
{
|
|
||||||
confirmDeleteEntryId = null;
|
|
||||||
confirmDeleteEntryTitle = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleConfirmDelete()
|
|
||||||
{
|
|
||||||
if (confirmDeleteEntryId.HasValue)
|
|
||||||
{
|
|
||||||
await EntryService.DeleteEntryAsync(confirmDeleteEntryId.Value);
|
|
||||||
confirmDeleteEntryId = null;
|
|
||||||
confirmDeleteEntryTitle = null;
|
|
||||||
await LoadAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RequestRestoreEntry(int entryId)
|
|
||||||
{
|
|
||||||
confirmRestoreEntryId = entryId;
|
|
||||||
confirmRestoreEntryTitle = entries?.FirstOrDefault(e => e.Id == entryId)?.Title;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CancelRestoreConfirm()
|
|
||||||
{
|
|
||||||
confirmRestoreEntryId = null;
|
|
||||||
confirmRestoreEntryTitle = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleConfirmRestore()
|
|
||||||
{
|
|
||||||
if (confirmRestoreEntryId.HasValue)
|
|
||||||
{
|
|
||||||
await EntryService.RestoreEntryAsync(confirmRestoreEntryId.Value);
|
|
||||||
confirmRestoreEntryId = null;
|
|
||||||
confirmRestoreEntryTitle = null;
|
|
||||||
await LoadAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RequestEditEntry(int entryId)
|
|
||||||
{
|
|
||||||
var entry = entries?.FirstOrDefault(e => e.Id == entryId);
|
|
||||||
if (entry?.IsTransfer == true)
|
|
||||||
editingTransferEntry = entry;
|
|
||||||
else
|
|
||||||
editingEntry = entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleEntryEdited()
|
|
||||||
{
|
|
||||||
editingEntry = null;
|
|
||||||
editingTransferEntry = null;
|
|
||||||
await LoadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleExport()
|
|
||||||
{
|
|
||||||
var pdf = await PdfStatementService.GenerateStatementAsync(AccountId, showCurrentYearOnly);
|
|
||||||
var suffix = showCurrentYearOnly ? $"_{DateTime.Now.Year}" : "_Gesamt";
|
|
||||||
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} €";
|
|
||||||
}
|
|
||||||
|
|||||||
194
src/Duempelkas.App/Pages/Accounts/AccountDetail.razor.cs
Normal file
194
src/Duempelkas.App/Pages/Accounts/AccountDetail.razor.cs
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
using Duempelkas.App.Services.Models;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Duempelkas.App.Pages.Accounts;
|
||||||
|
|
||||||
|
public partial class AccountDetail
|
||||||
|
{
|
||||||
|
#region Parameters
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public int AccountId { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Fields
|
||||||
|
|
||||||
|
private AccountSummaryDto? account;
|
||||||
|
private AccountBalanceDto? balance;
|
||||||
|
private List<EntryDto>? entries;
|
||||||
|
private bool showAddEntry;
|
||||||
|
private bool showAddTransfer;
|
||||||
|
private bool showEditName;
|
||||||
|
private bool showEditCarryover;
|
||||||
|
private bool showCurrentYearOnly = true;
|
||||||
|
|
||||||
|
private int? confirmDeleteEntryId;
|
||||||
|
private string? confirmDeleteEntryTitle;
|
||||||
|
|
||||||
|
private int? confirmRestoreEntryId;
|
||||||
|
private string? confirmRestoreEntryTitle;
|
||||||
|
|
||||||
|
private string? savedPdfPath;
|
||||||
|
|
||||||
|
private EntryDto? editingEntry;
|
||||||
|
private EntryDto? editingTransferEntry;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Navigation
|
||||||
|
|
||||||
|
private void NavigateBack() => Navigation.NavigateTo("/");
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Lifecycle
|
||||||
|
|
||||||
|
protected override async Task OnParametersSetAsync()
|
||||||
|
{
|
||||||
|
await LoadAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Data Loading
|
||||||
|
|
||||||
|
private async Task LoadAll()
|
||||||
|
{
|
||||||
|
account = await AccountService.GetAccountAsync(AccountId);
|
||||||
|
balance = await BalanceQueryService.GetAccountBalanceAsync(AccountId);
|
||||||
|
entries = await EntryService.GetEntriesAsync(AccountId, showCurrentYearOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ToggleYearFilter()
|
||||||
|
{
|
||||||
|
showCurrentYearOnly = !showCurrentYearOnly;
|
||||||
|
entries = await EntryService.GetEntriesAsync(AccountId, showCurrentYearOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Actions
|
||||||
|
|
||||||
|
private async Task HandleSaveName(string newName)
|
||||||
|
{
|
||||||
|
await AccountService.RenameAccountAsync(AccountId, newName);
|
||||||
|
showEditName = false;
|
||||||
|
await LoadAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleSaveCarryover(decimal newAmount)
|
||||||
|
{
|
||||||
|
await AccountService.UpdateCarryoverAsync(AccountId, newAmount);
|
||||||
|
showEditCarryover = false;
|
||||||
|
await LoadAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleEntryCreated()
|
||||||
|
{
|
||||||
|
showAddEntry = false;
|
||||||
|
await LoadAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleTransferCreated()
|
||||||
|
{
|
||||||
|
showAddTransfer = false;
|
||||||
|
await LoadAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RequestDeleteEntry(int entryId)
|
||||||
|
{
|
||||||
|
confirmDeleteEntryId = entryId;
|
||||||
|
confirmDeleteEntryTitle = entries?.FirstOrDefault(e => e.Id == entryId)?.Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CancelDeleteConfirm()
|
||||||
|
{
|
||||||
|
confirmDeleteEntryId = null;
|
||||||
|
confirmDeleteEntryTitle = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleConfirmDelete()
|
||||||
|
{
|
||||||
|
if (confirmDeleteEntryId.HasValue)
|
||||||
|
{
|
||||||
|
await EntryService.DeleteEntryAsync(confirmDeleteEntryId.Value);
|
||||||
|
confirmDeleteEntryId = null;
|
||||||
|
confirmDeleteEntryTitle = null;
|
||||||
|
await LoadAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RequestRestoreEntry(int entryId)
|
||||||
|
{
|
||||||
|
confirmRestoreEntryId = entryId;
|
||||||
|
confirmRestoreEntryTitle = entries?.FirstOrDefault(e => e.Id == entryId)?.Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CancelRestoreConfirm()
|
||||||
|
{
|
||||||
|
confirmRestoreEntryId = null;
|
||||||
|
confirmRestoreEntryTitle = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleConfirmRestore()
|
||||||
|
{
|
||||||
|
if (confirmRestoreEntryId.HasValue)
|
||||||
|
{
|
||||||
|
await EntryService.RestoreEntryAsync(confirmRestoreEntryId.Value);
|
||||||
|
confirmRestoreEntryId = null;
|
||||||
|
confirmRestoreEntryTitle = null;
|
||||||
|
await LoadAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RequestEditEntry(int entryId)
|
||||||
|
{
|
||||||
|
var entry = entries?.FirstOrDefault(e => e.Id == entryId);
|
||||||
|
if (entry?.IsTransfer == true)
|
||||||
|
{
|
||||||
|
editingTransferEntry = entry;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
editingEntry = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleEntryEdited()
|
||||||
|
{
|
||||||
|
editingEntry = null;
|
||||||
|
editingTransferEntry = null;
|
||||||
|
await LoadAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleExport()
|
||||||
|
{
|
||||||
|
var pdf = await PdfStatementService.GenerateStatementAsync(AccountId, showCurrentYearOnly);
|
||||||
|
var suffix = showCurrentYearOnly ? $"_{DateTime.Now.Year}" : "_Gesamt";
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Helpers
|
||||||
|
|
||||||
|
private static string FormatAmount(decimal amount) => $"{amount:N2} €";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user