176 lines
6.2 KiB
C#
176 lines
6.2 KiB
C#
using System.Globalization;
|
|
|
|
namespace IronServices.Maui.Controls;
|
|
|
|
/// <summary>
|
|
/// Converts an integer to a boolean (true if greater than zero).
|
|
/// </summary>
|
|
public class IsGreaterThanZeroConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> value is int i && i > 0;
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a string to a boolean (true if not null or empty).
|
|
/// </summary>
|
|
public class StringToBoolConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> !string.IsNullOrEmpty(value as string);
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inverts a boolean value.
|
|
/// </summary>
|
|
public class InvertedBoolConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> value is bool b && !b;
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> value is bool b && !b;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts JourneyDisplayStatus or StepDisplayStatus to a Color.
|
|
/// </summary>
|
|
public class StatusToColorConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
return value switch
|
|
{
|
|
JourneyDisplayStatus.InProgress => Colors.Blue,
|
|
JourneyDisplayStatus.Completed => Colors.Green,
|
|
JourneyDisplayStatus.Failed => Colors.Red,
|
|
JourneyDisplayStatus.Abandoned => Colors.Gray,
|
|
StepDisplayStatus.InProgress => Colors.Blue,
|
|
StepDisplayStatus.Completed => Colors.Green,
|
|
StepDisplayStatus.Failed => Colors.Red,
|
|
StepDisplayStatus.Skipped => Colors.Gray,
|
|
_ => Colors.Gray
|
|
};
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts nesting level to a left margin for indentation.
|
|
/// </summary>
|
|
public class NestingLevelToMarginConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is int level)
|
|
return new Thickness(level * 20, 0, 0, 0);
|
|
return new Thickness(0);
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts JourneyViewMode to a boolean for visibility binding.
|
|
/// Parameter should be the target mode (e.g., "Timeline", "Tree", "Flow").
|
|
/// </summary>
|
|
public class ViewModeToVisibilityConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is JourneyViewMode mode && parameter is string targetMode)
|
|
{
|
|
return mode.ToString().Equals(targetMode, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts JourneyViewMode to a background color for tab-style buttons.
|
|
/// Returns Primary color when selected, Transparent when not.
|
|
/// </summary>
|
|
public class ViewModeToBackgroundConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is JourneyViewMode mode && parameter is string targetMode)
|
|
{
|
|
var isSelected = mode.ToString().Equals(targetMode, StringComparison.OrdinalIgnoreCase);
|
|
return isSelected ? Color.FromArgb("#512BD4") : Colors.Transparent;
|
|
}
|
|
return Colors.Transparent;
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts JourneyViewMode to a text color for tab-style buttons.
|
|
/// Returns White when selected, Primary when not.
|
|
/// </summary>
|
|
public class ViewModeToTextColorConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is JourneyViewMode mode && parameter is string targetMode)
|
|
{
|
|
var isSelected = mode.ToString().Equals(targetMode, StringComparison.OrdinalIgnoreCase);
|
|
return isSelected ? Colors.White : Color.FromArgb("#512BD4");
|
|
}
|
|
return Color.FromArgb("#512BD4");
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a dictionary to a formatted string for display.
|
|
/// </summary>
|
|
public class DictionaryToStringConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is Dictionary<string, object> dict && dict.Count > 0)
|
|
{
|
|
return string.Join("\n", dict.Select(kvp => $"{kvp.Key}: {kvp.Value}"));
|
|
}
|
|
return "No data";
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a collection count to visibility (visible if count > 0).
|
|
/// </summary>
|
|
public class CountToVisibilityConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is int count)
|
|
return count > 0;
|
|
if (value is System.Collections.ICollection collection)
|
|
return collection.Count > 0;
|
|
return false;
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|