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