From e71a64160ca83a78f4cb14358cefe7bc43bf85e5 Mon Sep 17 00:00:00 2001 From: Joao Rua Date: Fri, 26 Jul 2024 17:24:22 +0100 Subject: [PATCH] error handling for domain file store upload --- .../Components/Common/FormButtons.razor.css | 10 ---------- .../EngineeringModel/FileStore/FileForm.razor | 16 +++++++++++++++- .../FileStore/FileForm.razor.cs | 17 +++++++++++++++-- .../FileHandler/FileHandlerViewModel.cs | 19 +++++++++++++++---- .../FileHandler/IFileHandlerViewModel.cs | 6 ++++-- COMETwebapp/wwwroot/css/app.css | 13 ++++++++++++- 6 files changed, 61 insertions(+), 20 deletions(-) delete mode 100644 COMETwebapp/Components/Common/FormButtons.razor.css diff --git a/COMETwebapp/Components/Common/FormButtons.razor.css b/COMETwebapp/Components/Common/FormButtons.razor.css deleted file mode 100644 index 01159ef6..00000000 --- a/COMETwebapp/Components/Common/FormButtons.razor.css +++ /dev/null @@ -1,10 +0,0 @@ -.validation-container { - border: dashed 1px red; - padding-top: 1rem; - padding-right: 1rem; - border-radius: 10px; -} - -.validation-container:not(:has(li)) { - display: none; -} \ No newline at end of file diff --git a/COMETwebapp/Components/EngineeringModel/FileStore/FileForm.razor b/COMETwebapp/Components/EngineeringModel/FileStore/FileForm.razor index c6f45809..633295bc 100644 --- a/COMETwebapp/Components/EngineeringModel/FileStore/FileForm.razor +++ b/COMETwebapp/Components/EngineeringModel/FileStore/FileForm.razor @@ -54,7 +54,21 @@ Copyright (c) 2023-2024 Starion Group S.A.
- + +
+
    + + @if (!this.ViewModel.SelectedFileRevisions.Any()) + { +
  • At least one file revision should exist
  • + } + @if (!string.IsNullOrWhiteSpace(this.ErrorMessage)) + { +
  • @(this.ErrorMessage)
  • + } +
+
+
/// Support class for the /// @@ -47,14 +49,25 @@ public partial class FileForm : SelectedDataItemForm /// public bool IsDeletePopupVisible { get; private set; } + /// + /// Gets the error message from the , if any + /// + public string ErrorMessage { get; private set; } = string.Empty; + /// /// Method that is executed when there is a valid submit /// /// A protected override async Task OnValidSubmit() { - await this.ViewModel.CreateOrEditFile(this.ShouldCreate); - await base.OnValidSubmit(); + this.ErrorMessage = string.Empty; + var result = await this.ViewModel.CreateOrEditFile(this.ShouldCreate); + this.ErrorMessage = string.Join(", ", result.Reasons.OfType().Select(x => x.Exception.Message)); + + if (string.IsNullOrWhiteSpace(this.ErrorMessage)) + { + await base.OnValidSubmit(); + } } /// diff --git a/COMETwebapp/ViewModels/Components/EngineeringModel/FileStore/FileHandler/FileHandlerViewModel.cs b/COMETwebapp/ViewModels/Components/EngineeringModel/FileStore/FileHandler/FileHandlerViewModel.cs index 655baa4e..db85d132 100644 --- a/COMETwebapp/ViewModels/Components/EngineeringModel/FileStore/FileHandler/FileHandlerViewModel.cs +++ b/COMETwebapp/ViewModels/Components/EngineeringModel/FileStore/FileHandler/FileHandlerViewModel.cs @@ -36,6 +36,8 @@ namespace COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileHandl using COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileRevisionHandler; + using FluentResults; + using Microsoft.AspNetCore.Components; /// @@ -149,8 +151,8 @@ public async Task MoveFile(File file, Folder targetFolder) /// Creates or edits a file /// /// The condition to check if the file should be created - /// A - public async Task CreateOrEditFile(bool shouldCreate) + /// A containing a + public async Task CreateOrEditFile(bool shouldCreate) { this.IsLoading = true; this.logger.LogInformation("Creating or editing file"); @@ -193,11 +195,20 @@ public async Task CreateOrEditFile(bool shouldCreate) } thingsToUpdate.Add(this.CurrentThing); + var result = await this.SessionService.CreateOrUpdateThings(fileStoreClone, thingsToUpdate, newFileRevisions.Select(x => x.LocalPath).ToList()); - await this.SessionService.CreateOrUpdateThings(fileStoreClone, thingsToUpdate, newFileRevisions.Select(x => x.LocalPath).ToList()); + if (result.IsSuccess) + { + this.logger.LogInformation("File with iid {iid} updated successfully", this.CurrentThing.Iid); + } + else + { + this.logger.LogWarning("File could not be created. {warning}", string.Join(", ", string.Join(", ", result.Reasons.Select(x => x.Message)))); + } - this.logger.LogInformation("File with iid {iid} updated successfully", this.CurrentThing.Iid); this.IsLoading = false; + + return result; } /// diff --git a/COMETwebapp/ViewModels/Components/EngineeringModel/FileStore/FileHandler/IFileHandlerViewModel.cs b/COMETwebapp/ViewModels/Components/EngineeringModel/FileStore/FileHandler/IFileHandlerViewModel.cs index aef92ea7..dd1eb662 100644 --- a/COMETwebapp/ViewModels/Components/EngineeringModel/FileStore/FileHandler/IFileHandlerViewModel.cs +++ b/COMETwebapp/ViewModels/Components/EngineeringModel/FileStore/FileHandler/IFileHandlerViewModel.cs @@ -32,6 +32,8 @@ namespace COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileHandl using COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileRevisionHandler; + using FluentResults; + /// /// View model used to manage the files in Filestores /// @@ -96,8 +98,8 @@ public interface IFileHandlerViewModel : IApplicationBaseViewModel /// Creates a file into a target folder /// /// - /// A - Task CreateOrEditFile(bool shouldCreate); + /// A containing a + Task CreateOrEditFile(bool shouldCreate); /// /// Deletes the current file diff --git a/COMETwebapp/wwwroot/css/app.css b/COMETwebapp/wwwroot/css/app.css index dd2b31a0..5fbf33b6 100644 --- a/COMETwebapp/wwwroot/css/app.css +++ b/COMETwebapp/wwwroot/css/app.css @@ -290,4 +290,15 @@ sub { .model-editor-details { flex: 1 1 40% !important; -} \ No newline at end of file +} + +.validation-container { + border: dashed 1px red; + padding-top: 1rem; + padding-right: 1rem; + border-radius: 10px; +} + + .validation-container:not(:has(li)) { + display: none; + } \ No newline at end of file