mirror of
https://github.com/BlossomiShymae/Needlework.Net.git
synced 2025-12-06 18:20:47 +01:00
feat: display clicked schema to pane
This commit is contained in:
8
Needlework.Net/Models/SchemaPaneItem.cs
Normal file
8
Needlework.Net/Models/SchemaPaneItem.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Needlework.Net.ViewModels.Pages.Endpoints;
|
||||||
|
|
||||||
|
namespace Needlework.Net.Models
|
||||||
|
{
|
||||||
|
public record SchemaPaneItem(string Key, Tab Tab)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,6 +102,7 @@ class Program
|
|||||||
builder.AddSingleton<DialogService>();
|
builder.AddSingleton<DialogService>();
|
||||||
builder.AddSingleton<DocumentService>();
|
builder.AddSingleton<DocumentService>();
|
||||||
builder.AddSingleton<NotificationService>();
|
builder.AddSingleton<NotificationService>();
|
||||||
|
builder.AddSingleton<SchemaPaneService>();
|
||||||
builder.AddSingleton<IFlurlClientCache>(new FlurlClientCache()
|
builder.AddSingleton<IFlurlClientCache>(new FlurlClientCache()
|
||||||
.Add("GithubClient", "https://api.github.com")
|
.Add("GithubClient", "https://api.github.com")
|
||||||
.Add("GithubUserContentClient", "https://raw.githubusercontent.com")
|
.Add("GithubUserContentClient", "https://raw.githubusercontent.com")
|
||||||
|
|||||||
20
Needlework.Net/Services/SchemaPaneService.cs
Normal file
20
Needlework.Net/Services/SchemaPaneService.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Needlework.Net.Models;
|
||||||
|
using Needlework.Net.ViewModels.Pages.Endpoints;
|
||||||
|
using System;
|
||||||
|
using System.Reactive.Subjects;
|
||||||
|
|
||||||
|
namespace Needlework.Net.Services
|
||||||
|
{
|
||||||
|
public class SchemaPaneService
|
||||||
|
{
|
||||||
|
private readonly Subject<SchemaPaneItem> _schemaPaneItemsSubject = new();
|
||||||
|
|
||||||
|
public IObservable<SchemaPaneItem> SchemaPaneItems { get { return _schemaPaneItemsSubject; } }
|
||||||
|
|
||||||
|
public void Add(string key, Tab tab)
|
||||||
|
{
|
||||||
|
var schemaPaneItem = new SchemaPaneItem(key, tab);
|
||||||
|
_schemaPaneItemsSubject.OnNext(schemaPaneItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,15 +41,18 @@ public partial class MainWindowViewModel
|
|||||||
|
|
||||||
private readonly DialogService _dialogService;
|
private readonly DialogService _dialogService;
|
||||||
|
|
||||||
|
private readonly SchemaPaneService _schemaPaneService;
|
||||||
|
|
||||||
private readonly IDisposable _checkForUpdatesDisposable;
|
private readonly IDisposable _checkForUpdatesDisposable;
|
||||||
|
|
||||||
private readonly IDisposable _checkForSchemaVersionDisposable;
|
private readonly IDisposable _checkForSchemaVersionDisposable;
|
||||||
|
|
||||||
public MainWindowViewModel(IEnumerable<PageBase> pages, DialogService dialogService, DocumentService documentService, NotificationService notificationService, IFlurlClientCache clients)
|
public MainWindowViewModel(IEnumerable<PageBase> pages, DialogService dialogService, DocumentService documentService, NotificationService notificationService, IFlurlClientCache clients, SchemaPaneService schemaPaneService)
|
||||||
{
|
{
|
||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
_documentService = documentService;
|
_documentService = documentService;
|
||||||
_notificationService = notificationService;
|
_notificationService = notificationService;
|
||||||
|
_schemaPaneService = schemaPaneService;
|
||||||
_githubClient = clients.Get("GithubClient");
|
_githubClient = clients.Get("GithubClient");
|
||||||
|
|
||||||
NavigationViewItems = pages
|
NavigationViewItems = pages
|
||||||
@@ -68,6 +71,26 @@ public partial class MainWindowViewModel
|
|||||||
Notifications.Remove(vm);
|
Notifications.Remove(vm);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_schemaPaneService.SchemaPaneItems.Subscribe(async item =>
|
||||||
|
{
|
||||||
|
var document = item.Tab switch
|
||||||
|
{
|
||||||
|
Pages.Endpoints.Tab.LCU => await documentService.GetLcuSchemaDocumentAsync(),
|
||||||
|
Pages.Endpoints.Tab.GameClient => await documentService.GetLolClientDocumentAsync(),
|
||||||
|
_ => throw new NotImplementedException()
|
||||||
|
};
|
||||||
|
var propertyClassViewModel = OpenApiHelpers.WalkSchema(document.OpenApiDocument.Components.Schemas[item.Key], document.OpenApiDocument);
|
||||||
|
var schemaViewModel = new SchemaViewModel(propertyClassViewModel);
|
||||||
|
if (Schemas.ToList().Find(schema => schema.Id == schemaViewModel.Id) == null)
|
||||||
|
{
|
||||||
|
Schemas.Add(schemaViewModel);
|
||||||
|
IsPaneOpen = true;
|
||||||
|
|
||||||
|
OpenSchemaPaneCommand.NotifyCanExecuteChanged();
|
||||||
|
CloseSchemaAllCommand.NotifyCanExecuteChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_checkForUpdatesDisposable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromMinutes(10))
|
_checkForUpdatesDisposable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromMinutes(10))
|
||||||
.Select(time => Unit.Default)
|
.Select(time => Unit.Default)
|
||||||
.Subscribe(async _ =>
|
.Subscribe(async _ =>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Needlework.Net.Services;
|
||||||
using Needlework.Net.ViewModels.Pages.Endpoints;
|
using Needlework.Net.ViewModels.Pages.Endpoints;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
@@ -6,8 +8,12 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
|
|||||||
{
|
{
|
||||||
public partial class SchemaSearchDetailsViewModel : ObservableObject
|
public partial class SchemaSearchDetailsViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
public SchemaSearchDetailsViewModel(Tab tab, PropertyClassViewModel vm)
|
private readonly SchemaPaneService _schemaPaneService;
|
||||||
|
|
||||||
|
public SchemaSearchDetailsViewModel(Tab tab, PropertyClassViewModel vm, SchemaPaneService schemaPaneService)
|
||||||
{
|
{
|
||||||
|
_schemaPaneService = schemaPaneService;
|
||||||
|
|
||||||
Tab = tab;
|
Tab = tab;
|
||||||
Id = vm.Id;
|
Id = vm.Id;
|
||||||
}
|
}
|
||||||
@@ -22,5 +28,11 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
|
|||||||
Tab.GameClient => "Game Client",
|
Tab.GameClient => "Game Client",
|
||||||
_ => throw new NotImplementedException()
|
_ => throw new NotImplementedException()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private void Display()
|
||||||
|
{
|
||||||
|
_schemaPaneService.Add(Id, Tab);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Avalonia.Threading;
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using DebounceThrottle;
|
using DebounceThrottle;
|
||||||
using Needlework.Net.Helpers;
|
using Needlework.Net.Helpers;
|
||||||
|
using Needlework.Net.Services;
|
||||||
using Needlework.Net.ViewModels.Pages.Endpoints;
|
using Needlework.Net.ViewModels.Pages.Endpoints;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -17,11 +18,14 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
|
|||||||
|
|
||||||
private readonly DocumentService _documentService;
|
private readonly DocumentService _documentService;
|
||||||
|
|
||||||
|
private readonly SchemaPaneService _schemaPaneService;
|
||||||
|
|
||||||
private List<SchemaSearchDetailsViewModel> _schemas = [];
|
private List<SchemaSearchDetailsViewModel> _schemas = [];
|
||||||
|
|
||||||
public SchemasViewModel(DocumentService documentService) : base("Schemas", "fa-solid fa-file-lines", -100)
|
public SchemasViewModel(DocumentService documentService, SchemaPaneService schemaPaneService) : base("Schemas", "fa-solid fa-file-lines", -100)
|
||||||
{
|
{
|
||||||
_documentService = documentService;
|
_documentService = documentService;
|
||||||
|
_schemaPaneService = schemaPaneService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
@@ -61,8 +65,8 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
|
|||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
var schemas = Enumerable.Concat(
|
var schemas = Enumerable.Concat(
|
||||||
lcuSchemaDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.LCU, OpenApiHelpers.WalkSchema(schema, lcuSchemaDocument.OpenApiDocument))),
|
lcuSchemaDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.LCU, OpenApiHelpers.WalkSchema(schema, lcuSchemaDocument.OpenApiDocument), _schemaPaneService)),
|
||||||
lolClientDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.GameClient, OpenApiHelpers.WalkSchema(schema, lolClientDocument.OpenApiDocument)))
|
lolClientDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.GameClient, OpenApiHelpers.WalkSchema(schema, lolClientDocument.OpenApiDocument), _schemaPaneService))
|
||||||
).ToList();
|
).ToList();
|
||||||
_schemas = schemas;
|
_schemas = schemas;
|
||||||
SchemaItems = schemas.ToList();
|
SchemaItems = schemas.ToList();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||||
xmlns:i="https://github.com/projektanker/icons.avalonia"
|
xmlns:i="https://github.com/projektanker/icons.avalonia"
|
||||||
xmlns:vm="using:Needlework.Net.ViewModels.MainWindow"
|
xmlns:vm="using:Needlework.Net.ViewModels.MainWindow"
|
||||||
|
xmlns:views="using:Needlework.Net.Views.MainWindow"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Needlework.Net.Views.MainWindow.MainWindowView"
|
x:Class="Needlework.Net.Views.MainWindow.MainWindowView"
|
||||||
x:DataType="vm:MainWindowViewModel"
|
x:DataType="vm:MainWindowViewModel"
|
||||||
@@ -132,6 +133,11 @@
|
|||||||
<Setter Property="Margin" Value="0 0 0 8"></Setter>
|
<Setter Property="Margin" Value="0 0 0 8"></Setter>
|
||||||
</Style>
|
</Style>
|
||||||
</ListBox.Styles>
|
</ListBox.Styles>
|
||||||
|
<ListBox.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel/>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ListBox.ItemsPanel>
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ContentControl Content="{Binding}"/>
|
<ContentControl Content="{Binding}"/>
|
||||||
|
|||||||
@@ -28,7 +28,8 @@
|
|||||||
Padding="0"
|
Padding="0"
|
||||||
BorderThickness="1"
|
BorderThickness="1"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
HorizontalContentAlignment="Stretch">
|
HorizontalContentAlignment="Stretch"
|
||||||
|
Command="{Binding DisplayCommand}">
|
||||||
<Border Grid.Column="0"
|
<Border Grid.Column="0"
|
||||||
Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
|
Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
|
||||||
Padding="12">
|
Padding="12">
|
||||||
|
|||||||
Reference in New Issue
Block a user