| | | 1 | | @using System.ComponentModel |
| | | 2 | | @implements IDisposable |
| | | 3 | | |
| | | 4 | | <RadzenDropDown TValue="string" |
| | | 5 | | @attributes="AdditionalAttributes" |
| | | 6 | | Data="@viewModels" |
| | | 7 | | @bind-Value="@ProfileManager.ActiveProfile.Model" |
| | | 8 | | Placeholder="Model" |
| | | 9 | | AllowFiltering="true" |
| | | 10 | | LoadData="@OnLoadData" |
| | | 11 | | Change="@OnValueChange" /> |
| | | 12 | | |
| | | 13 | | @code { |
| | | 14 | | [Parameter(CaptureUnmatchedValues = true)] |
| | 0 | 15 | | public Dictionary<string, object> AdditionalAttributes { get; set; } = []; |
| | | 16 | | |
| | 0 | 17 | | [Inject] private IProfileManager ProfileManager { get; set; } = null!; |
| | | 18 | | |
| | | 19 | | // Список для отображения (включает оригинальные данные или опцию добавления) |
| | 0 | 20 | | IEnumerable<string> viewModels = []; |
| | | 21 | | |
| | | 22 | | protected override void OnInitialized() |
| | | 23 | | { |
| | 0 | 24 | | viewModels = ProfileManager.ActiveProfile.AvailableModels; |
| | 0 | 25 | | ProfileManager.PropertyChanged += ProfilePropertyChanged; |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | void OnLoadData(LoadDataArgs args) |
| | | 29 | | { |
| | 0 | 30 | | var allModels = ProfileManager.ActiveProfile.AvailableModels; |
| | | 31 | | |
| | 0 | 32 | | if (string.IsNullOrEmpty(args.Filter)) |
| | | 33 | | { |
| | 0 | 34 | | viewModels = allModels; |
| | | 35 | | } |
| | | 36 | | else |
| | | 37 | | { |
| | | 38 | | // Фильтруем существующие модели |
| | 0 | 39 | | var filtered = allModels |
| | 0 | 40 | | .Where(m => m.Contains(args.Filter, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 41 | | .ToList(); |
| | | 42 | | |
| | | 43 | | // Если точного совпадения нет - добавляем пункт-команду |
| | 0 | 44 | | if (filtered.Count == 0) |
| | | 45 | | { |
| | 0 | 46 | | filtered.Insert(0, $"➕ {args.Filter}"); |
| | | 47 | | } |
| | | 48 | | |
| | 0 | 49 | | viewModels = filtered; |
| | | 50 | | } |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | void OnValueChange(object value) |
| | | 54 | | { |
| | 0 | 55 | | var selectedValue = value?.ToString(); |
| | | 56 | | |
| | 0 | 57 | | if (!string.IsNullOrEmpty(selectedValue) && selectedValue.StartsWith("➕ ")) |
| | | 58 | | { |
| | 0 | 59 | | var newModelName = selectedValue.Substring(2).Trim(); |
| | 0 | 60 | | ProfileManager.ActiveProfile.Model = newModelName; |
| | 0 | 61 | | viewModels = ProfileManager.ActiveProfile.AvailableModels; |
| | | 62 | | } |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | private void ProfilePropertyChanged(object? sender, PropertyChangedEventArgs args) |
| | | 66 | | { |
| | 0 | 67 | | if (args.PropertyName is nameof(ConnectionProfile.AvailableModels) or nameof(ProfileOptions.ActiveProfileId)) |
| | | 68 | | { |
| | 0 | 69 | | viewModels = ProfileManager.ActiveProfile.AvailableModels; |
| | 0 | 70 | | InvokeAsync(StateHasChanged); |
| | | 71 | | } |
| | 0 | 72 | | else if (args.PropertyName is nameof(ConnectionProfile.Model)) |
| | | 73 | | { |
| | 0 | 74 | | InvokeAsync(StateHasChanged); |
| | | 75 | | } |
| | 0 | 76 | | } |
| | | 77 | | |
| | | 78 | | public void Dispose() |
| | | 79 | | { |
| | 0 | 80 | | ProfileManager.PropertyChanged -= ProfilePropertyChanged; |
| | 0 | 81 | | } |
| | | 82 | | } |