using Avalonia.Collections; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; using Needlework.Net.Desktop.Messages; using System.Linq; namespace Needlework.Net.Desktop.ViewModels { public partial class EndpointViewModel : ObservableObject { public string Endpoint { get; } public string Title => Endpoint; [ObservableProperty] private IAvaloniaReadOnlyList _pathOperations; [ObservableProperty] private PathOperationViewModel? _selectedPathOperation; [ObservableProperty] private string? _search; [ObservableProperty] private IAvaloniaReadOnlyList _filteredPathOperations; public EndpointViewModel(string endpoint) { Endpoint = endpoint; var handler = WeakReferenceMessenger.Default.Send().Response; PathOperations = new AvaloniaList(handler.Plugins[endpoint].Select(x => new PathOperationViewModel(x))); FilteredPathOperations = new AvaloniaList(PathOperations); } partial void OnSearchChanged(string? value) { if (string.IsNullOrWhiteSpace(value)) { FilteredPathOperations = new AvaloniaList(PathOperations); return; } FilteredPathOperations = new AvaloniaList(PathOperations.Where(o => o.Path.ToLower().Contains(value.ToLower()))); } partial void OnSelectedPathOperationChanged(PathOperationViewModel? value) { if (value == null) return; WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(value.Operation.RequestTemplate ?? string.Empty, "EndpointRequestEditor"))); } } }