Skip to content

Commit

Permalink
Workshop - Show required plugins on profile pages
Browse files Browse the repository at this point in the history
Workshop - Show related profiles on plugin pages
  • Loading branch information
RobertBeekman committed Mar 3, 2024
1 parent 36bff3c commit 9132301
Show file tree
Hide file tree
Showing 25 changed files with 286 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Artemis.UI.Screens.Workshop.Entries.Details;
public class EntryInfoViewModel : ViewModelBase
{
private readonly INotificationService _notificationService;
public IGetEntryById_Entry Entry { get; }
public IEntryDetails Entry { get; }
public DateTimeOffset? UpdatedAt { get; }

public EntryInfoViewModel(IGetEntryById_Entry entry, INotificationService notificationService)
public EntryInfoViewModel(IEntryDetails entry, INotificationService notificationService)
{
_notificationService = notificationService;
Entry = entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class EntryReleasesViewModel : ViewModelBase
private readonly IWindowService _windowService;
private readonly INotificationService _notificationService;

public EntryReleasesViewModel(IGetEntryById_Entry entry, EntryInstallationHandlerFactory factory, IWindowService windowService, INotificationService notificationService)
public EntryReleasesViewModel(IEntryDetails entry, EntryInstallationHandlerFactory factory, IWindowService windowService, INotificationService notificationService)
{
_factory = factory;
_windowService = windowService;
Expand All @@ -31,7 +31,7 @@ public EntryReleasesViewModel(IGetEntryById_Entry entry, EntryInstallationHandle
OnInstallationStarted = Confirm;
}

public IGetEntryById_Entry Entry { get; }
public IEntryDetails Entry { get; }
public ReactiveCommand<Unit, Unit> DownloadLatestRelease { get; }

public Func<IEntryDetails, Task<bool>> OnInstallationStarted { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
HorizontalContentAlignment="Stretch"
Command="{CompiledBinding NavigateToEntry}"
IsVisible="{CompiledBinding Entry, Converter={x:Static ObjectConverters.IsNotNull}}">
<Grid ColumnDefinitions="Auto,*,Auto">
<Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="*, Auto">
<!-- Icon -->
<Border Grid.Column="0"
Grid.Row="0"
Grid.RowSpan="2"
CornerRadius="6"
VerticalAlignment="Center"
Margin="0 0 10 0"
Expand All @@ -34,7 +36,7 @@
</Border>

<!-- Body -->
<Grid Grid.Column="1" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
<Grid Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Stretch" RowDefinitions="Auto,*,Auto">
<TextBlock Grid.Row="0" Margin="0 0 0 5" TextTrimming="CharacterEllipsis">
<Run Classes="h5" Text="{CompiledBinding Entry.Name, FallbackValue=Title}" />
<Run Classes="subtitle">by</Run>
Expand Down Expand Up @@ -65,14 +67,26 @@
</Grid>

<!-- Info -->
<StackPanel Grid.Column="2" Margin="0 0 4 0">
<StackPanel Grid.Column="2" Grid.Row="0" Margin="0 0 4 0" HorizontalAlignment="Right">
<TextBlock TextAlignment="Right" Text="{CompiledBinding Entry.CreatedAt, FallbackValue=01-01-1337, Converter={StaticResource DateTimeConverter}}" />
<TextBlock TextAlignment="Right">
<avalonia:MaterialIcon Kind="Downloads" />
<Run Classes="h5" Text="{CompiledBinding Entry.Downloads, FallbackValue=0}" />
<Run>downloads</Run>
</TextBlock>
</StackPanel>

<!-- Install state -->
<StackPanel Grid.Column="2" Grid.Row="1" Margin="0 0 4 0" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsVisible="{CompiledBinding IsInstalled}">
<TextBlock TextAlignment="Right" IsVisible="{CompiledBinding !UpdateAvailable}">
<avalonia:MaterialIcon Kind="CheckCircle" Foreground="{DynamicResource SystemAccentColorLight1}"/>
<Run>installed</Run>
</TextBlock>
<TextBlock TextAlignment="Right" IsVisible="{CompiledBinding UpdateAvailable}">
<avalonia:MaterialIcon Kind="Update" Foreground="{DynamicResource SystemAccentColorLight1}"/>
<Run>update available</Run>
</TextBlock>
</StackPanel>
</Grid>
</Button>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
using System;
using System.Reactive;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Routing;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Models;
using Artemis.WebClient.Workshop.Services;
using PropertyChanged.SourceGenerator;
using ReactiveUI;

namespace Artemis.UI.Screens.Workshop.Entries.List;

public class EntryListItemViewModel : ActivatableViewModelBase
public partial class EntryListItemViewModel : ActivatableViewModelBase
{
private readonly IRouter _router;
[Notify] private bool _isInstalled;
[Notify] private bool _updateAvailable;

public EntryListItemViewModel(IGetEntries_Entries_Items entry, IRouter router)
public EntryListItemViewModel(IEntrySummary entry, IRouter router, IWorkshopService workshopService)
{
_router = router;

Entry = entry;
NavigateToEntry = ReactiveCommand.CreateFromTask(ExecuteNavigateToEntry);

this.WhenActivated((CompositeDisposable _) =>
{
InstalledEntry? installedEntry = workshopService.GetInstalledEntry(entry.Id);
IsInstalled = installedEntry != null;
UpdateAvailable = installedEntry != null && installedEntry.ReleaseId != entry.LatestReleaseId;
});
}

public IGetEntries_Entries_Items Entry { get; }
public IEntrySummary Entry { get; }
public ReactiveCommand<Unit, Unit> NavigateToEntry { get; }

private async Task ExecuteNavigateToEntry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Artemis.UI.Screens.Workshop.Entries.List;

public abstract partial class EntryListViewModel : RoutableScreen<WorkshopListParameters>
{
private readonly SourceList<IGetEntries_Entries_Items> _entries = new();
private readonly SourceList<IEntrySummary> _entries = new();
private readonly ObservableAsPropertyHelper<bool> _isLoading;
private readonly INotificationService _notificationService;
private readonly string _route;
Expand All @@ -37,13 +37,13 @@ protected EntryListViewModel(string route,
CategoriesViewModel categoriesViewModel,
EntryListInputViewModel entryListInputViewModel,
INotificationService notificationService,
Func<IGetEntries_Entries_Items, EntryListItemViewModel> getEntryListViewModel)
Func<IEntrySummary, EntryListItemViewModel> getEntryListViewModel)
{
_route = route;
_workshopClient = workshopClient;
_notificationService = notificationService;
_showPagination = this.WhenAnyValue<EntryListViewModel, int>(vm => vm.TotalPages).Select(t => t > 1).ToProperty(this, vm => vm.ShowPagination);
_isLoading = this.WhenAnyValue<EntryListViewModel, bool, int, int>(vm => vm.Page, vm => vm.LoadedPage, (p, c) => p != c).ToProperty(this, vm => vm.IsLoading);
_showPagination = this.WhenAnyValue(vm => vm.TotalPages).Select(t => t > 1).ToProperty(this, vm => vm.ShowPagination);
_isLoading = this.WhenAnyValue(vm => vm.Page, vm => vm.LoadedPage, (p, c) => p != c).ToProperty(this, vm => vm.IsLoading);

CategoriesViewModel = categoriesViewModel;
InputViewModel = entryListInputViewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public LayoutListViewModel(IWorkshopClient workshopClient,
CategoriesViewModel categoriesViewModel,
EntryListInputViewModel entryListInputViewModel,
INotificationService notificationService,
Func<IGetEntries_Entries_Items, EntryListItemViewModel> getEntryListViewModel)
Func<IEntrySummary, EntryListItemViewModel> getEntryListViewModel)
: base("workshop/entries/layouts", workshopClient, router, categoriesViewModel, entryListInputViewModel, notificationService, getEntryListViewModel)
{
entryListInputViewModel.SearchWatermark = "Search layouts";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public PluginListViewModel(IWorkshopClient workshopClient,
CategoriesViewModel categoriesViewModel,
EntryListInputViewModel entryListInputViewModel,
INotificationService notificationService,
Func<IGetEntries_Entries_Items, EntryListItemViewModel> getEntryListViewModel)
Func<IEntrySummary, EntryListItemViewModel> getEntryListViewModel)
: base("workshop/entries/plugins", workshopClient, router, categoriesViewModel, entryListInputViewModel, notificationService, getEntryListViewModel)
{
entryListInputViewModel.SearchWatermark = "Search plugins";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ProfileListViewModel(IWorkshopClient workshopClient,
CategoriesViewModel categoriesViewModel,
EntryListInputViewModel entryListInputViewModel,
INotificationService notificationService,
Func<IGetEntries_Entries_Items, EntryListItemViewModel> getEntryListViewModel)
Func<IEntrySummary, EntryListItemViewModel> getEntryListViewModel)
: base("workshop/entries/profiles", workshopClient, router, categoriesViewModel, entryListInputViewModel, notificationService, getEntryListViewModel)
{
entryListInputViewModel.SearchWatermark = "Search profiles";
Expand Down
18 changes: 11 additions & 7 deletions src/Artemis.UI/Screens/Workshop/Layout/LayoutDetailsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
</Border>
</StackPanel>

<Border Classes="card" Grid.Row="1" Grid.Column="1" Margin="10 0">
<mdxaml:MarkdownScrollViewer Markdown="{CompiledBinding Entry.Description}" MarkdownStyleName="FluentAvalonia">
<mdxaml:MarkdownScrollViewer.Styles>
<StyleInclude Source="/Styles/Markdown.axaml" />
</mdxaml:MarkdownScrollViewer.Styles>
</mdxaml:MarkdownScrollViewer>
</Border>
<ScrollViewer Grid.Row="1" Grid.Column="1">
<StackPanel Margin="10 0" Spacing="10">
<Border Classes="card">
<mdxaml:MarkdownScrollViewer Markdown="{CompiledBinding Entry.Description}" MarkdownStyleName="FluentAvalonia">
<mdxaml:MarkdownScrollViewer.Styles>
<StyleInclude Source="/Styles/Markdown.axaml" />
</mdxaml:MarkdownScrollViewer.Styles>
</mdxaml:MarkdownScrollViewer>
</Border>
</StackPanel>
</ScrollViewer>

<ContentControl Grid.Row="1" Grid.Column="2" IsVisible="{CompiledBinding Entry.Images.Count}" Content="{CompiledBinding EntryImagesViewModel}" />
</Grid>
Expand Down
29 changes: 11 additions & 18 deletions src/Artemis.UI/Screens/Workshop/Layout/LayoutDetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public partial class LayoutDetailsViewModel : RoutableScreen<WorkshopDetailParam
private readonly IWorkshopClient _client;
private readonly IDeviceService _deviceService;
private readonly IWindowService _windowService;
private readonly Func<IGetEntryById_Entry, EntryInfoViewModel> _getEntryInfoViewModel;
private readonly Func<IGetEntryById_Entry, EntryReleasesViewModel> _getEntryReleasesViewModel;
private readonly Func<IGetEntryById_Entry, EntryImagesViewModel> _getEntryImagesViewModel;
[Notify] private IGetEntryById_Entry? _entry;
private readonly Func<IEntryDetails, EntryInfoViewModel> _getEntryInfoViewModel;
private readonly Func<IEntryDetails, EntryReleasesViewModel> _getEntryReleasesViewModel;
private readonly Func<IEntryDetails, EntryImagesViewModel> _getEntryImagesViewModel;
[Notify] private IEntryDetails? _entry;
[Notify] private EntryInfoViewModel? _entryInfoViewModel;
[Notify] private EntryReleasesViewModel? _entryReleasesViewModel;
[Notify] private EntryImagesViewModel? _entryImagesViewModel;

public LayoutDetailsViewModel(IWorkshopClient client,
IDeviceService deviceService,
IWindowService windowService,
Func<IGetEntryById_Entry, EntryInfoViewModel> getEntryInfoViewModel,
Func<IGetEntryById_Entry, EntryReleasesViewModel> getEntryReleasesViewModel,
Func<IGetEntryById_Entry, EntryImagesViewModel> getEntryImagesViewModel)
Func<IEntryDetails, EntryInfoViewModel> getEntryInfoViewModel,
Func<IEntryDetails, EntryReleasesViewModel> getEntryReleasesViewModel,
Func<IEntryDetails, EntryImagesViewModel> getEntryImagesViewModel)
{
_client = client;
_deviceService = deviceService;
Expand All @@ -59,19 +59,12 @@ private async Task GetEntry(long entryId, CancellationToken cancellationToken)
return;

Entry = result.Data?.Entry;
if (Entry == null)
{
EntryInfoViewModel = null;
EntryReleasesViewModel = null;
}
else
{
EntryInfoViewModel = _getEntryInfoViewModel(Entry);
EntryReleasesViewModel = _getEntryReleasesViewModel(Entry);
EntryImagesViewModel = _getEntryImagesViewModel(Entry);
EntryInfoViewModel = Entry != null ? _getEntryInfoViewModel(Entry) : null;
EntryReleasesViewModel = Entry != null ? _getEntryReleasesViewModel(Entry) : null;
EntryImagesViewModel = Entry != null ? _getEntryImagesViewModel(Entry) : null;

if (EntryReleasesViewModel != null)
EntryReleasesViewModel.OnInstallationFinished = OnInstallationFinished;
}
}

private async Task OnInstallationFinished(InstalledEntry installedEntry)
Expand Down
28 changes: 21 additions & 7 deletions src/Artemis.UI/Screens/Workshop/Plugins/PluginDetailsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@
</Border>
</StackPanel>

<Border Classes="card" Grid.Row="1" Grid.Column="1" Margin="10 0">
<mdxaml:MarkdownScrollViewer Markdown="{CompiledBinding Entry.Description}" MarkdownStyleName="FluentAvalonia">
<mdxaml:MarkdownScrollViewer.Styles>
<StyleInclude Source="/Styles/Markdown.axaml" />
</mdxaml:MarkdownScrollViewer.Styles>
</mdxaml:MarkdownScrollViewer>
</Border>
<ScrollViewer Grid.Row="1" Grid.Column="1">
<StackPanel Margin="10 0" Spacing="10">
<Border Classes="card">
<mdxaml:MarkdownScrollViewer Markdown="{CompiledBinding Entry.Description}" MarkdownStyleName="FluentAvalonia">
<mdxaml:MarkdownScrollViewer.Styles>
<StyleInclude Source="/Styles/Markdown.axaml" />
</mdxaml:MarkdownScrollViewer.Styles>
</mdxaml:MarkdownScrollViewer>
</Border>

<Border Classes="card" VerticalAlignment="Top" IsVisible="{CompiledBinding Dependants, Converter={x:Static ObjectConverters.IsNotNull}}">
<StackPanel>
<TextBlock Theme="{StaticResource SubtitleTextBlockStyle}">Used by these profiles</TextBlock>
<Border Classes="card-separator" />
<ScrollViewer>
<ItemsControl ItemsSource="{CompiledBinding Dependants}"></ItemsControl>
</ScrollViewer>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>

<ContentControl Grid.Row="1" Grid.Column="2" IsVisible="{CompiledBinding Entry.Images.Count}" Content="{CompiledBinding EntryImagesViewModel}" />
</Grid>
Expand Down
43 changes: 25 additions & 18 deletions src/Artemis.UI/Screens/Workshop/Plugins/PluginDetailsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Screens.Workshop.Entries.Details;
using Artemis.UI.Screens.Workshop.Entries.List;
using Artemis.UI.Screens.Workshop.Parameters;
using Artemis.UI.Screens.Workshop.Plugins.Dialogs;
using Artemis.UI.Shared.Routing;
Expand All @@ -21,27 +24,31 @@ public partial class PluginDetailsViewModel : RoutableScreen<WorkshopDetailParam
private readonly IWorkshopClient _client;
private readonly IWindowService _windowService;
private readonly IPluginManagementService _pluginManagementService;
private readonly Func<IGetEntryById_Entry, EntryInfoViewModel> _getEntryInfoViewModel;
private readonly Func<IGetEntryById_Entry, EntryReleasesViewModel> _getEntryReleasesViewModel;
private readonly Func<IGetEntryById_Entry, EntryImagesViewModel> _getEntryImagesViewModel;
[Notify] private IGetEntryById_Entry? _entry;
private readonly Func<IEntryDetails, EntryInfoViewModel> _getEntryInfoViewModel;
private readonly Func<IEntryDetails, EntryReleasesViewModel> _getEntryReleasesViewModel;
private readonly Func<IEntryDetails, EntryImagesViewModel> _getEntryImagesViewModel;
private readonly Func<IEntrySummary, EntryListItemViewModel> _getEntryListViewModel;
[Notify] private IEntryDetails? _entry;
[Notify] private EntryInfoViewModel? _entryInfoViewModel;
[Notify] private EntryReleasesViewModel? _entryReleasesViewModel;
[Notify] private EntryImagesViewModel? _entryImagesViewModel;

[Notify] private ReadOnlyObservableCollection<EntryListItemViewModel>? _dependants;

public PluginDetailsViewModel(IWorkshopClient client,
IWindowService windowService,
IPluginManagementService pluginManagementService,
Func<IGetEntryById_Entry, EntryInfoViewModel> getEntryInfoViewModel,
Func<IGetEntryById_Entry, EntryReleasesViewModel> getEntryReleasesViewModel,
Func<IGetEntryById_Entry, EntryImagesViewModel> getEntryImagesViewModel)
Func<IEntryDetails, EntryInfoViewModel> getEntryInfoViewModel,
Func<IEntryDetails, EntryReleasesViewModel> getEntryReleasesViewModel,
Func<IEntryDetails, EntryImagesViewModel> getEntryImagesViewModel,
Func<IEntrySummary, EntryListItemViewModel> getEntryListViewModel)
{
_client = client;
_windowService = windowService;
_pluginManagementService = pluginManagementService;
_getEntryInfoViewModel = getEntryInfoViewModel;
_getEntryReleasesViewModel = getEntryReleasesViewModel;
_getEntryImagesViewModel = getEntryImagesViewModel;
_getEntryListViewModel = getEntryListViewModel;
}

public override async Task OnNavigating(WorkshopDetailParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
Expand All @@ -56,20 +63,20 @@ private async Task GetEntry(long entryId, CancellationToken cancellationToken)
return;

Entry = result.Data?.Entry;
if (Entry == null)
{
EntryInfoViewModel = null;
EntryReleasesViewModel = null;
}
else
{
EntryInfoViewModel = _getEntryInfoViewModel(Entry);
EntryReleasesViewModel = _getEntryReleasesViewModel(Entry);
EntryImagesViewModel = _getEntryImagesViewModel(Entry);
EntryInfoViewModel = Entry != null ? _getEntryInfoViewModel(Entry) : null;
EntryReleasesViewModel = Entry != null ? _getEntryReleasesViewModel(Entry) : null;
EntryImagesViewModel = Entry != null ? _getEntryImagesViewModel(Entry) : null;

if (EntryReleasesViewModel != null)
{
EntryReleasesViewModel.OnInstallationStarted = OnInstallationStarted;
EntryReleasesViewModel.OnInstallationFinished = OnInstallationFinished;
}

IReadOnlyList<IEntrySummary>? dependants = (await _client.GetDependantEntries.ExecuteAsync(entryId, 0, 25, cancellationToken)).Data?.Entries?.Items;
Dependants = dependants != null && dependants.Any()
? new ReadOnlyObservableCollection<EntryListItemViewModel>(new ObservableCollection<EntryListItemViewModel>(dependants.Select(_getEntryListViewModel)))
: null;
}

private async Task<bool> OnInstallationStarted(IEntryDetails entryDetails)
Expand Down
Loading

0 comments on commit 9132301

Please sign in to comment.