refactor(app): split dashboard settings and layout into partial classes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
@inherits LayoutComponentBase
|
||||
@using System.Reflection
|
||||
|
||||
<div class="d-flex flex-column vh-100">
|
||||
<nav class="app-navbar d-flex justify-content-between align-items-center">
|
||||
@@ -33,28 +32,3 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
@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<AssemblyInformationalVersionAttribute>()?
|
||||
.InformationalVersion;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(infoVersion))
|
||||
{
|
||||
return infoVersion.Split('+')[0];
|
||||
}
|
||||
|
||||
return entryAssembly?.GetName().Version?.ToString(2) ?? "1.0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
src/Duempelkas.App/Components/Layout/MainLayout.razor.cs
Normal file
42
src/Duempelkas.App/Components/Layout/MainLayout.razor.cs
Normal file
@@ -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<AssemblyInformationalVersionAttribute>()?
|
||||
.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
|
||||
}
|
||||
@@ -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
src/Duempelkas.App/Pages/Dashboard.razor.cs
Normal file
142
src/Duempelkas.App/Pages/Dashboard.razor.cs
Normal 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
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
34
src/Duempelkas.App/Pages/Settings.razor.cs
Normal file
34
src/Duempelkas.App/Pages/Settings.razor.cs
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user