From 32516c33c2720fa09f4eca44935ae66fa1a6011c Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Tue, 2 Apr 2024 12:01:17 +0200
Subject: [PATCH] Display validation errors to user
---
AudioCuesheetEditor/Shared/MainLayout.razor | 52 +++++++++++--------
.../Shared/ModalExportdialog.razor | 32 ++++++++++--
2 files changed, 58 insertions(+), 26 deletions(-)
diff --git a/AudioCuesheetEditor/Shared/MainLayout.razor b/AudioCuesheetEditor/Shared/MainLayout.razor
index f5d077ef..276999b9 100644
--- a/AudioCuesheetEditor/Shared/MainLayout.razor
+++ b/AudioCuesheetEditor/Shared/MainLayout.razor
@@ -98,7 +98,7 @@ along with Foobar. If not, see
-
+
@@ -421,39 +421,49 @@ along with Foobar. If not, see
{
get
{
- String? text = null;
- if (IsCuesheetExportable == false)
+ var generator = new ExportfileGenerator(ExportType.Cuesheet, _sessionStateContainer.Cuesheet, applicationOptions: applicationOptions, audioConverterService: _audioConverterService);
+ var validationResult = generator.Validate();
+ if (validationResult.Status == Model.Entity.ValidationStatus.Error)
{
- text = _localizer["Please check processinghints for errors, otherwise the file is not exportable"];
+ string? detailText = null;
+ if (validationResult.ValidationMessages != null)
+ {
+ foreach (var validationMessage in validationResult.ValidationMessages)
+ {
+ detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine);
+ }
+ }
+ return _localizer["Please check processinghints for errors, otherwise the file is not exportable: {0}", detailText];
}
- return text;
+ return null;
}
}
- Boolean IsCuesheetExportable
+ Boolean IsCuesheetExportable => IsCuesheetExportableTooltip == null;
+
+ string? IsExportprofileExportableTooltip
{
get
{
- if (applicationOptions?.Validate(x => x.CuesheetFilename).Status != Model.Entity.ValidationStatus.Error)
- {
- var generator = new ExportfileGenerator(_sessionStateContainer.Cuesheet, applicationOptions: applicationOptions, audioConverterService: _audioConverterService);
- return generator.CanWrite(ExportType.Cuesheet);
- }
- else
+ var generator = new ExportfileGenerator(ExportType.Exportprofile, _sessionStateContainer.Cuesheet, SelectedExportProfile, audioConverterService: _audioConverterService);
+ var validationResult = generator.Validate();
+ if (validationResult.Status == Model.Entity.ValidationStatus.Error)
{
- return false;
+ string? detailText = null;
+ if (validationResult.ValidationMessages != null)
+ {
+ foreach (var validationMessage in validationResult.ValidationMessages)
+ {
+ detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine);
+ }
+ }
+ return _localizer["Please check processinghints for errors, otherwise the file is not exportable: {0}", detailText];
}
+ return null;
}
}
- Boolean IsExportprofileExportable
- {
- get
- {
- var generator = new ExportfileGenerator(_sessionStateContainer.Cuesheet, SelectedExportProfile, audioConverterService: _audioConverterService);
- return generator.CanWrite(ExportType.Exportprofile);
- }
- }
+ Boolean IsExportprofileExportable => IsExportprofileExportableTooltip == null;
Boolean ModalExportdialogCuesheetLockUserInput
{
diff --git a/AudioCuesheetEditor/Shared/ModalExportdialog.razor b/AudioCuesheetEditor/Shared/ModalExportdialog.razor
index 2de42131..f8f9b7c3 100644
--- a/AudioCuesheetEditor/Shared/ModalExportdialog.razor
+++ b/AudioCuesheetEditor/Shared/ModalExportdialog.razor
@@ -113,7 +113,7 @@ along with Foobar. If not, see
{
@if (selectedStep != "displayExportResult")
{
-
+
@@ -175,6 +175,27 @@ along with Foobar. If not, see
}
}
+ String? ExportPossibleTooltip
+ {
+ get
+ {
+ var validationResult = ExportfileGenerator?.Validate();
+ if (validationResult?.Status == Model.Entity.ValidationStatus.Error)
+ {
+ string? detailText = null;
+ if (validationResult.ValidationMessages != null)
+ {
+ foreach (var validationMessage in validationResult.ValidationMessages)
+ {
+ detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine);
+ }
+ }
+ return _localizer["Export files can not be generated. Please check validationerrors and solve errors in order to download export: {0}", detailText];
+ }
+ return null;
+ }
+ }
+
Boolean ExportPossible
{
get
@@ -184,9 +205,10 @@ along with Foobar. If not, see
{
exportPossible = Validations.ValidateAll().GetAwaiter().GetResult();
}
- if ((exportPossible == false) && (ExportfileGenerator != null))
+ //TODO: Warum nur bei exportPossible == false?
+ if (exportPossible == false)
{
- exportPossible = ExportfileGenerator.CanWrite(ExportType);
+ exportPossible = ExportPossibleTooltip == null;
}
return exportPossible;
}
@@ -198,7 +220,7 @@ along with Foobar. If not, see
.Add(Key.Enter, OnEnterKeyDown);
_audioConverterService.ProgressChanged += IAudioConverterService_ProgressChanged;
- ExportfileGenerator = new ExportfileGenerator(_sessionStateContainer.Cuesheet, audioConverterService: _audioConverterService);
+ ExportfileGenerator = new ExportfileGenerator(ExportType, _sessionStateContainer.Cuesheet, audioConverterService: _audioConverterService);
await base.OnInitializedAsync();
}
@@ -244,7 +266,7 @@ along with Foobar. If not, see
exportProgress = 0;
if (ExportfileGenerator != null)
{
- exportfiles = await ExportfileGenerator.GenerateExportfilesAsync(ExportType);
+ exportfiles = await ExportfileGenerator.GenerateExportfilesAsync();
selectedStep = "displayExportResult";
prepareExportCompleted = true;
}