From b508b96d8386a44b14ada54b64a379f8fbec9ee1 Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Wed, 3 Apr 2024 09:21:36 +0200 Subject: [PATCH] Model and UI changes for audiofile for splitpoints --- .../Model/IO/Export/ExportfileGenerator.cs | 1 + .../Model/IO/Export/SplitPoint.cs | 23 +++++- .../Pages/EditSplitpoints.razor | 73 +++++++++++++++++++ .../Localization/EditSplitpoints/de.json | 7 +- .../Localization/EditSplitpoints/en.json | 7 +- .../Localization/ValidationMessage/de.json | 3 +- .../Localization/ValidationMessage/en.json | 3 +- 7 files changed, 112 insertions(+), 5 deletions(-) diff --git a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs index 50f4d964..12cef661 100644 --- a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs +++ b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs @@ -57,6 +57,7 @@ public IReadOnlyCollection GenerateExportfiles() var counter = 1; String? content = null; String filename = String.Empty; + //TODO String audioFileName = String.Empty; foreach (var splitPoint in Cuesheet.SplitPoints.OrderBy(x => x.Moment)) { diff --git a/AudioCuesheetEditor/Model/IO/Export/SplitPoint.cs b/AudioCuesheetEditor/Model/IO/Export/SplitPoint.cs index 15a332e4..78e782c7 100644 --- a/AudioCuesheetEditor/Model/IO/Export/SplitPoint.cs +++ b/AudioCuesheetEditor/Model/IO/Export/SplitPoint.cs @@ -22,11 +22,11 @@ namespace AudioCuesheetEditor.Model.IO.Export { public class SplitPoint : Validateable, ITraceable { - //TODO: Add audio file name as property to be set by user private Cuesheet? cuesheet; private TimeSpan? moment; private String? artist; private String? title; + private String? audiofileName; public event EventHandler? TraceablePropertyChanged; @@ -35,6 +35,7 @@ public SplitPoint(Cuesheet cuesheet) Cuesheet = cuesheet; artist = Cuesheet.Artist; title = Cuesheet.Title; + audiofileName = Cuesheet.Audiofile?.Name; } [JsonConstructor] @@ -91,6 +92,18 @@ public TimeSpan? Moment } } + public String? AudiofileName + { + get => audiofileName; + set + { + var previousValue = audiofileName; + audiofileName = value; + OnValidateablePropertyChanged(nameof(AudiofileName)); + OnTraceablePropertyChanged(previousValue, nameof(AudiofileName)); + } + } + public void CopyValues(SplitPoint splitPoint) { Artist = splitPoint.Artist; @@ -137,6 +150,14 @@ protected override ValidationResult Validate(string property) validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Title))); } break; + case nameof(AudiofileName): + validationStatus = ValidationStatus.Success; + if (String.IsNullOrEmpty(AudiofileName)) + { + validationMessages ??= new(); + validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(AudiofileName))); + } + break; } return ValidationResult.Create(validationStatus, validationMessages); } diff --git a/AudioCuesheetEditor/Pages/EditSplitpoints.razor b/AudioCuesheetEditor/Pages/EditSplitpoints.razor index c81913fa..c551484b 100644 --- a/AudioCuesheetEditor/Pages/EditSplitpoints.razor +++ b/AudioCuesheetEditor/Pages/EditSplitpoints.razor @@ -23,6 +23,7 @@ along with Foobar. If not, see @inject DateTimeUtility _dateTimeUtility @inject ITextLocalizerService _localizationService @inject TraceChangeManager _traceChangeManager +@inject IJSRuntime _jsRuntime @if (Cuesheet != null) @@ -51,6 +52,7 @@ along with Foobar. If not, see @_localizer["Moment"] @_localizer["CD artist"] @_localizer["CD title"] + @_localizer["Audiofile name"] @@ -99,6 +101,33 @@ along with Foobar. If not, see + + + @if (String.IsNullOrEmpty(splitPoint.AudiofileName)) + { + x.MimeType))" Changed="(args) => OnSplitpointAudiofileChanged(args, splitPoint)" AutoReset="false"> + + + + + } + else + { + + + + + + + + + + + + + } + + } @@ -106,8 +135,13 @@ along with Foobar. If not, see } + + @code { Validations? validations; + ModalDialog? modalDialog; + Validation? audiofileValidation; + Dictionary fileEditAudiofileIds = new(); public Cuesheet? Cuesheet { @@ -172,6 +206,7 @@ along with Foobar. If not, see { var splitPoint = Cuesheet.AddSplitPoint(); _traceChangeManager.TraceChanges(splitPoint); + fileEditAudiofileIds.Add(splitPoint, Guid.NewGuid()); } return Task.CompletedTask; } @@ -229,4 +264,42 @@ along with Foobar. If not, see { StateHasChanged(); } + + async Task OnSplitpointAudiofileChangedCliccked(SplitPoint splitPoint) + { + splitPoint.AudiofileName = null; + StateHasChanged(); + await Task.Delay(1); + await _jsRuntime.InvokeVoidAsync("triggerClick", fileEditAudiofileIds[splitPoint]); + } + + async Task OnSplitpointAudiofileChanged(FileChangedEventArgs e, SplitPoint splitPoint) + { + if (e.Files.FirstOrDefault() != null) + { + if (Cuesheet != null) + { + var file = e.Files.First(); + if (IOUtility.CheckFileMimeTypeForAudioCodec(file) == true) + { + splitPoint.AudiofileName = file.Name; + } + else + { + if (modalDialog != null) + { + modalDialog.Title = _localizer["Error"]; + modalDialog.Text = String.Format(_localizer["The file {0} can not be used for operation: {1}. The file is invalid, please use a valid file!"], file.Name, _localizer["Audiofile"]); + modalDialog.ModalSize = ModalSize.Small; + modalDialog.Mode = ModalDialog.DialogMode.Alert; + await modalDialog.ShowModal(); + } + } + } + } + if (audiofileValidation != null) + { + await audiofileValidation.ValidateAsync(); + } + } } diff --git a/AudioCuesheetEditor/Resources/Localization/EditSplitpoints/de.json b/AudioCuesheetEditor/Resources/Localization/EditSplitpoints/de.json index 7a92f7c6..1ade6c3a 100644 --- a/AudioCuesheetEditor/Resources/Localization/EditSplitpoints/de.json +++ b/AudioCuesheetEditor/Resources/Localization/EditSplitpoints/de.json @@ -6,6 +6,11 @@ "Moment": "Zeitpunkt", "Delete split tooltip": "Löscht diesen Aufteilungspunkt", "CD artist": "CD Künstler", - "CD title": "CD Titel" + "CD title": "CD Titel", + "Audiofile name": "Audiodatei", + "Error": "Fehler", + "The file {0} can not be used for operation: {1}. The file is invalid, please use a valid file!": "Die Datei {0} kann nicht für folgende Operation genutzt werden: {1}. Die Datei ist ungültig, bitte verwenden Sie eine gültige Datei!", + "Audiofile": "Audiofile", + "Change": "Ändern" } } \ No newline at end of file diff --git a/AudioCuesheetEditor/Resources/Localization/EditSplitpoints/en.json b/AudioCuesheetEditor/Resources/Localization/EditSplitpoints/en.json index 1642de6b..7256528d 100644 --- a/AudioCuesheetEditor/Resources/Localization/EditSplitpoints/en.json +++ b/AudioCuesheetEditor/Resources/Localization/EditSplitpoints/en.json @@ -6,6 +6,11 @@ "Moment": "Moment", "Delete split tooltip": "Deletes this split point", "CD artist": "CD artist", - "CD title": "CD title" + "CD title": "CD title", + "Audiofile name": "Audiofile", + "Error": "Error", + "The file {0} can not be used for operation: {1}. The file is invalid, please use a valid file!": "The file {0} can not be used for operation: {1}. The file is invalid, please use a valid file!", + "Audiofile": "Audiofile", + "Change": "Change" } } \ No newline at end of file diff --git a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json index c4a91e06..afdb290e 100644 --- a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json +++ b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json @@ -39,6 +39,7 @@ "Artist": "Künstler", "Title": "Titel", "Exportprofile": "Exportprofil", - "ApplicationOptions": "Applikationsoptionen" + "ApplicationOptions": "Applikationsoptionen", + "AudiofileName": "Audiodatei" } } \ No newline at end of file diff --git a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json index d08f0bd6..309d5fe4 100644 --- a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json +++ b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json @@ -39,6 +39,7 @@ "Artist": "Artist", "Title": "Title", "Exportprofile": "Exportprofile", - "ApplicationOptions": "Application options" + "ApplicationOptions": "Application options", + "AudiofileName": "Audiofile" } } \ No newline at end of file