diff --git a/src/Duempelkas.App/Components/Layout/MainLayout.razor b/src/Duempelkas.App/Components/Layout/MainLayout.razor index c67155a..82d26b2 100644 --- a/src/Duempelkas.App/Components/Layout/MainLayout.razor +++ b/src/Duempelkas.App/Components/Layout/MainLayout.razor @@ -1,5 +1,4 @@ @inherits LayoutComponentBase -@using System.Reflection
} -@code { - private bool showAboutDialog; - - private void OpenAboutDialog() => showAboutDialog = true; - - private void CloseAboutDialog() => showAboutDialog = false; - - private static string AppVersion - { - get - { - var entryAssembly = Assembly.GetEntryAssembly(); - var infoVersion = entryAssembly? - .GetCustomAttribute()? - .InformationalVersion; - - if (!string.IsNullOrWhiteSpace(infoVersion)) - { - return infoVersion.Split('+')[0]; - } - - return entryAssembly?.GetName().Version?.ToString(2) ?? "1.0"; - } - } -} diff --git a/src/Duempelkas.App/Components/Layout/MainLayout.razor.cs b/src/Duempelkas.App/Components/Layout/MainLayout.razor.cs new file mode 100644 index 0000000..9d909bd --- /dev/null +++ b/src/Duempelkas.App/Components/Layout/MainLayout.razor.cs @@ -0,0 +1,42 @@ +using System.Reflection; + +namespace Duempelkas.App.Components.Layout; + +public partial class MainLayout +{ + #region Fields + + private bool showAboutDialog; + + #endregion + + #region Properties + + private static string AppVersion + { + get + { + var entryAssembly = Assembly.GetEntryAssembly(); + var infoVersion = entryAssembly? + .GetCustomAttribute()? + .InformationalVersion; + + if (!string.IsNullOrWhiteSpace(infoVersion)) + { + return infoVersion.Split('+')[0]; + } + + return entryAssembly?.GetName().Version?.ToString(2) ?? "1.0"; + } + } + + #endregion + + #region Event Handlers + + private void OpenAboutDialog() => showAboutDialog = true; + + private void CloseAboutDialog() => showAboutDialog = false; + + #endregion +} diff --git a/src/Duempelkas.App/Pages/Dashboard.razor b/src/Duempelkas.App/Pages/Dashboard.razor index 498b1be..37f2b26 100644 --- a/src/Duempelkas.App/Pages/Dashboard.razor +++ b/src/Duempelkas.App/Pages/Dashboard.razor @@ -5,7 +5,6 @@ @inject IPdfStatementService PdfStatementService @inject IFileSaveService FileSaveService @inject NavigationManager NavigationManager -@using System.Globalization
@@ -108,112 +107,3 @@ OnCancel="CancelRestoreConfirm" /> } -@code { - private List? 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")) + " €"; - } -} diff --git a/src/Duempelkas.App/Pages/Dashboard.razor.cs b/src/Duempelkas.App/Pages/Dashboard.razor.cs new file mode 100644 index 0000000..2dbddc3 --- /dev/null +++ b/src/Duempelkas.App/Pages/Dashboard.razor.cs @@ -0,0 +1,142 @@ +using System.Globalization; +using Duempelkas.App.Services.Models; + +namespace Duempelkas.App.Pages; + +public partial class Dashboard +{ + #region Fields + + private List? 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 +} diff --git a/src/Duempelkas.App/Pages/Settings.razor b/src/Duempelkas.App/Pages/Settings.razor index 243e76b..b351ca2 100644 --- a/src/Duempelkas.App/Pages/Settings.razor +++ b/src/Duempelkas.App/Pages/Settings.razor @@ -29,22 +29,3 @@
-@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; - } -} diff --git a/src/Duempelkas.App/Pages/Settings.razor.cs b/src/Duempelkas.App/Pages/Settings.razor.cs new file mode 100644 index 0000000..0d970b3 --- /dev/null +++ b/src/Duempelkas.App/Pages/Settings.razor.cs @@ -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 +}