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:
commit
f0f2c1e7aa
39
SPTInstaller/Converters/StateSpinnerStateToColorConverter.cs
Normal file
39
SPTInstaller/Converters/StateSpinnerStateToColorConverter.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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}}"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ItemsControl ItemsSource="{Binding PreChecks}" VerticalAlignment="Stretch">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<Grid />
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate DataType="model:PreCheckBase">
|
||||||
<!-- selected precheck details -->
|
<!-- selected precheck details -->
|
||||||
<Grid RowDefinitions="10, *, Auto, 10" ColumnDefinitions="10, 10, *, 10"
|
<Grid RowDefinitions="10, *, Auto, 10" ColumnDefinitions="10, 10, *, 10" VerticalAlignment="Stretch"
|
||||||
IsVisible="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
IsVisible="{Binding IsSelected}"
|
||||||
>
|
>
|
||||||
<Rectangle Grid.Row="1" Grid.Column="1" Width="3" Fill="{Binding BarColor, RelativeSource={RelativeSource AncestorType=UserControl}}" HorizontalAlignment="Left"/>
|
<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">
|
<StackPanel Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left">
|
||||||
<Label Content="{Binding PreCheckName, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
<Label Content="{Binding Name}"
|
||||||
FontSize="20"
|
FontSize="20"
|
||||||
/>
|
/>
|
||||||
<Rectangle Height="1" Fill="Gray" Margin="0 10"/>
|
<Rectangle Height="1" Fill="Gray" Margin="0 10"/>
|
||||||
<TextBlock Text="{Binding Details, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
<TextBlock Text="{Binding PreCheckDetails}"
|
||||||
TextWrapping="Wrap"
|
TextWrapping="Wrap"
|
||||||
/>
|
/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<Button Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Classes="yellow"
|
<Button Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Classes="yellow"
|
||||||
IsVisible="{Binding ShowAction, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
IsVisible="{Binding ActionButtonIsVisible}"
|
||||||
CornerRadius="15"
|
CornerRadius="15"
|
||||||
Margin="0 10"
|
Margin="0 10"
|
||||||
Command="{Binding ActionCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
Command="{Binding ActionButtonCommand}"
|
||||||
Content="{Binding ActionButtonText, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
Content="{Binding ActionButtonText}"
|
||||||
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
|
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
</Panel>
|
</Panel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,8 @@
|
|||||||
|
|
||||||
<!-- 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 -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user