mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Workshop Library - Installed entries WIP
This commit is contained in:
parent
c69be2836e
commit
876465cfdb
@ -0,0 +1,53 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:tabs="clr-namespace:Artemis.UI.Screens.Workshop.Library.Tabs"
|
||||||
|
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
|
||||||
|
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="Artemis.UI.Screens.Workshop.Library.Tabs.InstalledTabItemView"
|
||||||
|
x:DataType="tabs:InstalledTabItemViewModel">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<converters:EntryIconUriConverter x:Key="EntryIconUriConverter" />
|
||||||
|
<converters:DateTimeConverter x:Key="DateTimeConverter" />
|
||||||
|
</UserControl.Resources>
|
||||||
|
<Border Classes="card-condensed"
|
||||||
|
MinHeight="80"
|
||||||
|
MaxHeight="110"
|
||||||
|
Padding="12 6"
|
||||||
|
Margin="0 0 0 5"
|
||||||
|
HorizontalAlignment="Stretch">
|
||||||
|
<Grid ColumnDefinitions="Auto,*,Auto">
|
||||||
|
<!-- Icon -->
|
||||||
|
<Border Grid.Column="0"
|
||||||
|
CornerRadius="6"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Margin="0 0 10 0"
|
||||||
|
Width="50"
|
||||||
|
Height="50"
|
||||||
|
ClipToBounds="True">
|
||||||
|
<Image Stretch="UniformToFill" asyncImageLoader:ImageLoader.Source="{CompiledBinding InstalledEntry.EntryId, Converter={StaticResource EntryIconUriConverter}, Mode=OneWay}" />
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- Body -->
|
||||||
|
<Grid Grid.Column="1" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
|
||||||
|
<TextBlock Grid.Row="0"
|
||||||
|
Classes="h5 no-margin"
|
||||||
|
TextTrimming="CharacterEllipsis"
|
||||||
|
Text="{CompiledBinding InstalledEntry.Name, FallbackValue=Title}" />
|
||||||
|
<TextBlock Grid.Row="1"
|
||||||
|
Classes="subtitle"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
TextTrimming="CharacterEllipsis"
|
||||||
|
Text="{CompiledBinding InstalledEntry.Summary, FallbackValue=Summary}">
|
||||||
|
</TextBlock>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Info -->
|
||||||
|
<StackPanel Grid.Column="2" Margin="0 0 4 0">
|
||||||
|
<TextBlock TextAlignment="Right" Text="{CompiledBinding InstalledEntry.InstalledAt, FallbackValue=01-01-1337, Converter={StaticResource DateTimeConverter}}" />
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</UserControl>
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Screens.Workshop.Library.Tabs;
|
||||||
|
|
||||||
|
public partial class InstalledTabItemView : UserControl
|
||||||
|
{
|
||||||
|
public InstalledTabItemView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
using Artemis.UI.Shared;
|
||||||
|
using Artemis.WebClient.Workshop.Services;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Screens.Workshop.Library.Tabs;
|
||||||
|
|
||||||
|
public class InstalledTabItemViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
public InstalledTabItemViewModel(InstalledEntry installedEntry)
|
||||||
|
{
|
||||||
|
InstalledEntry = installedEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InstalledEntry InstalledEntry { get; }
|
||||||
|
}
|
||||||
@ -2,7 +2,17 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:tabs="clr-namespace:Artemis.UI.Screens.Workshop.Library.Tabs"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Artemis.UI.Screens.Workshop.Library.Tabs.InstalledTabView">
|
x:Class="Artemis.UI.Screens.Workshop.Library.Tabs.InstalledTabView"
|
||||||
Installed entries management here 🫡
|
x:DataType="tabs:InstalledTabViewModel">
|
||||||
</UserControl>
|
<ScrollViewer>
|
||||||
|
<ItemsRepeater ItemsSource="{CompiledBinding InstalledEntries}">
|
||||||
|
<ItemsRepeater.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ContentControl Content="{CompiledBinding}"></ContentControl>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsRepeater.ItemTemplate>
|
||||||
|
</ItemsRepeater>
|
||||||
|
</ScrollViewer>
|
||||||
|
</UserControl>
|
||||||
@ -1,9 +1,55 @@
|
|||||||
using Artemis.UI.Shared;
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Reactive.Disposables;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using Artemis.UI.Shared.Routing;
|
using Artemis.UI.Shared.Routing;
|
||||||
|
using Artemis.WebClient.Workshop.Services;
|
||||||
|
using Avalonia.ReactiveUI;
|
||||||
|
using DynamicData;
|
||||||
|
using DynamicData.Binding;
|
||||||
|
using ReactiveUI;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Workshop.Library.Tabs;
|
namespace Artemis.UI.Screens.Workshop.Library.Tabs;
|
||||||
|
|
||||||
public class InstalledTabViewModel : RoutableScreen
|
public class InstalledTabViewModel : RoutableScreen
|
||||||
{
|
{
|
||||||
|
private string? _searchEntryInput;
|
||||||
|
|
||||||
|
public InstalledTabViewModel(IWorkshopService workshopService, Func<InstalledEntry, InstalledTabItemViewModel> getInstalledTabItemViewModel)
|
||||||
|
{
|
||||||
|
SourceList<InstalledEntry> installedEntries = new();
|
||||||
|
IObservable<Func<InstalledEntry, bool>> pluginFilter = this.WhenAnyValue(vm => vm.SearchEntryInput).Throttle(TimeSpan.FromMilliseconds(100)).Select(CreatePredicate);
|
||||||
|
|
||||||
|
installedEntries.Connect()
|
||||||
|
.Filter(pluginFilter)
|
||||||
|
.Sort(SortExpressionComparer<InstalledEntry>.Ascending(p => p.Name))
|
||||||
|
.Transform(getInstalledTabItemViewModel)
|
||||||
|
.ObserveOn(AvaloniaScheduler.Instance)
|
||||||
|
.Bind(out ReadOnlyObservableCollection<InstalledTabItemViewModel> installedEntryViewModels)
|
||||||
|
.Subscribe();
|
||||||
|
InstalledEntries = installedEntryViewModels;
|
||||||
|
|
||||||
|
this.WhenActivated(d =>
|
||||||
|
{
|
||||||
|
installedEntries.AddRange(workshopService.GetInstalledEntries());
|
||||||
|
Disposable.Create(installedEntries, e => e.Clear()).DisposeWith(d);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyObservableCollection<InstalledTabItemViewModel> InstalledEntries { get; }
|
||||||
|
|
||||||
|
public string? SearchEntryInput
|
||||||
|
{
|
||||||
|
get => _searchEntryInput;
|
||||||
|
set => RaiseAndSetIfChanged(ref _searchEntryInput, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Func<InstalledEntry, bool> CreatePredicate(string? text)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(text))
|
||||||
|
return _ => true;
|
||||||
|
|
||||||
|
return data => data.Name.Contains(text, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
|
data.Summary.Contains(text, StringComparison.InvariantCultureIgnoreCase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -10,6 +10,8 @@ public interface IWorkshopService
|
|||||||
Task<WorkshopStatus> GetWorkshopStatus(CancellationToken cancellationToken);
|
Task<WorkshopStatus> GetWorkshopStatus(CancellationToken cancellationToken);
|
||||||
Task<bool> ValidateWorkshopStatus(CancellationToken cancellationToken);
|
Task<bool> ValidateWorkshopStatus(CancellationToken cancellationToken);
|
||||||
Task NavigateToEntry(Guid entryId, EntryType entryType);
|
Task NavigateToEntry(Guid entryId, EntryType entryType);
|
||||||
|
|
||||||
|
List<InstalledEntry> GetInstalledEntries();
|
||||||
InstalledEntry? GetInstalledEntry(IGetEntryById_Entry entry);
|
InstalledEntry? GetInstalledEntry(IGetEntryById_Entry entry);
|
||||||
InstalledEntry CreateInstalledEntry(IGetEntryById_Entry entry);
|
InstalledEntry CreateInstalledEntry(IGetEntryById_Entry entry);
|
||||||
void SaveInstalledEntry(InstalledEntry entry);
|
void SaveInstalledEntry(InstalledEntry entry);
|
||||||
|
|||||||
@ -103,6 +103,11 @@ public class WorkshopService : IWorkshopService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<InstalledEntry> GetInstalledEntries()
|
||||||
|
{
|
||||||
|
return _entryRepository.GetAll().Select(e => new InstalledEntry(e)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public InstalledEntry? GetInstalledEntry(IGetEntryById_Entry entry)
|
public InstalledEntry? GetInstalledEntry(IGetEntryById_Entry entry)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user