-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEditTrackModal.razor
More file actions
127 lines (118 loc) · 8.41 KB
/
EditTrackModal.razor
File metadata and controls
127 lines (118 loc) · 8.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!--
This file is part of AudioCuesheetEditor.
AudioCuesheetEditor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
AudioCuesheetEditor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see
<http: //www.gnu.org/licenses />.
-->
@inherits BaseLocalizedComponent
@inject IStringLocalizer<EditTrackModal> _localizer
@inject ApplicationOptionsTimeSpanParser _applicationOptionsTimeSpanParser
@inject AutocompleteManager _autocompleteManager
@inject ValidationService _validationService
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h5">@_localizer["Edit track details"]</MudText>
</TitleContent>
<DialogContent>
<MudForm Model="EditedTrack">
<MudSwitch @bind-Value="EditedTrack.IsLinkedToPreviousTrack" Label="@_localizer["Link to previous track"]" Color="Color.Primary" Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.IsLinkedToPreviousTrack)))"
ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.IsLinkedToPreviousTrack))" />
<MudTextField @bind-Value="EditedTrack.Position" Label="@_localizer["Position"]" Variant="Variant.Outlined" Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.Position)))"
ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.Position))" />
@{
MusicBrainzArtist? autocompleteArtist = new()
{
Name = EditedTrack.Artist
};
}
<MudAutocomplete T="MusicBrainzArtist" Label="@_localizer["Artist"]" Variant="Variant.Outlined" SearchFunc="_autocompleteManager.SearchArtistsAsync" ToStringFunc="(value) => value.Name"
@bind-Text="EditedTrack.Artist" @bind-Value="autocompleteArtist" Clearable ShowProgressIndicator Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.Artist)))"
ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.Artist))" MaxItems="null" CoerceText="false">
<ItemTemplate Context="autocompleteContext">
<MudText>@autocompleteContext.Name</MudText>
@if (autocompleteContext.Disambiguation != null)
{
<MudSpacer />
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">@autocompleteContext.Disambiguation</MudText>
}
</ItemTemplate>
</MudAutocomplete>
@{
MusicBrainzTrack? autocompleteTrack = new()
{
Artist = EditedTrack.Artist,
Title = EditedTrack.Title
};
}
<MudAutocomplete T="MusicBrainzTrack" Label="@_localizer["Title"]" Variant="Variant.Outlined" SearchFunc="(value, token) => _autocompleteManager.SearchTitlesAsync(value, EditedTrack.Artist, token)" ToStringFunc="(value) => value.Title"
@bind-Text="EditedTrack.Title" Value="autocompleteTrack" ValueChanged="TitleSelected" Clearable ShowProgressIndicator
Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.Title)))" ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.Title))" MaxItems="null" CoerceText="false">
<ItemTemplate Context="autocompleteContext">
<MudText>@autocompleteContext.Title</MudText>
@if (autocompleteContext.Disambiguation != null)
{
<MudSpacer />
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">@autocompleteContext.Disambiguation</MudText>
}
</ItemTemplate>
</MudAutocomplete>
<MudTextField Label="@_localizer["Begin"]" Variant="Variant.Outlined" Value="@EditedTrack.Begin.ToString()" ValueChanged="(string value) => _applicationOptionsTimeSpanParser.TimespanTextChanged<Track, TimeSpan?>(EditedTrack, x => x.Begin, value)"
Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.Begin)))" ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.Begin))" />
<MudTextField Label="@_localizer["End"]" Variant="Variant.Outlined" Value="@EditedTrack.End.ToString()" ValueChanged="(string value) => _applicationOptionsTimeSpanParser.TimespanTextChanged<Track, TimeSpan?>(EditedTrack, x => x.End, value)"
Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.End)))" ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.End))" />
<MudTextField Label="@_localizer["Length"]" Variant="Variant.Outlined" Value="@EditedTrack.Length.ToString()" ValueChanged="(string value) => _applicationOptionsTimeSpanParser.TimespanTextChanged<Track, TimeSpan?>(EditedTrack, x => x.Length, value)"
Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.Length)))" ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.Length))" />
<MudField Label="@_localizer["Flags"]" Variant="Variant.Outlined" Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.Flags)))" ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.Flags))">
<MudChipSet T="Flag" SelectedValues="EditedTrack.Flags.ToList().AsReadOnly()" SelectedValuesChanged="(newFlags) => EditedTrack.Flags = newFlags" CheckMark SelectionMode="SelectionMode.MultiSelection" Variant="Variant.Text" Color="Color.Info">
@foreach(var flag in Flag.AvailableFlags)
{
<MudChip Value="flag">@flag.Name</MudChip>
}
</MudChipSet>
</MudField>
<MudTextField Label="@_localizer["PreGap"]" Variant="Variant.Outlined" Value="@EditedTrack.PreGap.ToString()" ValueChanged="(string value) => _applicationOptionsTimeSpanParser.TimespanTextChanged<Track, TimeSpan?>(EditedTrack, x => x.PreGap, value)"
Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.PreGap)))" ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.PreGap))" />
<MudTextField Label="@_localizer["PostGap"]" Variant="Variant.Outlined" Value="@EditedTrack.PostGap.ToString()" ValueChanged="(string value) => _applicationOptionsTimeSpanParser.TimespanTextChanged<Track, TimeSpan?>(EditedTrack, x => x.PostGap, value)"
Error="!String.IsNullOrEmpty(GetValidationErrorMessage(EditedTrack, nameof(Track.PostGap)))" ErrorText="@GetValidationErrorMessage(EditedTrack, nameof(Track.PostGap))" />
</MudForm>
</DialogContent>
<DialogActions>
<MudButton Color="Color.Info" Variant="Variant.Filled" OnClick="() => MudDialog?.Close(DialogResult.Ok(EditedTrack))">@_localizer["Save changes"]</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
private IMudDialogInstance? MudDialog { get; set; }
[Parameter]
[EditorRequired]
public Track EditedTrack { get; set; } = null!;
void TitleSelected(MusicBrainzTrack? musicBrainzTrack)
{
if ((String.IsNullOrEmpty(EditedTrack.Artist)) && (String.IsNullOrEmpty(musicBrainzTrack?.Artist) == false))
{
EditedTrack.Artist = musicBrainzTrack.Artist;
}
if ((EditedTrack.Length.HasValue == false) && (musicBrainzTrack?.Length.HasValue == true))
{
EditedTrack.Length = musicBrainzTrack?.Length;
}
}
String? GetValidationErrorMessage(object model, string propertyName)
{
String? validationErrorMessage = null;
var validationMessages = _validationService.Validate(model, propertyName);
if (validationMessages.Count() > 0)
{
validationErrorMessage = String.Join(Environment.NewLine, validationMessages);
}
return validationErrorMessage;
}
}