Skip to content

Commit

Permalink
Model and UI changes for audiofile for splitpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Apr 3, 2024
1 parent ac628a5 commit b508b96
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 5 deletions.
1 change: 1 addition & 0 deletions AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public IReadOnlyCollection<Exportfile> 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))
{
Expand Down
23 changes: 22 additions & 1 deletion AudioCuesheetEditor/Model/IO/Export/SplitPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ namespace AudioCuesheetEditor.Model.IO.Export
{
public class SplitPoint : Validateable<SplitPoint>, 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<TraceablePropertiesChangedEventArgs>? TraceablePropertyChanged;

Expand All @@ -35,6 +35,7 @@ public SplitPoint(Cuesheet cuesheet)
Cuesheet = cuesheet;
artist = Cuesheet.Artist;
title = Cuesheet.Title;
audiofileName = Cuesheet.Audiofile?.Name;
}

[JsonConstructor]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
73 changes: 73 additions & 0 deletions AudioCuesheetEditor/Pages/EditSplitpoints.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ along with Foobar. If not, see
@inject DateTimeUtility _dateTimeUtility
@inject ITextLocalizerService _localizationService
@inject TraceChangeManager _traceChangeManager
@inject IJSRuntime _jsRuntime

<Validations @ref="validations">
@if (Cuesheet != null)
Expand Down Expand Up @@ -51,6 +52,7 @@ along with Foobar. If not, see
<TableHeaderCell>@_localizer["Moment"]</TableHeaderCell>
<TableHeaderCell>@_localizer["CD artist"]</TableHeaderCell>
<TableHeaderCell>@_localizer["CD title"]</TableHeaderCell>
<TableHeaderCell>@_localizer["Audiofile name"]</TableHeaderCell>
</TableRow>
</TableHeader>
<TableBody>
Expand Down Expand Up @@ -99,15 +101,47 @@ along with Foobar. If not, see
</TextEdit>
</Validation>
</TableRowCell>
<TableRowCell>
<Validation @ref="audiofileValidation" AsyncValidator="(args, token) => ValidatorUtility<SplitPoint>.Validate(args, splitPoint, x => x.AudiofileName, _validationMessageLocalizer, token)">
@if (String.IsNullOrEmpty(splitPoint.AudiofileName))
{
<FileEdit id="@fileEditAudiofileIds[splitPoint]" Filter="@String.Join(",", Audiofile.AudioCodecs.Select(x => x.MimeType))" Changed="(args) => OnSplitpointAudiofileChanged(args, splitPoint)" AutoReset="false">
<Feedback>
<ValidationError />
</Feedback>
</FileEdit>
}
else
{
<Addons>
<Addon AddonType="AddonType.Body">
<TextEdit ReadOnly Text="@splitPoint.AudiofileName">
<Feedback>
<ValidationError Tooltip />
</Feedback>
</TextEdit>
</Addon>
<Addon AddonType="AddonType.End">
<Button Color="Color.Secondary" Outline Clicked="(args) => OnSplitpointAudiofileChangedCliccked(splitPoint)">@_localizer["Change"]</Button>
</Addon>
</Addons>
}
</Validation>
</TableRowCell>
</TableRow>
}
</TableBody>
</Table>
}
</Validations>

<ModalDialog @ref="modalDialog" />

@code {
Validations? validations;
ModalDialog? modalDialog;
Validation? audiofileValidation;
Dictionary<SplitPoint, Guid> fileEditAudiofileIds = new();

public Cuesheet? Cuesheet
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"Artist": "Künstler",
"Title": "Titel",
"Exportprofile": "Exportprofil",
"ApplicationOptions": "Applikationsoptionen"
"ApplicationOptions": "Applikationsoptionen",
"AudiofileName": "Audiodatei"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"Artist": "Artist",
"Title": "Title",
"Exportprofile": "Exportprofile",
"ApplicationOptions": "Application options"
"ApplicationOptions": "Application options",
"AudiofileName": "Audiofile"
}
}

0 comments on commit b508b96

Please sign in to comment.