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

View File

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

View File

@ -19,7 +19,13 @@ namespace SPTInstaller.ViewModels;
public class PreChecksViewModel : ViewModelBase 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>()); public ObservableCollection<PreCheckBase> PreChecks { get; set; } = new(ServiceHelper.GetAll<PreCheckBase>());
@ -202,30 +208,8 @@ public class PreChecksViewModel : ViewModelBase
if (check.Id == precheck.Id) if (check.Id == precheck.Id)
{ {
precheck.IsSelected = true; 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) HasPreCheckSelected = true;
{
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;
}
continue; continue;
} }

View File

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