You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
12 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||
|
using DynamicData;
|
||
|
using DynamicData.Binding;
|
||
|
using StabilityMatrix.Avalonia.Models.HuggingFace;
|
||
|
using StabilityMatrix.Avalonia.ViewModels.Base;
|
||
|
|
||
|
namespace StabilityMatrix.Avalonia.ViewModels.HuggingFacePage;
|
||
|
|
||
|
public partial class CategoryViewModel : ViewModelBase
|
||
|
{
|
||
|
[ObservableProperty]
|
||
|
private IObservableCollection<HuggingfaceItemViewModel> items =
|
||
|
new ObservableCollectionExtended<HuggingfaceItemViewModel>();
|
||
|
|
||
12 months ago
|
public SourceCache<HuggingfaceItem, string> ItemsCache { get; } = new(i => i.RepositoryPath + i.ModelName);
|
||
12 months ago
|
|
||
|
[ObservableProperty]
|
||
|
private string? title;
|
||
|
|
||
|
[ObservableProperty]
|
||
|
private bool isChecked;
|
||
|
|
||
|
[ObservableProperty]
|
||
|
private int numSelected;
|
||
|
|
||
|
public CategoryViewModel(IEnumerable<HuggingfaceItem> items)
|
||
|
{
|
||
|
ItemsCache
|
||
|
.Connect()
|
||
|
.DeferUntilLoaded()
|
||
|
.Transform(i => new HuggingfaceItemViewModel { Item = i })
|
||
|
.Bind(Items)
|
||
|
.WhenPropertyChanged(p => p.IsSelected)
|
||
|
.Subscribe(_ => NumSelected = Items.Count(i => i.IsSelected));
|
||
|
|
||
|
ItemsCache.EditDiff(items, (a, b) => a.RepositoryPath == b.RepositoryPath);
|
||
|
}
|
||
|
|
||
|
partial void OnIsCheckedChanged(bool value)
|
||
|
{
|
||
|
if (Items is null)
|
||
|
return;
|
||
|
|
||
|
foreach (var item in Items)
|
||
|
{
|
||
|
item.IsSelected = value;
|
||
|
}
|
||
|
}
|
||
|
}
|