mirror of
https://github.com/BlossomiShymae/Needlework.Net.git
synced 2025-12-06 02:00:47 +01:00
fix: change schemas list to prevent layout cycle
This commit is contained in:
@@ -79,6 +79,9 @@
|
||||
<Compile Update="Views\Pages\Endpoints\PluginView.axaml.cs">
|
||||
<DependentUpon>PluginView.axaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Views\Pages\Schemas\SchemaSearchDetailsView.axaml.cs">
|
||||
<DependentUpon>SchemaSearchDetailsView.axaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Views\Pages\WebSocket\WebsocketView.axaml.cs">
|
||||
<DependentUpon>WebSocketView.axaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -87,4 +90,8 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="Assets\Users\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="ViewModels\Pages\Schemas\SchemaSearchDetailsViewModel.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -70,7 +70,7 @@ class Program
|
||||
var locator = new ViewLocator();
|
||||
// MAIN WINDOW
|
||||
locator.Register<NotificationViewModel>(() => new NotificationView());
|
||||
locator.Register<SchemaSearchDetailsViewModel>(() => new SchemaSearchDetailsView());
|
||||
locator.Register<ViewModels.MainWindow.SchemaSearchDetailsViewModel>(() => new Views.MainWindow.SchemaSearchDetailsView());
|
||||
locator.Register<SchemaViewModel>(() => new SchemaView());
|
||||
// ABOUT
|
||||
locator.Register<AboutViewModel>(() => new AboutView());
|
||||
@@ -89,7 +89,7 @@ class Program
|
||||
locator.Register<LibraryViewModel>(() => new LibraryView());
|
||||
// SCHEMAS
|
||||
locator.Register<SchemasViewModel>(() => new SchemasView());
|
||||
locator.Register<SchemaItemViewModel>(() => new SchemaItemView());
|
||||
locator.Register<ViewModels.Pages.Schemas.SchemaSearchDetailsViewModel>(() => new Views.Pages.Schemas.SchemaSearchDetailsView());
|
||||
// WEBSOCKET
|
||||
locator.Register<WebSocketViewModel>(() => new WebSocketView());
|
||||
locator.Register<EventViewModel>(() => new EventView());
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Needlework.Net.ViewModels.Pages.Endpoints;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Needlework.Net.ViewModels.Pages.Schemas
|
||||
{
|
||||
public partial class SchemaItemViewModel : ObservableObject
|
||||
{
|
||||
public SchemaItemViewModel(PropertyClassViewModel vm)
|
||||
{
|
||||
Id = vm.Id;
|
||||
PropertyFields = vm.PropertyFields;
|
||||
PropertyEnums = vm.PropertyEnums;
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
|
||||
public List<PropertyFieldViewModel> PropertyFields { get; } = [];
|
||||
|
||||
public List<PropertyEnumViewModel> PropertyEnums { get; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Needlework.Net.ViewModels.Pages.Endpoints;
|
||||
using System;
|
||||
|
||||
namespace Needlework.Net.ViewModels.Pages.Schemas
|
||||
{
|
||||
public partial class SchemaSearchDetailsViewModel : ObservableObject
|
||||
{
|
||||
public SchemaSearchDetailsViewModel(Tab tab, PropertyClassViewModel vm)
|
||||
{
|
||||
Tab = tab;
|
||||
Id = vm.Id;
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
|
||||
public Tab Tab { get; }
|
||||
|
||||
public string Document => Tab switch
|
||||
{
|
||||
Tab.LCU => "LCU",
|
||||
Tab.GameClient => "Game Client",
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using DebounceThrottle;
|
||||
using Needlework.Net.Helpers;
|
||||
using Needlework.Net.Models;
|
||||
using Needlework.Net.ViewModels.Pages.Endpoints;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -18,9 +17,7 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
|
||||
|
||||
private readonly DocumentService _documentService;
|
||||
|
||||
public record SchemaTab(string Key, Tab Tab);
|
||||
|
||||
private List<SchemaTab> _schemas = [];
|
||||
private List<SchemaSearchDetailsViewModel> _schemas = [];
|
||||
|
||||
public SchemasViewModel(DocumentService documentService) : base("Schemas", "fa-solid fa-file-lines", -100)
|
||||
{
|
||||
@@ -34,7 +31,7 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
|
||||
private string? _search;
|
||||
|
||||
[ObservableProperty]
|
||||
private List<SchemaItemViewModel> _schemaItems = [];
|
||||
private List<SchemaSearchDetailsViewModel> _schemaItems = [];
|
||||
|
||||
[ObservableProperty]
|
||||
private Vector _offset = new();
|
||||
@@ -43,40 +40,20 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
|
||||
{
|
||||
_debounceDispatcher.Debounce(() =>
|
||||
{
|
||||
Task.Run(async () =>
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
var lcuSchemaDocument = await _documentService.GetLcuSchemaDocumentAsync();
|
||||
var lolClientDocument = await _documentService.GetLolClientDocumentAsync();
|
||||
if (string.IsNullOrEmpty(value))
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
SchemaItems = _schemas.Select((schema) => ToSchemaItemViewModel(schema, lcuSchemaDocument, lolClientDocument))
|
||||
.ToList();
|
||||
});
|
||||
return;
|
||||
}
|
||||
var items = _schemas.Where(schema => schema.Key.Contains(value, StringComparison.OrdinalIgnoreCase))
|
||||
.Select((schema) => ToSchemaItemViewModel(schema, lcuSchemaDocument, lolClientDocument))
|
||||
.ToList();
|
||||
Dispatcher.UIThread.Invoke(() => { SchemaItems = items; });
|
||||
});
|
||||
SchemaItems = _schemas.ToList();
|
||||
});
|
||||
return;
|
||||
}
|
||||
var items = _schemas.Where(schema => schema.Id.Contains(value, StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
Dispatcher.UIThread.Invoke(() => { SchemaItems = items; });
|
||||
});
|
||||
}
|
||||
|
||||
private SchemaItemViewModel ToSchemaItemViewModel(SchemaTab schema, Document lcuSchemaDocument, Document lolClientDocument)
|
||||
{
|
||||
var document = schema.Tab switch
|
||||
{
|
||||
Tab.LCU => lcuSchemaDocument.OpenApiDocument,
|
||||
Tab.GameClient => lolClientDocument.OpenApiDocument,
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
var vm = OpenApiHelpers.WalkSchema(document.Components.Schemas[schema.Key], document);
|
||||
return new SchemaItemViewModel(vm);
|
||||
|
||||
}
|
||||
|
||||
public override async Task InitializeAsync()
|
||||
{
|
||||
var lcuSchemaDocument = await _documentService.GetLcuSchemaDocumentAsync();
|
||||
@@ -84,13 +61,11 @@ namespace Needlework.Net.ViewModels.Pages.Schemas
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
var schemas = Enumerable.Concat(
|
||||
lcuSchemaDocument.OpenApiDocument.Components.Schemas.Keys.Select(key => new SchemaTab(key, Tab.LCU)),
|
||||
lolClientDocument.OpenApiDocument.Components.Schemas.Keys.Select(key => new SchemaTab(key, Tab.GameClient))
|
||||
lcuSchemaDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.LCU, OpenApiHelpers.WalkSchema(schema, lcuSchemaDocument.OpenApiDocument))),
|
||||
lolClientDocument.OpenApiDocument.Components.Schemas.Values.Select(schema => new SchemaSearchDetailsViewModel(Tab.GameClient, OpenApiHelpers.WalkSchema(schema, lolClientDocument.OpenApiDocument)))
|
||||
).ToList();
|
||||
_schemas = schemas;
|
||||
SchemaItems = schemas
|
||||
.Select((schema) => ToSchemaItemViewModel(schema, lcuSchemaDocument, lolClientDocument))
|
||||
.ToList();
|
||||
SchemaItems = schemas.ToList();
|
||||
IsBusy = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<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:vm="using:Needlework.Net.ViewModels.Pages.Schemas"
|
||||
xmlns:controls="using:Needlework.Net.Controls"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Needlework.Net.Views.Pages.Schemas.SchemaItemView"
|
||||
x:DataType="vm:SchemaItemViewModel">
|
||||
<UserControl.Styles>
|
||||
<Style Selector="DataGrid">
|
||||
<Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource ControlElevationBorderBrush}"/>
|
||||
</Style>
|
||||
<Style Selector="DataGridColumnHeader TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
|
||||
</Style>
|
||||
<Style Selector="DataGridRow DataGridCell">
|
||||
<Setter Property="FontSize" Value="12"></Setter>
|
||||
</Style>
|
||||
<Style Selector="DataGridRow">
|
||||
<Setter Property="Margin" Value="0 0 0 4"></Setter>
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
<Border CornerRadius="4"
|
||||
ClipToBounds="True"
|
||||
BorderBrush="{DynamicResource ControlStrokeColorOnAccentTertiaryBrush}"
|
||||
BorderThickness="1">
|
||||
<StackPanel>
|
||||
<Border Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
|
||||
BorderThickness="0 0 0 1"
|
||||
BorderBrush="{DynamicResource ControlStrokeColorOnAccentTertiaryBrush}"
|
||||
Padding="12">
|
||||
<TextBlock FontSize="12"
|
||||
FontWeight="DemiBold"
|
||||
Text="{Binding Id}"/>
|
||||
</Border>
|
||||
<Border Background="{DynamicResource CardBackgroundFillColorSecondaryBrush}"
|
||||
Padding="12"
|
||||
IsVisible="{Binding PropertyFields, Converter={StaticResource EnumerableToVisibilityConverter}}">
|
||||
<DataGrid
|
||||
ItemsSource="{Binding PropertyFields}"
|
||||
AutoGenerateColumns="True"
|
||||
IsReadOnly="True"
|
||||
GridLinesVisibility="Horizontal">
|
||||
</DataGrid>
|
||||
</Border>
|
||||
<Border Background="{DynamicResource CardBackgroundFillColorSecondaryBrush}"
|
||||
Padding="12"
|
||||
IsVisible="{Binding PropertyEnums, Converter={StaticResource EnumerableToVisibilityConverter}}">
|
||||
<DataGrid
|
||||
ItemsSource="{Binding PropertyEnums}"
|
||||
AutoGenerateColumns="True"
|
||||
IsReadOnly="True"
|
||||
GridLinesVisibility="Horizontal">
|
||||
</DataGrid>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,46 @@
|
||||
<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:vm="using:Needlework.Net.ViewModels.Pages.Schemas"
|
||||
xmlns:controls="using:Needlework.Net.Controls"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Needlework.Net.Views.Pages.Schemas.SchemaSearchDetailsView"
|
||||
x:DataType="vm:SchemaSearchDetailsViewModel">
|
||||
<UserControl.Styles>
|
||||
<Style Selector="DataGrid">
|
||||
<Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource ControlElevationBorderBrush}"/>
|
||||
</Style>
|
||||
<Style Selector="DataGridColumnHeader TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
|
||||
</Style>
|
||||
<Style Selector="DataGridRow DataGridCell">
|
||||
<Setter Property="FontSize" Value="12"></Setter>
|
||||
</Style>
|
||||
<Style Selector="DataGridRow">
|
||||
<Setter Property="Margin" Value="0 0 0 4"></Setter>
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
<Button CornerRadius="4"
|
||||
ClipToBounds="True"
|
||||
BorderBrush="{DynamicResource ControlStrokeColorOnAccentTertiaryBrush}"
|
||||
Background="Transparent"
|
||||
Padding="0"
|
||||
BorderThickness="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch">
|
||||
<Border Grid.Column="0"
|
||||
Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
|
||||
Padding="12">
|
||||
<StackPanel>
|
||||
<TextBlock FontSize="12"
|
||||
FontWeight="DemiBold"
|
||||
Text="{Binding Id}"/>
|
||||
<TextBlock FontSize="12"
|
||||
Text="{Binding Document}"
|
||||
Theme="{StaticResource CaptionTextBlockStyle}"
|
||||
Foreground="{DynamicResource AccentTextFillColorPrimaryBrush}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Button>
|
||||
</UserControl>
|
||||
@@ -2,9 +2,9 @@ using Avalonia.Controls;
|
||||
|
||||
namespace Needlework.Net.Views.Pages.Schemas;
|
||||
|
||||
public partial class SchemaItemView : UserControl
|
||||
public partial class SchemaSearchDetailsView : UserControl
|
||||
{
|
||||
public SchemaItemView()
|
||||
public SchemaSearchDetailsView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@@ -23,13 +23,13 @@
|
||||
Offset="{Binding Offset, Mode=TwoWay}">
|
||||
<ItemsControl ItemsSource="{Binding SchemaItems}">
|
||||
<ItemsControl.Styles>
|
||||
<Style Selector="views|SchemaItemView">
|
||||
<Setter Property="Margin" Value="0 0 0 8"/>
|
||||
<Style Selector="views|SchemaSearchDetailsView">
|
||||
<Setter Property="Margin" Value="0 0 0 8" />
|
||||
</Style>
|
||||
</ItemsControl.Styles>
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel/>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
|
||||
Reference in New Issue
Block a user