Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Converters/StatisticsConverters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;

namespace ScriptRunner.GUI.Converters;

public class IntensityToColorConverter : IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values.Count > 0 && values[0] is int intensity)
{
return intensity switch
{
0 => Color.Parse("#161b22"),
1 => Color.Parse("#0e4429"),
2 => Color.Parse("#006d32"),
3 => Color.Parse("#26a641"),
4 => Color.Parse("#39d353"),
_ => Color.Parse("#161b22")
};
}
return Color.Parse("#161b22");
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class IntensityConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is int intensity && parameter is string paramStr && int.TryParse(paramStr, out var targetIntensity))
{
return intensity == targetIntensity;
}
return false;
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class WeekToPositionConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is int weekIndex)
{
return weekIndex * 14; // 12px width + 2px margin
}
return 0;
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class DayToPositionConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is int dayOfWeek)
{
return dayOfWeek * 14; // 12px height + 2px margin
}
return 0;
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class MonthLabelConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string str)
{
var parts = str.Split('|');
return parts.Length > 0 ? parts[0] : "";
}
return "";
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class MonthWidthConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string str)
{
var parts = str.Split('|');
if (parts.Length > 1 && int.TryParse(parts[1], out var weekCount))
{
// Each week is 14px wide (12px cell + 2px margin)
return weekCount * 14;
}
}
return 56; // Default to 4 weeks
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class MonthPositionConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string str)
{
var parts = str.Split('|');
if (parts.Length > 1 && int.TryParse(parts[1], out var weekIndex))
{
return weekIndex * 14; // 12px width + 2px margin
}
}
return 0;
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class IndexToRankConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is int index)
{
return (index + 1).ToString();
}
return "0";
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,23 @@ private IControlRecord CreateControlRecord(ScriptParam p, string? value, int ind
case PromptType.Dropdown:
var delimiterForOptions = p.GetPromptSettings("delimiter", x => x, ",");
var dropdownOptions = p.GetDropdownOptions(delimiterForOptions);
var observableDropdownOptions = new ObservableCollection<DropdownOption>(dropdownOptions);

var searchable = p.GetPromptSettings("searchable", bool.Parse, false);
var optionsGeneratorCommand = p.GetPromptSettings("optionsGeneratorCommand", out var optionsGeneratorCommandText) ? optionsGeneratorCommandText : null;

// Find selected item by matching value
DropdownOption? selectedOption = null;
if (!string.IsNullOrWhiteSpace(value))
{
selectedOption = observableDropdownOptions.FirstOrDefault(opt => opt.Value == value);
if (selectedOption == null && string.IsNullOrWhiteSpace(optionsGeneratorCommand) == false)
selectedOption = dropdownOptions.FirstOrDefault(opt => opt.Value == value);
if (selectedOption == null)
{
// Add the value as a temporary option if not found and generator is available
selectedOption = new DropdownOption(value);
observableDropdownOptions.Add(selectedOption);
// Add the value as a temporary option, maybe it was available before but not anymore
selectedOption = new DropdownOption(value, value);
dropdownOptions.Add(selectedOption);
}
}

var observableDropdownOptions = new ObservableCollection<DropdownOption>(dropdownOptions);
Control inputControl;

if (searchable)
Expand Down
5 changes: 0 additions & 5 deletions src/ScriptRunner/ScriptRunner.GUI/Themes/StyleClasses.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@
<Style Selector="StackPanel.paramRow NumericUpDown">
<Setter Property="Background" Value="#1e1e1e" />
</Style>

<Style Selector="StackPanel.paramRow views|PasswordBox">
<Setter Property="Background" Value="#1e1e1e" />
</Style>

<Style Selector="StackPanel.paramRow views|SearchableComboBox">
<Setter Property="Background" Value="#1e1e1e" />
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public bool IsRecentListVisible

private bool _isRecentListVisible;

public bool IsStatisticsVisible
{
get => _isStatisticsVisible;
set => this.RaiseAndSetIfChanged(ref _isStatisticsVisible, value);
}

private bool _isStatisticsVisible;

public StatisticsViewModel Statistics { get; private set; }

public bool IsSideBoxVisible => _isSideBoxVisible.Value;

Expand Down Expand Up @@ -229,6 +238,9 @@ public MainWindowViewModel(ParamsPanelFactory paramsPanelFactory, VaultProvider
_vaultProvider = vaultProvider;
this.appUpdater = new GithubUpdater();

// Initialize Statistics ViewModel
Statistics = new StatisticsViewModel(ExecutionLog);

ExecutionLogAction? lastSelected = null;

this.WhenAnyValue(x=>x.SelectedRecentExecution)
Expand All @@ -245,20 +257,30 @@ public MainWindowViewModel(ParamsPanelFactory paramsPanelFactory, VaultProvider
}
});

this.WhenAnyValue(x => x.IsScriptListVisible, x => x.IsRecentListVisible)
.Select((t1, t2) => (t1.Item1 || t1.Item2))
this.WhenAnyValue(x => x.IsScriptListVisible, x => x.IsRecentListVisible, x => x.IsStatisticsVisible)
.Select(t => (t.Item1 || t.Item2 || t.Item3))
.ObserveOn(RxApp.MainThreadScheduler)
.ToProperty(this, x => x.IsSideBoxVisible, out _isSideBoxVisible);

this.WhenAnyValue(x => x.IsScriptListVisible)
.Where(x => x)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(b => IsRecentListVisible = false);
.Subscribe(b => { IsRecentListVisible = false; IsStatisticsVisible = false; });

this.WhenAnyValue(x => x.IsRecentListVisible)
.Where(x => x)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(b => IsScriptListVisible = false);
.Subscribe(b => { IsScriptListVisible = false; IsStatisticsVisible = false; });

this.WhenAnyValue(x => x.IsStatisticsVisible)
.Where(x => x)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(b =>
{
IsScriptListVisible = false;
IsRecentListVisible = false;
Statistics.RefreshStatistics();
});

this.WhenAnyValue(x => x.ActionFilter, x => x.Actions)
.Throttle(TimeSpan.FromMilliseconds(200))
Expand Down
Loading
Loading