using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Reactive.Linq; using System.Text; using DynamicData; using NodeNetwork.Views; using ReactiveUI; using Splat; namespace NodeNetwork.ViewModels { public class EndpointGroupViewModel : ReactiveObject { static EndpointGroupViewModel() { NNViewRegistrar.AddRegistration(() => new EndpointGroupView(), typeof(IViewFor)); } #region VisibleInputs /// /// The list of inputs that is currently visible on this group. /// Some inputs may be hidden if the node is collapsed. /// public IObservableList VisibleInputs { get; } #endregion #region VisibleOutputs /// /// The list of outputs that is currently visible on this group. /// Some outputs may be hidden if the node is collapsed. /// public IObservableList VisibleOutputs { get; } #endregion #region Group /// /// The endpoint group wrapping the name and the parent group of this group. /// public EndpointGroup Group { get; } #endregion #region Children /// /// The list of nested endpoint groups. /// public ReadOnlyObservableCollection Children => _children; private readonly ReadOnlyObservableCollection _children; #endregion public EndpointGroupViewModel( EndpointGroup group, IObservable> allInputs, IObservable> allOutputs, IObservableCache, EndpointGroup> children, EndpointGroupViewModelFactory endpointGroupViewModelFactory) { Group = group; VisibleInputs = allInputs.Filter(e => e.Group == group).AsObservableList(); VisibleOutputs = allOutputs.Filter(e => e.Group == group).AsObservableList(); children .Connect() .Transform(n => endpointGroupViewModelFactory(n.Key, allInputs, allOutputs, n.Children, endpointGroupViewModelFactory)) .Bind(out _children) .Subscribe(); } } }