Merge pull request 'impr/precheck-details-refresh' (#67) from waffle.lord/SPT-AKI-Installer:impr/precheck-details-refresh into master

Reviewed-on: CWX/SPT-AKI-Installer#67
This commit is contained in:
IsWaffle 2024-03-25 22:24:26 +00:00
commit f0f2c1e7aa
5 changed files with 111 additions and 108 deletions

View File

@ -0,0 +1,39 @@
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
using SPTInstaller.CustomControls;
namespace SPTInstaller.Converters;
public class StateSpinnerStateToColorConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value == null)
return null;
if (value is not StatusSpinner.SpinnerState state)
return null;
switch (state)
{
case StatusSpinner.SpinnerState.Pending:
return new SolidColorBrush(Colors.Gray);
case StatusSpinner.SpinnerState.Running:
return new SolidColorBrush(Colors.DodgerBlue);
case StatusSpinner.SpinnerState.OK:
return new SolidColorBrush(Colors.ForestGreen);
case StatusSpinner.SpinnerState.Warning:
return new SolidColorBrush(Colors.Goldenrod);
case StatusSpinner.SpinnerState.Error:
return new SolidColorBrush(Colors.Crimson);
default:
throw new ArgumentOutOfRangeException();
}
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value;
}
}

View File

@ -2,41 +2,60 @@
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:model="using:SPTInstaller.Models"
xmlns:cvt="using:SPTInstaller.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SPTInstaller.CustomControls.PreCheckDetails">
<UserControl.Resources>
<cvt:StateSpinnerStateToColorConverter x:Key="colorConverter"/>
</UserControl.Resources>
<Panel>
<!-- show when nothing is selected -->
<!-- show when nothing is selected -->
<Label Content="Select a Pre-Check to see more info" FontSize="20"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={x:Static StringConverters.IsNullOrEmpty}}"
IsVisible="{Binding HasSelection, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={x:Static BoolConverters.Not}}"
/>
<!-- selected precheck details -->
<Grid RowDefinitions="10, *, Auto, 10" ColumnDefinitions="10, 10, *, 10"
IsVisible="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
>
<Rectangle Grid.Row="1" Grid.Column="1" Width="3" Fill="{Binding BarColor, RelativeSource={RelativeSource AncestorType=UserControl}}" HorizontalAlignment="Left"/>
<StackPanel Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left">
<Label Content="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}}"
FontSize="20"
/>
<Rectangle Height="1" Fill="Gray" Margin="0 10"/>
<TextBlock Text="{Binding Details, RelativeSource={RelativeSource AncestorType=UserControl}}"
TextWrapping="Wrap"
/>
</StackPanel>
<Button Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Classes="yellow"
IsVisible="{Binding ShowAction, RelativeSource={RelativeSource AncestorType=UserControl}}"
CornerRadius="15"
Margin="0 10"
Command="{Binding ActionCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
Content="{Binding ActionButtonText, RelativeSource={RelativeSource AncestorType=UserControl}}"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
HorizontalAlignment="Stretch"
/>
</Grid>
<ItemsControl ItemsSource="{Binding PreChecks}" VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="model:PreCheckBase">
<!-- selected precheck details -->
<Grid RowDefinitions="10, *, Auto, 10" ColumnDefinitions="10, 10, *, 10" VerticalAlignment="Stretch"
IsVisible="{Binding IsSelected}"
>
<Rectangle Grid.Row="1" Grid.Column="1" Width="3" Fill="{Binding State, Converter={StaticResource colorConverter}}"
HorizontalAlignment="Left"/>
<StackPanel Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left">
<Label Content="{Binding Name}"
FontSize="20"
/>
<Rectangle Height="1" Fill="Gray" Margin="0 10"/>
<TextBlock Text="{Binding PreCheckDetails}"
TextWrapping="Wrap"
/>
</StackPanel>
<Button Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Classes="yellow"
IsVisible="{Binding ActionButtonIsVisible}"
CornerRadius="15"
Margin="0 10"
Command="{Binding ActionButtonCommand}"
Content="{Binding ActionButtonText}"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
HorizontalAlignment="Stretch"
/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Panel>
</UserControl>

View File

@ -1,6 +1,7 @@
using System.Windows.Input;
using System.Collections.ObjectModel;
using Avalonia;
using Avalonia.Controls;
using SPTInstaller.Models;
namespace SPTInstaller.CustomControls;
@ -11,57 +12,21 @@ public partial class PreCheckDetails : UserControl
InitializeComponent();
}
public static readonly StyledProperty<string> PreCheckNameProperty =
AvaloniaProperty.Register<PreCheckDetails, string>(nameof(PreCheckName));
public static readonly StyledProperty<ObservableCollection<PreCheckBase>> PreChecksProperty =
AvaloniaProperty.Register<PreCheckDetails, ObservableCollection<PreCheckBase>>(nameof(PreChecks));
public string PreCheckName
public ObservableCollection<PreCheckBase> PreChecks
{
get => GetValue(PreCheckNameProperty);
set => SetValue(PreCheckNameProperty, value);
get => GetValue(PreChecksProperty);
set => SetValue(PreChecksProperty, value);
}
public static readonly StyledProperty<string> DetailsProperty =
AvaloniaProperty.Register<PreCheckDetails, string>(nameof(Details));
public static readonly StyledProperty<bool> HasSelectionProperty =
AvaloniaProperty.Register<PreCheckDetails, bool>(nameof(HasSelection));
public string Details
public bool HasSelection
{
get => GetValue(DetailsProperty);
set => SetValue(DetailsProperty, value);
}
public static readonly StyledProperty<string> ActionButtonTextProperty =
AvaloniaProperty.Register<PreCheckDetails, string>(nameof(ActionButtonText));
public string ActionButtonText
{
get => GetValue(ActionButtonTextProperty);
set => SetValue(ActionButtonTextProperty, value);
}
public static readonly StyledProperty<ICommand> ActionCommandProperty =
AvaloniaProperty.Register<PreCheckDetails, ICommand>(nameof(ActionCommand));
public ICommand ActionCommand
{
get => GetValue(ActionCommandProperty);
set => SetValue(ActionCommandProperty, value);
}
public static readonly StyledProperty<bool> ShowActionProperty =
AvaloniaProperty.Register<PreCheckDetails, bool>(nameof(ShowAction));
public bool ShowAction
{
get => GetValue(ShowActionProperty);
set => SetValue(ShowActionProperty, value);
}
public static readonly StyledProperty<string> BarColorProperty =
AvaloniaProperty.Register<PreCheckDetails, string>(nameof(BarColor));
public string BarColor
{
get => GetValue(BarColorProperty);
set => SetValue(BarColorProperty, value);
get => GetValue(HasSelectionProperty);
set => SetValue(HasSelectionProperty, value);
}
}

View File

@ -19,7 +19,13 @@ namespace SPTInstaller.ViewModels;
public class PreChecksViewModel : ViewModelBase
{
public PreCheckDetailInfo SelectedPreCheck { get; set; } = new();
private bool _hasPreCheckSelected;
public bool HasPreCheckSelected
{
get => _hasPreCheckSelected;
set => this.RaiseAndSetIfChanged(ref _hasPreCheckSelected, value);
}
public ObservableCollection<PreCheckBase> PreChecks { get; set; } = new(ServiceHelper.GetAll<PreCheckBase>());
@ -202,30 +208,8 @@ public class PreChecksViewModel : ViewModelBase
if (check.Id == precheck.Id)
{
precheck.IsSelected = true;
SelectedPreCheck.Name = precheck.Name;
SelectedPreCheck.Details = precheck.PreCheckDetails;
SelectedPreCheck.ActionButtonText = precheck.ActionButtonText;
SelectedPreCheck.ActionButtonCommand = precheck.ActionButtonCommand;
SelectedPreCheck.ShowActionButton = precheck.ActionButtonIsVisible;
switch (precheck.State)
{
case StatusSpinner.SpinnerState.Pending:
SelectedPreCheck.BarColor = "gray";
break;
case StatusSpinner.SpinnerState.Running:
SelectedPreCheck.BarColor = "dodgerblue";
break;
case StatusSpinner.SpinnerState.OK:
SelectedPreCheck.BarColor = "forestgreen";
break;
case StatusSpinner.SpinnerState.Warning:
SelectedPreCheck.BarColor = "gold";
break;
case StatusSpinner.SpinnerState.Error:
SelectedPreCheck.BarColor = "red";
break;
}
HasPreCheckSelected = true;
continue;
}

View File

@ -20,14 +20,10 @@
/>
<!-- selected precheck details grid -->
<cc:PreCheckDetails Grid.Row="2" Grid.Column="1"
PreCheckName="{Binding SelectedPreCheck.Name}"
Details="{Binding SelectedPreCheck.Details}"
ActionButtonText="{Binding SelectedPreCheck.ActionButtonText}"
ActionCommand="{Binding SelectedPreCheck.ActionButtonCommand}"
ShowAction="{Binding SelectedPreCheck.ShowActionButton}"
BarColor="{Binding SelectedPreCheck.BarColor}"
/>
<cc:PreCheckDetails Grid.Row="2" Grid.Column="1"
PreChecks="{Binding PreChecks}"
HasSelection="{Binding HasPreCheckSelected}"
/>
<!-- info card vertical separator -->
<Rectangle Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" VerticalAlignment="Stretch"