Add Blazor application layer with UI components and pages
- Service interfaces and DTO models - Dashboard page with account overview - Account detail page with year/entry management - Reusable components: AccountCard, EntryTable, YearSelector - Dialog components: Add/Edit Account, Entry, Transfer, Year - Main layout and routing configuration
This commit is contained in:
298
src/Duempelkas.App/Pages/Accounts/AccountDetail.razor
Normal file
298
src/Duempelkas.App/Pages/Accounts/AccountDetail.razor
Normal file
@@ -0,0 +1,298 @@
|
||||
@page "/accounts/{AccountId:int}"
|
||||
@inject IAccountService AccountService
|
||||
@inject IEntryService EntryService
|
||||
@inject IBalanceQueryService BalanceQueryService
|
||||
@inject IPdfStatementService PdfStatementService
|
||||
@inject IFileSaveService FileSaveService
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<div class="container-fluid">
|
||||
@if (account == null)
|
||||
{
|
||||
<div class="text-center py-5">
|
||||
<div class="spinner-border" role="status"></div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="d-flex align-items-center gap-2 mb-3">
|
||||
<button class="btn btn-outline-secondary btn-sm flex-shrink-0" @onclick="NavigateBack">
|
||||
<i class="bi bi-arrow-left"></i> Zurück
|
||||
</button>
|
||||
<div class="d-flex align-items-center flex-grow-1" style="min-width: 0;">
|
||||
<h2 class="mb-0" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
|
||||
@account.Name
|
||||
<button class="btn-edit-pen" @onclick="() => showEditName = true" title="Name bearbeiten"><i class="bi bi-pencil"></i></button>
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (balance != null)
|
||||
{
|
||||
<div class="summary-section mb-3">
|
||||
<div class="summary-flex">
|
||||
<div>
|
||||
<small class="text-muted">Saldo</small>
|
||||
<div class="fs-3 fw-bold @(balance.TotalBalance >= 0 ? "amount-positive" : "amount-negative")">
|
||||
@FormatAmount(balance.TotalBalance)
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end">
|
||||
<small class="text-muted">Einnahmen</small>
|
||||
<div class="amount-positive">@FormatAmount(showCurrentYearOnly ? balance.CurrentYearIncome : balance.TotalIncome)</div>
|
||||
</div>
|
||||
<div class="text-end">
|
||||
<small class="text-muted">Ausgaben</small>
|
||||
<div class="amount-negative">@FormatAmount(showCurrentYearOnly ? balance.CurrentYearExpense : balance.TotalExpense)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (showCurrentYearOnly)
|
||||
{
|
||||
<div class="summary-section mb-3">
|
||||
<div class="summary-flex">
|
||||
<div>
|
||||
<small class="text-muted">Übertrag von @(DateTime.Now.Year - 1)</small>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<span class="fw-bold">@FormatAmount(balance.CarryoverBalance)</span>
|
||||
<button class="btn-edit-pen" @onclick="() => showEditCarryover = true" title="Übertrag bearbeiten">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end">
|
||||
<small class="text-muted">Umsätze @DateTime.Now.Year</small>
|
||||
<div class="fw-bold @(balance.CurrentYearIncome - balance.CurrentYearExpense >= 0 ? "amount-positive" : "amount-negative")">
|
||||
@FormatAmount(balance.CurrentYearIncome - balance.CurrentYearExpense)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<div class="d-flex align-items-center gap-2 mb-3 py-3 flex-wrap">
|
||||
<button class="btn btn-success btn-sm" @onclick="() => showAddEntry = true">
|
||||
<i class="bi bi-plus-lg"></i> Eintrag
|
||||
</button>
|
||||
<button class="btn btn-info btn-sm" @onclick="() => showAddTransfer = true">
|
||||
<i class="bi bi-arrow-left-right"></i> Umbuchung
|
||||
</button>
|
||||
<button class="btn btn-dark btn-sm" @onclick="HandleExport">
|
||||
<i class="bi bi-file-earmark-pdf"></i> PDF
|
||||
</button>
|
||||
<button class="btn btn-sm @(showCurrentYearOnly ? "btn-primary" : "btn-outline-secondary")" @onclick="ToggleYearFilter">
|
||||
<i class="bi bi-funnel"></i> @(showCurrentYearOnly ? $"Nur {DateTime.Now.Year}" : "Alle Einträge")
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (entries != null)
|
||||
{
|
||||
<div class="entries-scroll-wrapper">
|
||||
<EntryTable Entries="entries" OnDeleteEntry="RequestDeleteEntry" OnRestoreEntry="RequestRestoreEntry" OnEditEntry="RequestEditEntry" />
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (showAddEntry)
|
||||
{
|
||||
<AddEntryDialog AccountId="AccountId"
|
||||
OnSave="HandleEntryCreated"
|
||||
OnCancel="() => showAddEntry = false" />
|
||||
}
|
||||
|
||||
@if (showAddTransfer)
|
||||
{
|
||||
<AddTransferDialog SourceAccountId="AccountId"
|
||||
OnSave="HandleTransferCreated"
|
||||
OnCancel="() => showAddTransfer = false" />
|
||||
}
|
||||
|
||||
@if (showEditName)
|
||||
{
|
||||
<EditNameDialog CurrentName="@(account?.Name ?? "")"
|
||||
OnSave="HandleSaveName"
|
||||
OnCancel="() => showEditName = false" />
|
||||
}
|
||||
|
||||
@if (showEditCarryover)
|
||||
{
|
||||
<EditCarryoverDialog CurrentAmount="@(balance?.CarryoverBalance ?? 0)"
|
||||
OnSave="HandleSaveCarryover"
|
||||
OnCancel="() => showEditCarryover = false" />
|
||||
}
|
||||
|
||||
@if (confirmDeleteEntryId.HasValue)
|
||||
{
|
||||
<ConfirmDialog Title="Eintrag löschen"
|
||||
Message="@($"Soll \"{confirmDeleteEntryTitle}\" wirklich gelöscht werden?")"
|
||||
ConfirmText="Ja, löschen"
|
||||
CancelText="Nein, abbrechen"
|
||||
OnConfirm="HandleConfirmDelete"
|
||||
OnCancel="CancelDeleteConfirm" />
|
||||
}
|
||||
|
||||
@if (confirmRestoreEntryId.HasValue)
|
||||
{
|
||||
<ConfirmDialog Title="Eintrag wiederherstellen"
|
||||
Message="@($"Soll \"{confirmRestoreEntryTitle}\" wiederhergestellt werden?")"
|
||||
ConfirmText="Ja, wiederherstellen"
|
||||
CancelText="Nein, abbrechen"
|
||||
OnConfirm="HandleConfirmRestore"
|
||||
OnCancel="CancelRestoreConfirm" />
|
||||
}
|
||||
|
||||
@if (editingEntry != null)
|
||||
{
|
||||
<AddEntryDialog AccountId="AccountId"
|
||||
EditEntry="editingEntry"
|
||||
OnSave="HandleEntryEdited"
|
||||
OnCancel="() => editingEntry = null" />
|
||||
}
|
||||
|
||||
@if (editingTransferEntry != null)
|
||||
{
|
||||
<AddTransferDialog SourceAccountId="AccountId"
|
||||
EditEntry="editingTransferEntry"
|
||||
OnSave="HandleEntryEdited"
|
||||
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 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";
|
||||
await FileSaveService.SaveFileAsync(pdf, $"{account?.Name}{suffix}.pdf");
|
||||
}
|
||||
|
||||
private static string FormatAmount(decimal amount) => $"{amount:N2} €";
|
||||
}
|
||||
Reference in New Issue
Block a user