diff --git a/NEW/src/Utils/JdeScoping.ConfigManager/ViewModels/Dialogs/DiffPreviewDialogViewModel.cs b/NEW/src/Utils/JdeScoping.ConfigManager/ViewModels/Dialogs/DiffPreviewDialogViewModel.cs new file mode 100644 index 0000000..940d958 --- /dev/null +++ b/NEW/src/Utils/JdeScoping.ConfigManager/ViewModels/Dialogs/DiffPreviewDialogViewModel.cs @@ -0,0 +1,75 @@ +using System.Collections.ObjectModel; +using System.Windows.Input; +using JdeScoping.ConfigManager.Services; + +namespace JdeScoping.ConfigManager.ViewModels.Dialogs; + +/// +/// ViewModel for the diff preview dialog. +/// +public class DiffPreviewDialogViewModel : ViewModelBase +{ + private bool _result; + + public DiffPreviewDialogViewModel(DiffResult diff) + { + ArgumentNullException.ThrowIfNull(diff); + + Lines = new ObservableCollection( + diff.Lines.Select(l => new DiffLineViewModel(l))); + Insertions = diff.Insertions; + Deletions = diff.Deletions; + HasChanges = diff.HasChanges; + + SaveCommand = new RelayCommand(() => { Result = true; RequestClose?.Invoke(); }); + CancelCommand = new RelayCommand(() => { Result = false; RequestClose?.Invoke(); }); + } + + public ObservableCollection Lines { get; } + public int Insertions { get; } + public int Deletions { get; } + public bool HasChanges { get; } + + public bool Result + { + get => _result; + private set => SetProperty(ref _result, value); + } + + public ICommand SaveCommand { get; } + public ICommand CancelCommand { get; } + public Action? RequestClose { get; set; } +} + +/// +/// ViewModel for a single diff line. +/// +public class DiffLineViewModel +{ + public DiffLineViewModel(DiffLine line) + { + OldLineNumber = line.OldLineNumber?.ToString() ?? ""; + NewLineNumber = line.NewLineNumber?.ToString() ?? ""; + Text = line.Text; + Type = line.Type; + Background = line.Type switch + { + DiffLineType.Added => "#1A3DD68C", + DiffLineType.Removed => "#1AFF6B6B", + _ => "Transparent" + }; + BorderColor = line.Type switch + { + DiffLineType.Added => "#3DD68C", + DiffLineType.Removed => "#FF6B6B", + _ => "Transparent" + }; + } + + public string OldLineNumber { get; } + public string NewLineNumber { get; } + public string Text { get; } + public DiffLineType Type { get; } + public string Background { get; } + public string BorderColor { get; } +} diff --git a/NEW/src/Utils/JdeScoping.ConfigManager/ViewModels/Dialogs/ValidationResultsDialogViewModel.cs b/NEW/src/Utils/JdeScoping.ConfigManager/ViewModels/Dialogs/ValidationResultsDialogViewModel.cs new file mode 100644 index 0000000..5432194 --- /dev/null +++ b/NEW/src/Utils/JdeScoping.ConfigManager/ViewModels/Dialogs/ValidationResultsDialogViewModel.cs @@ -0,0 +1,144 @@ +using System.Collections.ObjectModel; +using System.Windows.Input; +using JdeScoping.ConfigManager.Services; + +namespace JdeScoping.ConfigManager.ViewModels.Dialogs; + +/// +/// ViewModel for the validation results dialog. +/// +public class ValidationResultsDialogViewModel : ViewModelBase +{ + /// + /// Initializes a new instance of the class. + /// + /// The validation result for appsettings.json. + /// The validation result for pipelines.json. + public ValidationResultsDialogViewModel(ValidationResult appSettingsResult, ValidationResult pipelinesResult) + { + ArgumentNullException.ThrowIfNull(appSettingsResult); + ArgumentNullException.ThrowIfNull(pipelinesResult); + + var items = new List(); + + foreach (var error in appSettingsResult.Errors) + items.Add(new ValidationItemViewModel(error, "appsettings.json", ValidationItemType.Error)); + foreach (var warning in appSettingsResult.Warnings) + items.Add(new ValidationItemViewModel(warning, "appsettings.json", ValidationItemType.Warning)); + foreach (var error in pipelinesResult.Errors) + items.Add(new ValidationItemViewModel(error, "pipelines.json", ValidationItemType.Error)); + foreach (var warning in pipelinesResult.Warnings) + items.Add(new ValidationItemViewModel(warning, "pipelines.json", ValidationItemType.Warning)); + + Items = new ObservableCollection(items); + ErrorCount = appSettingsResult.Errors.Count + pipelinesResult.Errors.Count; + WarningCount = appSettingsResult.Warnings.Count + pipelinesResult.Warnings.Count; + IsValid = ErrorCount == 0 && WarningCount == 0; + + CloseCommand = new RelayCommand(() => RequestClose?.Invoke()); + } + + /// + /// Gets the collection of validation items to display. + /// + public ObservableCollection Items { get; } + + /// + /// Gets the total count of validation errors. + /// + public int ErrorCount { get; } + + /// + /// Gets the total count of validation warnings. + /// + public int WarningCount { get; } + + /// + /// Gets a value indicating whether all validation passed (no errors or warnings). + /// + public bool IsValid { get; } + + /// + /// Gets the command to close the dialog. + /// + public ICommand CloseCommand { get; } + + /// + /// Gets or sets the action to request closing the dialog. + /// + public Action? RequestClose { get; set; } +} + +/// +/// Specifies the type of validation item. +/// +public enum ValidationItemType +{ + /// + /// A validation error that must be fixed. + /// + Error, + + /// + /// A validation warning that should be reviewed. + /// + Warning +} + +/// +/// ViewModel for a single validation item. +/// +public class ValidationItemViewModel +{ + /// + /// Initializes a new instance of the class. + /// + /// The validation message. + /// The source file name. + /// The type of validation item. + public ValidationItemViewModel(string message, string source, ValidationItemType type) + { + Message = message; + Source = source; + Type = type; + Icon = type == ValidationItemType.Error ? "\u2717" : "\u26A0"; + IconColor = type == ValidationItemType.Error ? "#FF6B6B" : "#FFB84D"; + Background = type == ValidationItemType.Error ? "#1AFF6B6B" : "#1AFFB84D"; + BorderColor = type == ValidationItemType.Error ? "#FF6B6B" : "#FFB84D"; + } + + /// + /// Gets the validation message. + /// + public string Message { get; } + + /// + /// Gets the source file name. + /// + public string Source { get; } + + /// + /// Gets the type of validation item. + /// + public ValidationItemType Type { get; } + + /// + /// Gets the icon character for the validation type. + /// + public string Icon { get; } + + /// + /// Gets the icon color as a hex string. + /// + public string IconColor { get; } + + /// + /// Gets the background color as a hex string with alpha. + /// + public string Background { get; } + + /// + /// Gets the border color as a hex string. + /// + public string BorderColor { get; } +} diff --git a/NEW/src/Utils/JdeScoping.ConfigManager/Views/Dialogs/DiffPreviewDialog.axaml b/NEW/src/Utils/JdeScoping.ConfigManager/Views/Dialogs/DiffPreviewDialog.axaml new file mode 100644 index 0000000..1526d1c --- /dev/null +++ b/NEW/src/Utils/JdeScoping.ConfigManager/Views/Dialogs/DiffPreviewDialog.axaml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + insertions, deletions + + + +