mirror of
https://github.com/4sval/FModel.git
synced 2026-03-21 17:24:26 -05:00
history ui done
This commit is contained in:
parent
51575d1025
commit
7e35306b01
|
|
@ -21,7 +21,9 @@ public static class Constants
|
|||
public const string BLUE = "#528BCC";
|
||||
|
||||
public const string ISSUE_LINK = "https://github.com/4sval/FModel/discussions/categories/q-a";
|
||||
public const string COMMITS_LINK = "https://api.github.com/repos/4sval/FModel/commits";
|
||||
public const string GH_REPO = "https://api.github.com/repos/4sval/FModel";
|
||||
public const string GH_COMMITS_HISTORY = GH_REPO + "/commits";
|
||||
public const string GH_RELEASES = GH_REPO + "/releases";
|
||||
public const string DONATE_LINK = "https://fmodel.app/donate";
|
||||
public const string DISCORD_LINK = "https://fmodel.app/discord";
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class FModelApiEndpoint : AbstractApiProvider
|
|||
|
||||
public async Task<GitHubCommit[]> GetGitHubCommitHistoryAsync(string branch = "dev", int page = 1, int limit = 20)
|
||||
{
|
||||
var request = new FRestRequest(Constants.COMMITS_LINK);
|
||||
var request = new FRestRequest(Constants.GH_COMMITS_HISTORY);
|
||||
request.AddParameter("sha", branch);
|
||||
request.AddParameter("page", page);
|
||||
request.AddParameter("per_page", limit);
|
||||
|
|
@ -43,6 +43,13 @@ public class FModelApiEndpoint : AbstractApiProvider
|
|||
return response.Data;
|
||||
}
|
||||
|
||||
public async Task<GitHubRelease> GetGitHubReleaseAsync(string tag)
|
||||
{
|
||||
var request = new FRestRequest($"{Constants.GH_RELEASES}/tags/{tag}");
|
||||
var response = await _client.ExecuteAsync<GitHubRelease>(request).ConfigureAwait(false);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public async Task<News> GetNewsAsync(CancellationToken token, string game)
|
||||
{
|
||||
var request = new FRestRequest($"https://api.fmodel.app/v1/news/{Constants.APP_VERSION}");
|
||||
|
|
|
|||
|
|
@ -4,16 +4,44 @@ using System.Diagnostics;
|
|||
using CUE4Parse.UE4.Versions;
|
||||
using FModel.Creator;
|
||||
using FModel.Extensions;
|
||||
using FModel.Framework;
|
||||
using SkiaSharp;
|
||||
using J = Newtonsoft.Json.JsonPropertyAttribute;
|
||||
|
||||
namespace FModel.ViewModels.ApiEndpoints.Models;
|
||||
|
||||
public class GitHubCommit
|
||||
public class GitHubRelease
|
||||
{
|
||||
[J("assets")] public GitHubAsset[] Assets { get; private set; }
|
||||
}
|
||||
|
||||
public class GitHubAsset
|
||||
{
|
||||
[J("name")] public string Name { get; private set; }
|
||||
[J("size")] public int Size { get; private set; }
|
||||
[J("download_count")] public int DownloadCount { get; private set; }
|
||||
[J("browser_download_url")] public string BrowserDownloadUrl { get; private set; }
|
||||
}
|
||||
|
||||
public class GitHubCommit : ViewModel
|
||||
{
|
||||
[J("sha")] public string Sha { get; private set; }
|
||||
[J("commit")] public Commit Commit { get; private set; }
|
||||
[J("author")] public Author Author { get; private set; }
|
||||
|
||||
private GitHubAsset _asset;
|
||||
public GitHubAsset Asset
|
||||
{
|
||||
get => _asset;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _asset, value);
|
||||
RaisePropertyChanged(nameof(IsDownloadable));
|
||||
}
|
||||
}
|
||||
|
||||
public string ShortSha => Sha[..7];
|
||||
public bool IsDownloadable => Asset != null;
|
||||
}
|
||||
|
||||
public class Commit
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using FModel.Extensions;
|
||||
using FModel.Framework;
|
||||
using FModel.Services;
|
||||
using FModel.ViewModels.ApiEndpoints.Models;
|
||||
using FModel.Views.Resources.Converters;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace FModel.ViewModels;
|
||||
|
||||
public class UpdateViewModel : ViewModel
|
||||
{
|
||||
private ApiEndpointViewModel _apiEndpointView => ApplicationService.ApiEndpointView;
|
||||
|
||||
public RangeObservableCollection<GitHubCommit> Commits { get; }
|
||||
public ICollectionView CommitsView { get; }
|
||||
|
||||
|
|
@ -24,6 +30,29 @@ public class UpdateViewModel : ViewModel
|
|||
|
||||
public async Task Load()
|
||||
{
|
||||
Commits.AddRange(await ApplicationService.ApiEndpointView.FModelApi.GetGitHubCommitHistoryAsync());
|
||||
#if DEBUG
|
||||
Commits.AddRange(JsonConvert.DeserializeObject<GitHubCommit[]>(await File.ReadAllTextAsync(@"C:\Users\valen\Downloads\history.json")));
|
||||
#else
|
||||
Commits.AddRange(await _apiEndpointView.FModelApi.GetGitHubCommitHistoryAsync());
|
||||
#endif
|
||||
_ = PostLoad();
|
||||
}
|
||||
|
||||
private async Task PostLoad()
|
||||
{
|
||||
#if DEBUG
|
||||
var qa = JsonConvert.DeserializeObject<GitHubRelease>(await File.ReadAllTextAsync(@"C:\Users\valen\Downloads\qa.json"));
|
||||
#else
|
||||
var qa = await _apiEndpointView.FModelApi.GetGitHubReleaseAsync("qa");
|
||||
#endif
|
||||
foreach (var asset in qa.Assets)
|
||||
{
|
||||
var commitSha = asset.Name.SubstringBeforeLast(".zip");
|
||||
var commit = Commits.FirstOrDefault(x => x.Sha == commitSha);
|
||||
if (commit != null)
|
||||
{
|
||||
commit.Asset = asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
|
||||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI">
|
||||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
|
||||
xmlns:controls="clr-namespace:FModel.Views.Resources.Controls">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
|
@ -10,17 +11,15 @@
|
|||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border BorderThickness="1" CornerRadius="0.5"
|
||||
BorderBrush="{DynamicResource {x:Static adonisUi:Brushes.Layer4BackgroundBrush}}">
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Border Grid.Column="0" Background="{DynamicResource {x:Static adonisUi:Brushes.Layer2BackgroundBrush}}"
|
||||
BorderBrush="{DynamicResource {x:Static adonisUi:Brushes.Layer2HighlightBorderBrush}}"
|
||||
BorderThickness="1" Padding="5">
|
||||
<Grid>
|
||||
<Grid Grid.Column="0" Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
|
|
@ -65,17 +64,20 @@
|
|||
</TextBlock>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Button Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" ToolTip="Download" Padding="4"
|
||||
Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarButton}}">
|
||||
<Viewbox Width="16" Height="16" HorizontalAlignment="Center">
|
||||
<Canvas Width="24" Height="24">
|
||||
<Path Fill="{DynamicResource {x:Static adonisUi:Brushes.DisabledForegroundBrush}}"
|
||||
Data="{StaticResource ArchiveIcon}" />
|
||||
</Canvas>
|
||||
</Viewbox>
|
||||
</Button>
|
||||
</Grid>
|
||||
<controls:CommitDownloaderControl Grid.Column="1" CommitAsset="{Binding Asset}">
|
||||
<controls:CommitDownloaderControl.Style>
|
||||
<Style TargetType="controls:CommitDownloaderControl">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsDownloadable}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</controls:CommitDownloaderControl.Style>
|
||||
</controls:CommitDownloaderControl>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
|
||||
|
|
|
|||
53
FModel/Views/Resources/Controls/CommitDownloaderControl.xaml
Normal file
53
FModel/Views/Resources/Controls/CommitDownloaderControl.xaml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<UserControl x:Class="FModel.Views.Resources.Controls.CommitDownloaderControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
|
||||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="../Resources.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="15" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Viewbox Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<Canvas Width="16" Height="16">
|
||||
<Path Fill="{DynamicResource {x:Static adonisUi:Brushes.DisabledForegroundBrush}}"
|
||||
Data="{StaticResource ArchiveIcon}" />
|
||||
</Canvas>
|
||||
</Viewbox>
|
||||
<StackPanel Grid.Column="2">
|
||||
<TextBlock Text="Size" FontSize="10" />
|
||||
<TextBlock FontSize="10" Text="{Binding CommitAsset.Size, Converter={x:Static converters:SizeToStringConverter.Instance}, RelativeSource={RelativeSource AncestorType=UserControl}}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<Button Grid.Column="2" Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarButton}}" ToolTip="Download"
|
||||
Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}"
|
||||
Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}">
|
||||
<Viewbox Width="16" Height="16" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<Canvas Width="16" Height="16">
|
||||
<Path Fill="{DynamicResource {x:Static adonisUi:Brushes.DisabledForegroundBrush}}"
|
||||
Data="M2.75 14A1.75 1.75 0 0 1 1 12.25v-2.5a.75.75 0 0 1 1.5 0v2.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25v-2.5a.75.75 0 0 1 1.5 0v2.5A1.75 1.75 0 0 1 13.25 14Z" />
|
||||
<Path Fill="{DynamicResource {x:Static adonisUi:Brushes.DisabledForegroundBrush}}"
|
||||
Data="M11.78 4.72a.749.749 0 1 1-1.06 1.06L8.75 3.811V9.5a.75.75 0 0 1-1.5 0V3.811L5.28 5.78a.749.749 0 1 1-1.06-1.06l3.25-3.25a.749.749 0 0 1 1.06 0l3.25 3.25Z" />
|
||||
</Canvas>
|
||||
</Viewbox>
|
||||
</Button>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using FModel.ViewModels.ApiEndpoints.Models;
|
||||
|
||||
namespace FModel.Views.Resources.Controls;
|
||||
|
||||
public partial class CommitDownloaderControl : UserControl
|
||||
{
|
||||
public CommitDownloaderControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CommitAssetProperty =
|
||||
DependencyProperty.Register("CommitAsset", typeof(GitHubAsset), typeof(CommitDownloaderControl), new PropertyMetadata(null));
|
||||
|
||||
public GitHubAsset CommitAsset
|
||||
{
|
||||
get { return (GitHubAsset)GetValue(CommitAssetProperty); }
|
||||
set { SetValue(CommitAssetProperty, value); }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2,11 +2,10 @@
|
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
|
||||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
|
||||
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
|
||||
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
|
||||
xmlns:controls="clr-namespace:FModel.Views.Resources.Controls"
|
||||
MinHeight="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={converters:RatioConverter}, ConverterParameter='0.20'}"
|
||||
MaxHeight="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={converters:RatioConverter}, ConverterParameter='0.80'}"
|
||||
Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.50'}"
|
||||
Loaded="OnLoaded">
|
||||
<adonisControls:AdonisWindow.Style>
|
||||
|
|
@ -31,36 +30,45 @@
|
|||
<Button Grid.Row="0">Download Latest</Button>
|
||||
<Separator Grid.Row="1" Style="{StaticResource CustomSeparator}" Tag="History" />
|
||||
|
||||
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<ItemsControl ItemsSource="{Binding CommitsView}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel Orientation="Vertical" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock FontSize="16"
|
||||
Text="{Binding Name, StringFormat='Commits on {0:MMM d, yyyy}'}"
|
||||
Foreground="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}"/>
|
||||
</DataTemplate>
|
||||
</GroupStyle.HeaderTemplate>
|
||||
<GroupStyle.Panel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Vertical" />
|
||||
</ItemsPanelTemplate>
|
||||
</GroupStyle.Panel>
|
||||
</GroupStyle>
|
||||
</ItemsControl.GroupStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<controls:CommitControl Margin="1" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
<ItemsControl Grid.Row="2" ItemsSource="{Binding CommitsView}">
|
||||
<ItemsControl.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.ContainerStyle>
|
||||
<Style TargetType="GroupItem">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="GroupItem">
|
||||
<GroupBox adonisExtensions:LayerExtension.Layer="3"
|
||||
Header="{Binding Name}"
|
||||
HeaderStringFormat="Commits on {0:MMM d, yyyy}"
|
||||
Margin="0 0 0 5">
|
||||
<ItemsPresenter />
|
||||
</GroupBox>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</GroupStyle.ContainerStyle>
|
||||
<GroupStyle.Panel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Vertical" />
|
||||
</ItemsPanelTemplate>
|
||||
</GroupStyle.Panel>
|
||||
</GroupStyle>
|
||||
</ItemsControl.GroupStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<controls:CommitControl Margin="0 0 0 1" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
<ItemsControl.Template>
|
||||
<ControlTemplate TargetType="ItemsControl">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<ItemsPresenter />
|
||||
</ScrollViewer>
|
||||
</ControlTemplate>
|
||||
</ItemsControl.Template>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</adonisControls:AdonisWindow>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user