refactor(app): split dashboard settings and layout into partial classes

This commit is contained in:
2026-04-03 12:59:16 +02:00
parent b8b1c74a84
commit 08185f88cd
6 changed files with 218 additions and 155 deletions
-110
View File
@@ -5,7 +5,6 @@
@inject IPdfStatementService PdfStatementService
@inject IFileSaveService FileSaveService
@inject NavigationManager NavigationManager
@using System.Globalization
<div class="container-fluid">
@@ -108,112 +107,3 @@
OnCancel="CancelRestoreConfirm" />
}
@code {
private List<AccountSummaryDto>? accounts;
private bool showAddAccount;
private bool showEditClubName;
private bool showRestoreConfirm;
private string clubName = string.Empty;
private string? operationMessage;
private string operationMessageClass = "alert-info";
private string? savedPdfPath;
private string DisplayClubName => string.IsNullOrWhiteSpace(clubName) ? "Mein Verein" : clubName;
private decimal TotalClubBalance => accounts?.Sum(a => a.TotalBalance) ?? 0m;
protected override async Task OnInitializedAsync()
{
await LoadClubName();
await LoadAccounts();
}
private async Task LoadAccounts()
{
accounts = await AccountService.GetAllAccountsAsync();
}
private async Task LoadClubName()
{
clubName = await SettingsService.GetClubNameAsync() ?? string.Empty;
}
private async Task HandleAccountCreated(string name)
{
await AccountService.CreateAccountAsync(name);
showAddAccount = false;
await LoadAccounts();
}
private async Task HandleSaveClubName(string newName)
{
await SettingsService.SetClubNameAsync(newName);
showEditClubName = false;
await LoadClubName();
}
private async Task HandleBackupAsync()
{
var message = await BackupService.CreateBackupAsync();
if(message.Contains("fehlgeschlagen", StringComparison.OrdinalIgnoreCase)) {
SetOperationMessage(message, false);
}
}
private Task HandleRestoreAsync()
{
showRestoreConfirm = true;
return Task.CompletedTask;
}
private void CancelRestoreConfirm()
{
showRestoreConfirm = false;
}
private async Task HandleConfirmRestore()
{
showRestoreConfirm = false;
var message = await BackupService.RestoreBackupAsync();
var isSuccess = message.StartsWith("Wiederherstellung erfolgreich", StringComparison.OrdinalIgnoreCase);
if (isSuccess)
{
// Reload the Blazor app so all components/services re-query from restored DB.
NavigationManager.NavigateTo("/", forceLoad: true);
} else {
SetOperationMessage(message, isSuccess);
}
}
private async Task HandleDashboardExportAsync()
{
var pdf = await PdfStatementService.GenerateDashboardStatementAsync();
savedPdfPath = await FileSaveService.SaveFileAsync(pdf, $"{DisplayClubName}_Übersicht.pdf");
}
private async Task HandleOpenSavedPdf()
{
if (!string.IsNullOrWhiteSpace(savedPdfPath))
{
await FileSaveService.OpenFileAsync(savedPdfPath);
}
savedPdfPath = null;
}
private void CancelOpenSavedPdf()
{
savedPdfPath = null;
}
private void SetOperationMessage(string message, bool success)
{
operationMessage = message;
operationMessageClass = success ? "alert-success" : "alert-danger";
}
private static string FormatCurrency(decimal amount)
{
return amount.ToString("N2", CultureInfo.GetCultureInfo("de-DE")) + " €";
}
}
+142
View File
@@ -0,0 +1,142 @@
using System.Globalization;
using Duempelkas.App.Services.Models;
namespace Duempelkas.App.Pages;
public partial class Dashboard
{
#region Fields
private List<AccountSummaryDto>? accounts;
private bool showAddAccount;
private bool showEditClubName;
private bool showRestoreConfirm;
private string clubName = string.Empty;
private string? operationMessage;
private string operationMessageClass = "alert-info";
private string? savedPdfPath;
#endregion
#region Properties
private string DisplayClubName => string.IsNullOrWhiteSpace(clubName) ? "Mein Verein" : clubName;
private decimal TotalClubBalance => accounts?.Sum(a => a.TotalBalance) ?? 0m;
#endregion
#region Lifecycle
protected override async Task OnInitializedAsync()
{
await LoadClubName();
await LoadAccounts();
}
#endregion
#region Data Loading
private async Task LoadAccounts()
{
accounts = await AccountService.GetAllAccountsAsync();
}
private async Task LoadClubName()
{
clubName = await SettingsService.GetClubNameAsync() ?? string.Empty;
}
#endregion
#region Actions
private async Task HandleAccountCreated(string name)
{
await AccountService.CreateAccountAsync(name);
showAddAccount = false;
await LoadAccounts();
}
private async Task HandleSaveClubName(string newName)
{
await SettingsService.SetClubNameAsync(newName);
showEditClubName = false;
await LoadClubName();
}
private async Task HandleBackupAsync()
{
var message = await BackupService.CreateBackupAsync();
if (message.Contains("fehlgeschlagen", StringComparison.OrdinalIgnoreCase))
{
SetOperationMessage(message, false);
}
}
private Task HandleRestoreAsync()
{
showRestoreConfirm = true;
return Task.CompletedTask;
}
private void CancelRestoreConfirm()
{
showRestoreConfirm = false;
}
private async Task HandleConfirmRestore()
{
showRestoreConfirm = false;
var message = await BackupService.RestoreBackupAsync();
var isSuccess = message.StartsWith("Wiederherstellung erfolgreich", StringComparison.OrdinalIgnoreCase);
if (isSuccess)
{
NavigationManager.NavigateTo("/", forceLoad: true);
}
else
{
SetOperationMessage(message, isSuccess);
}
}
private async Task HandleDashboardExportAsync()
{
var pdf = await PdfStatementService.GenerateDashboardStatementAsync();
savedPdfPath = await FileSaveService.SaveFileAsync(pdf, $"{DisplayClubName}_Übersicht.pdf");
}
private async Task HandleOpenSavedPdf()
{
if (!string.IsNullOrWhiteSpace(savedPdfPath))
{
await FileSaveService.OpenFileAsync(savedPdfPath);
}
savedPdfPath = null;
}
private void CancelOpenSavedPdf()
{
savedPdfPath = null;
}
#endregion
#region Helpers
private void SetOperationMessage(string message, bool success)
{
operationMessage = message;
operationMessageClass = success ? "alert-success" : "alert-danger";
}
private static string FormatCurrency(decimal amount)
{
return amount.ToString("N2", CultureInfo.GetCultureInfo("de-DE")) + " €";
}
#endregion
}
-19
View File
@@ -29,22 +29,3 @@
</div>
</div>
@code {
private string clubName = string.Empty;
private bool saving;
private bool saved;
protected override async Task OnInitializedAsync()
{
clubName = await SettingsService.GetClubNameAsync() ?? string.Empty;
}
private async Task Save()
{
saving = true;
saved = false;
await SettingsService.SetClubNameAsync(clubName);
saved = true;
saving = false;
}
}
@@ -0,0 +1,34 @@
namespace Duempelkas.App.Pages;
public partial class Settings
{
#region Fields
private string clubName = string.Empty;
private bool saving;
private bool saved;
#endregion
#region Lifecycle
protected override async Task OnInitializedAsync()
{
clubName = await SettingsService.GetClubNameAsync() ?? string.Empty;
}
#endregion
#region Actions
private async Task Save()
{
saving = true;
saved = false;
await SettingsService.SetClubNameAsync(clubName);
saved = true;
saving = false;
}
#endregion
}