Skip to content

Commit

Permalink
Fix #10: Generic Export UI improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineatstariongroup committed Dec 11, 2024
1 parent 78368d5 commit 862adb6
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void VerifyViewModelProperties()
{
Assert.That(this.exporterViewModel.CanProceed, Is.False);
Assert.That(this.exporterViewModel.SelectedFilePath, Is.Null);
Assert.That(this.exporterViewModel.ExportSetups.Items, Is.Empty);
Assert.That(this.exporterViewModel.AvailableExportSetups.Items, Is.Empty);
Assert.That(this.exporterViewModel.OutputFileCommand, Is.Null);
Assert.That(this.exporterViewModel.ExportCommand, Is.Null);
});
Expand All @@ -141,22 +141,22 @@ public void VerifyInitializeViewModel()
Assert.Multiple(() =>
{
this.cacheService.Verify(x => x.GetTaggedValues(It.IsAny<int[]>()), Times.Once);
Assert.That(this.exporterViewModel.ExportSetups.Items, Is.Not.Empty);
Assert.That(this.exporterViewModel.ExportSetups, Has.Count.EqualTo(3));
Assert.That(this.exporterViewModel.AvailableExportSetups.Items, Is.Not.Empty);
Assert.That(this.exporterViewModel.AvailableExportSetups, Has.Count.EqualTo(3));
Assert.That(this.exporterViewModel.OutputFileCommand, Is.Not.Null);
Assert.That(this.exporterViewModel.ExportCommand, Is.Not.Null);
Assert.That(this.exporterViewModel.ExportSetups.Items.All(x => x.ShouldBeExported), Is.True);
Assert.That(this.exporterViewModel.AvailableExportSetups.Items.All(x => x.ShouldBeExported), Is.True);

Assert.That(this.exporterViewModel.ExportSetups.Items.Single(x => x.ElementKind == "Requirement").AvailableTaggedValuesForExport
Assert.That(this.exporterViewModel.AvailableExportSetups.Items.Single(x => x.ElementKind == "Requirement").AvailableTaggedValuesForExport
.Count(), Is.EqualTo(2));

Assert.That(this.exporterViewModel.ExportSetups.Items.Single(x => x.ElementKind == "Function").AvailableTaggedValuesForExport
Assert.That(this.exporterViewModel.AvailableExportSetups.Items.Single(x => x.ElementKind == "Function").AvailableTaggedValuesForExport
.Count(), Is.EqualTo(2));

Assert.That(this.exporterViewModel.ExportSetups.Items.Single(x => x.ElementKind == "Product").HaveAnyTaggedValues,
Assert.That(this.exporterViewModel.AvailableExportSetups.Items.Single(x => x.ElementKind == "Product").HaveAnyTaggedValues,
Is.False);

Assert.That(this.exporterViewModel.ExportSetups.Items.All(x => x.AvailableTaggedValuesForExport.Count()
Assert.That(this.exporterViewModel.AvailableExportSetups.Items.All(x => x.AvailableTaggedValuesForExport.Count()
== x.SelectedTaggedValuesForExport.Count()), Is.True);
});
}
Expand Down Expand Up @@ -193,10 +193,10 @@ public void VerifyCanProceedComputation()

this.exporterViewModel.OutputFileCommand.Execute().Subscribe();
Assert.That(this.exporterViewModel.CanProceed, Is.True);
this.exporterViewModel.ExportSetups.Items.ForEach(x => x.ShouldBeExported = false);
this.exporterViewModel.AvailableExportSetups.Items.ForEach(x => x.ShouldBeExported = false);

Assert.That(this.exporterViewModel.CanProceed, Is.False);
this.exporterViewModel.ExportSetups.Items[0].ShouldBeExported = true;
this.exporterViewModel.AvailableExportSetups.Items[0].ShouldBeExported = true;
Assert.That(this.exporterViewModel.CanProceed, Is.True);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public GenericExportSetupViewModel(IReadOnlyList<SlimElement> elements)
}

this.ElementKind = elements[0].ElementKind;
this.ElementType = elements[0].ElementType;

this.AvailableTaggedValuesForExport = elements
.SelectMany(x => x.TaggedValues.Keys)
Expand All @@ -83,6 +84,11 @@ public GenericExportSetupViewModel(IReadOnlyList<SlimElement> elements)
this.ExportableElements = elements;
}

/// <summary>
/// Gets the <see cref="Element" /> Type
/// </summary>
public string ElementType { get; }

/// <summary>
/// Gets the collection of available Connectors kind that could be exported
/// </summary>
Expand Down
62 changes: 49 additions & 13 deletions EA-ModelKit/ViewModels/Exporter/GenericExporterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ internal class GenericExporterViewModel : BaseDialogViewModel, IGenericExporterV
/// </summary>
private readonly ICacheService cacheService;

/// <summary>
/// Gets the injected <see cref="IGenericExporterService" />
/// </summary>
private readonly IGenericExporterService exporterService;

/// <summary>
/// The injected <see cref="IViewBuilderService" />
/// </summary>
Expand All @@ -64,22 +69,27 @@ internal class GenericExporterViewModel : BaseDialogViewModel, IGenericExporterV
private bool canProceed;

/// <summary>
/// Backing field for <see cref="SelectedFilePath" />
/// Backing field for <see cref="HaveSelectedExportSetup" />
/// </summary>
private string selectedFilePath;
private bool haveSelectedExportSetup;

/// <summary>
/// Gets the injected <see cref="IGenericExporterService"/>
/// Backing field for <see cref="SelectedExportSetup" />
/// </summary>
private readonly IGenericExporterService exporterService;
private IGenericExportSetupViewModel selectedExportSetup;

/// <summary>
/// Backing field for <see cref="SelectedFilePath" />
/// </summary>
private string selectedFilePath;

/// <summary>
/// Initialize a new instance of <see cref="GenericExporterViewModel" />
/// </summary>
/// <param name="loggerService">The <see cref="ILoggerService" /></param>
/// <param name="cacheService">The injected <see cref="ICacheService" /></param>
/// <param name="viewBuilderService">The injected <see cref="IViewBuilderService" /></param>
/// <param name="exporterService">The injected <see cref="IGenericExporterService"/></param>
/// <param name="exporterService">The injected <see cref="IGenericExporterService" /></param>
public GenericExporterViewModel(ILoggerService loggerService, ICacheService cacheService, IViewBuilderService viewBuilderService,
IGenericExporterService exporterService) : base(loggerService)
{
Expand Down Expand Up @@ -109,7 +119,7 @@ public bool CanProceed
/// <summary>
/// Gets the <see cref="SourceList{T}" /> of <see cref="IGenericExportSetupViewModel" />
/// </summary>
public SourceList<IGenericExportSetupViewModel> ExportSetups { get; } = new();
public SourceList<IGenericExportSetupViewModel> AvailableExportSetups { get; } = new();

/// <summary>
/// Gets the <see cref="ReactiveCommand{TParam,TResult}" /> that allows the selection of the output file
Expand All @@ -121,6 +131,24 @@ public bool CanProceed
/// </summary>
public ReactiveCommand<Unit, Unit> ExportCommand { get; private set; }

/// <summary>
/// Gets or sets the currently selected <see cref="IGenericExportSetupViewModel" />
/// </summary>
public IGenericExportSetupViewModel SelectedExportSetup
{
get => this.selectedExportSetup;
set => this.RaiseAndSetIfChanged(ref this.selectedExportSetup, value);
}

/// <summary>
/// Asserts that the an <see cref="IGenericExportSetupViewModel" /> is selected or not
/// </summary>
public bool HaveSelectedExportSetup
{
get => this.haveSelectedExportSetup;
private set => this.RaiseAndSetIfChanged(ref this.haveSelectedExportSetup, value);
}

/// <summary>
/// Initialies properties of the ViewModel
/// </summary>
Expand All @@ -145,9 +173,13 @@ public void InitializeViewModel(IReadOnlyList<Element> elements)
? existingTaggedValues
: [], this.cacheService.GetAssociatedConnectors(x.ElementID)));

this.ExportSetups.AddRange(slimElements.GroupBy(x => x.ElementKind)
.Select(e => new GenericExportSetupViewModel(e.ToList())));
this.AvailableExportSetups.AddRange(slimElements
.GroupBy(x => x.ElementKind)
.Select(e => new GenericExportSetupViewModel(e.ToList()))
.OrderBy(x => x.ElementType)
.ThenBy(x => x.ElementKind));

this.SelectedExportSetup = this.AvailableExportSetups.Items[0];
this.InitializeObservablesAndCommands();
}

Expand All @@ -158,10 +190,14 @@ private void InitializeObservablesAndCommands()
{
this.OutputFileCommand = ReactiveCommand.Create(this.OnOutputFileSelect);

this.Disposables.Add(this.ExportSetups.Connect().WhenPropertyChanged(x => x.ShouldBeExported)
this.Disposables.Add(this.AvailableExportSetups.Connect().WhenPropertyChanged(x => x.ShouldBeExported)
.Subscribe(_ => this.ComputeCanProceed()));

this.Disposables.Add(this.WhenPropertyChanged(x => x.SelectedFilePath).Subscribe(_ => this.ComputeCanProceed()));

this.Disposables.Add(this.WhenPropertyChanged(x => x.SelectedExportSetup)
.Subscribe(_ => this.HaveSelectedExportSetup = this.SelectedExportSetup != null));

this.ExportCommand = ReactiveCommand.CreateFromTask(this.OnExportAsync, this.WhenAnyValue(x => x.CanProceed));
}

Expand All @@ -174,10 +210,10 @@ private async Task OnExportAsync()

try
{
var exportConfiguration = this.ExportSetups.Items.Where(x => x.ShouldBeExported)
.Select(x => new GenericExportConfiguration(x.ExportableElements,
var exportConfiguration = this.AvailableExportSetups.Items.Where(x => x.ShouldBeExported)
.Select(x => new GenericExportConfiguration(x.ExportableElements,
[..x.SelectedTaggedValuesForExport], [..x.SelectedConnectorsForExport]));

await this.exporterService.ExportElementsAsync(this.selectedFilePath, [..exportConfiguration]);
this.CloseWindowBehavior.Close();
}
Expand All @@ -202,7 +238,7 @@ private void ComputeCanProceed()
return;
}

this.CanProceed = this.ExportSetups.Items.Any(x => x.ShouldBeExported);
this.CanProceed = this.AvailableExportSetups.Items.Any(x => x.ShouldBeExported);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,10 @@ internal interface IGenericExportSetupViewModel: INotifyPropertyChanged
/// Gets or sets the collection of selected Connectors kind that have to be exported
/// </summary>
IEnumerable<string> SelectedConnectorsForExport { get; set; }

/// <summary>
/// Gets the <see cref="Element" /> Type
/// </summary>
string ElementType { get; }
}
}
12 changes: 11 additions & 1 deletion EA-ModelKit/ViewModels/Exporter/IGenericExporterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal interface IGenericExporterViewModel : IBaseDialogViewModel
/// <summary>
/// Gets the <see cref="SourceList{T}" /> of <see cref="IGenericExportSetupViewModel" />
/// </summary>
SourceList<IGenericExportSetupViewModel> ExportSetups { get; }
SourceList<IGenericExportSetupViewModel> AvailableExportSetups { get; }

/// <summary>
/// Gets the path to the file that should be use for export
Expand All @@ -61,6 +61,16 @@ internal interface IGenericExporterViewModel : IBaseDialogViewModel
/// </summary>
ReactiveCommand<Unit, Unit> ExportCommand { get; }

/// <summary>
/// Gets or sets the currently selected <see cref="IGenericExportSetupViewModel"/>
/// </summary>
IGenericExportSetupViewModel SelectedExportSetup { get; set; }

/// <summary>
/// Asserts that the an <see cref="IGenericExportSetupViewModel" /> is selected or not
/// </summary>
bool HaveSelectedExportSetup { get; }

/// <summary>
/// Initialies properties of the ViewModel
/// </summary>
Expand Down
Loading

0 comments on commit 862adb6

Please sign in to comment.