diff --git a/Accounting.sln.DotSettings.user b/Accounting.sln.DotSettings.user deleted file mode 100644 index 96dd07f..0000000 --- a/Accounting.sln.DotSettings.user +++ /dev/null @@ -1,5 +0,0 @@ - - ForceIncluded - ForceIncluded - ForceIncluded - ForceIncluded \ No newline at end of file diff --git a/Schaad.Accounting.Common/Datasets/MessageDataset.cs b/Schaad.Accounting.Common/Datasets/MessageDataset.cs index 105b143..cc18624 100644 --- a/Schaad.Accounting.Common/Datasets/MessageDataset.cs +++ b/Schaad.Accounting.Common/Datasets/MessageDataset.cs @@ -25,18 +25,6 @@ namespace Schaad.Accounting.Datasets Status = status; } } - - public string GetCssAlertClass() - { - switch (Status) - { - case MessageStatus.Success: return "alert-success"; - case MessageStatus.Info: return "alert-info"; - case MessageStatus.Warning: return "alert-warning"; - case MessageStatus.Error: return "alert-danger"; - default: return "alert-success"; - } - } } public enum MessageStatus diff --git a/Schaad.Accounting.UI/Components/Layout/MainLayout.razor b/Schaad.Accounting.UI/Components/Layout/MainLayout.razor index b9a19cb..c660f23 100644 --- a/Schaad.Accounting.UI/Components/Layout/MainLayout.razor +++ b/Schaad.Accounting.UI/Components/Layout/MainLayout.razor @@ -7,6 +7,7 @@ +
@Body
@@ -21,6 +22,7 @@ +
An unhandled error has occurred. diff --git a/Schaad.Accounting.UI/Components/MyHeader.razor b/Schaad.Accounting.UI/Components/MyHeader.razor index d41f2e6..6ea08f6 100644 --- a/Schaad.Accounting.UI/Components/MyHeader.razor +++ b/Schaad.Accounting.UI/Components/MyHeader.razor @@ -16,8 +16,4 @@ AccountingNext OptionValue="@(i => i.ToString())" @bind-SelectedOption="@selectedMandator" ValueChanged="MandatorChanged"/> - - -@code { - -} \ No newline at end of file + \ No newline at end of file diff --git a/Schaad.Accounting.UI/Components/MyHeader.razor.cs b/Schaad.Accounting.UI/Components/MyHeader.razor.cs index 8dee923..5a81078 100644 --- a/Schaad.Accounting.UI/Components/MyHeader.razor.cs +++ b/Schaad.Accounting.UI/Components/MyHeader.razor.cs @@ -8,6 +8,9 @@ public partial class MyHeader : ComponentBase [Inject] private ISettingsService settingsService { get; set; } = null!; + [Inject] + NavigationManager navigationManager { get; set; } = null!; + private List years = new (); private int selectedYear; @@ -32,12 +35,20 @@ public partial class MyHeader : ComponentBase public void YearChanged(string syear) { var year = int.Parse(syear); - settingsService.SetYear(year); - mandators = settingsService.GetMandators(year).ToList(); + if (selectedYear != year) + { + settingsService.SetYear(year); + mandators = settingsService.GetMandators(year).ToList(); + navigationManager.NavigateTo(navigationManager.Uri, forceLoad: true); + } } public void MandatorChanged(string mandator) { - settingsService.SetMandator(mandator); + if (selectedMandator != mandator) + { + settingsService.SetMandator(mandator); + navigationManager.NavigateTo(navigationManager.Uri, forceLoad: true); + } } } \ No newline at end of file diff --git a/Schaad.Accounting.UI/Components/Pages/BankTransactions.razor b/Schaad.Accounting.UI/Components/Pages/BankTransactions.razor index 42be214..e72827e 100644 --- a/Schaad.Accounting.UI/Components/Pages/BankTransactions.razor +++ b/Schaad.Accounting.UI/Components/Pages/BankTransactions.razor @@ -4,16 +4,14 @@
- - - - + + + - +
@code { - DataGridRowSize rowSize = DataGridRowSize.Small; PaginationState pagination = new PaginationState() { ItemsPerPage = 10 }; } \ No newline at end of file diff --git a/Schaad.Accounting.UI/Components/Pages/Home.razor b/Schaad.Accounting.UI/Components/Pages/Home.razor index 440a622..427e282 100644 --- a/Schaad.Accounting.UI/Components/Pages/Home.razor +++ b/Schaad.Accounting.UI/Components/Pages/Home.razor @@ -1,7 +1,44 @@ @page "/" -

Home

+@rendermode InteractiveServer -@foreach (var bankTransaction in bankTransactions) -{ -

@bankTransaction.BankAccountNumber

-} \ No newline at end of file +Home + + + + + + @progressTitle + + + + Upload files + + + + Cancel + + +
+ + + + + + + + + + +
Keine Daten vorhanden!
+
+
+
+
\ No newline at end of file diff --git a/Schaad.Accounting.UI/Components/Pages/Home.razor.cs b/Schaad.Accounting.UI/Components/Pages/Home.razor.cs index 42461f7..77a9564 100644 --- a/Schaad.Accounting.UI/Components/Pages/Home.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Home.razor.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNetCore.Components; +using System.IO.Compression; +using Microsoft.AspNetCore.Components; +using Microsoft.FluentUI.AspNetCore.Components; +using Schaad.Accounting.Datasets; using Schaad.Accounting.Interfaces; using Schaad.Accounting.Models; @@ -8,12 +11,127 @@ public partial class Home : ComponentBase { [Inject] private IViewService viewService { get; set; } = null!; - - private List bankTransactions = null!; - protected override Task OnInitializedAsync() - { - bankTransactions = viewService.GetOpenBankTransactionList(); + [Inject] + private IToastService toastService { get; set; } = null!; + + [Inject] + private IMessageService messageService { get; set; } = null!; + + [Inject] + private ISettingsService settingsService { get; set; } = null!; + + [Inject] + private IFileService fileService { get; set; } = null!; + + private IQueryable? bankTransactionsQueryable; + + FluentInputFile? myFileByBuffer; + int? progressPercent; + string? progressTitle; + bool IsCanceled; + Dictionary Files = new(); + + protected override Task OnInitializedAsync() + { + bankTransactionsQueryable = viewService.GetOpenBankTransactionList().AsQueryable(); return base.OnInitializedAsync(); - } + } + + async Task OnProgressChangeAsync(FluentInputFileEventArgs file) + { + progressPercent = file.ProgressPercent; + progressTitle = file.ProgressTitle; + + // To cancel? + file.IsCancelled = IsCanceled; + + // New file + if (!Files.ContainsKey(file.Index)) + { + var localFile = Path.GetTempFileName() + file.Name; + Files.Add(file.Index, localFile); + } + + // Write to the FileStream + await file.Buffer.AppendToFileAsync(Files[file.Index]); + } + + private async Task OnCompletedAsync(IEnumerable files) + { + progressPercent = myFileByBuffer!.ProgressPercent; + progressTitle = myFileByBuffer!.ProgressTitle; + + foreach (var file in Files) + { + var extension = Path.GetExtension(file.Value); + if (extension is ".xml") + { + await ImportXmlAndShowResultAsync(file.Value); + } + else if (extension is ".zip") + { + var unzippedFiles = UnzipAndListFiles(file.Value); + foreach (var unzippedFile in unzippedFiles) + { + await ImportXmlAndShowResultAsync(unzippedFile); + File.Delete(unzippedFile); + } + } + + File.Delete(file.Value); + } + + bankTransactionsQueryable = viewService.GetOpenBankTransactionList().AsQueryable(); + } + + private async Task ImportXmlAndShowResultAsync(string fileName) + { + var messages = fileService.ImportAccountStatementFile(fileName); + foreach (var message in messages) + { + await ShowImportResultAsync(message); + } + } + + private IReadOnlyList UnzipAndListFiles(string zipFilePath) + { + var tempExtractPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())); + Directory.CreateDirectory(tempExtractPath); + ZipFile.ExtractToDirectory(zipFilePath, tempExtractPath); + return new List(Directory.GetFiles(tempExtractPath, "*", SearchOption.AllDirectories)); + } + + private async Task ShowImportResultAsync(MessageDataset message) + { + var joinedDetails = string.Join(", ", message.Lines); + var text = $"{message.Title}: {joinedDetails}"; + + if (message.Status == MessageStatus.Success) + { + ShowToast(text, ToastIntent.Success); + } + else if (message.Status == MessageStatus.Info) + { + ShowToast(text, ToastIntent.Info); + } + else if (message.Status == MessageStatus.Warning) + { + ShowToast(text, ToastIntent.Warning); + } + else if (message.Status == MessageStatus.Error) + { + await ShowMessageAsync(text, MessageIntent.Error); + } + } + + private async Task ShowMessageAsync(string message, MessageIntent intent) + { + await messageService.ShowMessageBarAsync(message, intent, "MESSAGES_TOP"); + } + + private void ShowToast(string message, ToastIntent intent) + { + toastService.ShowToast(intent, message, 3000); + } }