Skip to content

Commit

Permalink
[FIX] - Copy problem for two-way drag-drop source <=> target
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander van Delft committed Dec 20, 2024
1 parent a649e9e commit bd46ec2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public partial class ElementDefinitionTree
/// The Iteration
/// </summary>
[Parameter]
public Iteration Iteration { get; set; }
public Iteration InitialIteration { get; set; }

/// <summary>
/// Gets or sets a value indicating that another model can be selected for this TreeView or not
Expand Down Expand Up @@ -154,9 +154,9 @@ public partial class ElementDefinitionTree
/// </remarks>
protected override async Task OnAfterRenderAsync(bool firstRender)

Check warning on line 155 in COMETwebapp/Components/MultiModelEditor/ElementDefinitionTree.razor.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 155 in COMETwebapp/Components/MultiModelEditor/ElementDefinitionTree.razor.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 155 in COMETwebapp/Components/MultiModelEditor/ElementDefinitionTree.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 155 in COMETwebapp/Components/MultiModelEditor/ElementDefinitionTree.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (this.ViewModel.Iteration != this.Iteration)
if (this.ViewModel.Iteration != this.InitialIteration)
{
this.Iteration = this.ViewModel.Iteration;
this.InitialIteration = this.ViewModel.Iteration;
}
}

Expand All @@ -168,7 +168,7 @@ protected override void OnParametersSet()
{
base.OnParametersSet();

this.ViewModel.Iteration = this.Iteration;
this.ViewModel.Iteration ??= this.InitialIteration;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<h4>Source Model</h4>
<ElementDefinitionTree
@ref="this.SourceTree"
Iteration="@this.ViewModel.CurrentThing"
InitialIteration="@this.ViewModel.CurrentThing"
SelectionChanged="model => { if (model != null) this.TargetTree.ClearSelection(); this.OnElementSelected(model);}"
AllowDrag="true"
AllowDrop="true"
Expand All @@ -50,7 +50,7 @@
<h4>Target Model</h4>
<ElementDefinitionTree
@ref="this.TargetTree"
Iteration="@this.ViewModel.CurrentThing"
InitialIteration="@this.ViewModel.CurrentThing"
SelectionChanged="model => { if (model != null) this.SourceTree.ClearSelection(); this.OnElementSelected(model);}"
AllowDrag="true"
AllowDrop="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private async Task OnDrop((ElementDefinitionTree, ElementBaseTreeRowViewModel) n
if (nodeData.Item2 == null)
{
// Drop in the same model
await this.ViewModel.CopyAndAddNewElement(elementDefinitionTreeRowViewModel.ElementBase);
await this.ViewModel.CopyAndAddNewElement(nodeData.Item1, elementDefinitionTreeRowViewModel.ElementBase);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace COMETwebapp.ViewModels.Components.MultiModelEditor
using COMET.Web.Common.ViewModels.Components.Applications;

using COMETwebapp.Components.ModelEditor;
using COMETwebapp.Components.MultiModelEditor;
using COMETwebapp.ViewModels.Components.ModelEditor;
using COMETwebapp.ViewModels.Components.ModelEditor.AddParameterViewModel;
using COMETwebapp.ViewModels.Components.SystemRepresentation;
Expand Down Expand Up @@ -97,8 +98,9 @@ public interface IMultiModelEditorViewModel : ISingleIterationApplicationBaseVie
/// <summary>
/// Add a new <see cref="ElementDefinition"/> based on an existing <see cref="ElementBase"/>
/// </summary>
/// <param name="elementBase">The <see cref="ElementBase"/></param>
Task CopyAndAddNewElement(ElementBase elementBase);
/// <param name="elementDefinitionTree">The <see cref="ElementDefinitionTree"/> to copy the node to</param>
/// <param name="elementBase">The <see cref="ElementBase"/> to copy</param>
Task CopyAndAddNewElement(ElementDefinitionTree elementDefinitionTree, ElementBase elementBase);

/// <summary>
/// Add a new <see cref="ElementUsage"/> based on an existing <see cref="ElementBase"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace COMETwebapp.ViewModels.Components.MultiModelEditor
using COMET.Web.Common.ViewModels.Components.Applications;

using COMETwebapp.Components.ModelEditor;
using COMETwebapp.Components.MultiModelEditor;
using COMETwebapp.ViewModels.Components.ModelEditor;
using COMETwebapp.ViewModels.Components.ModelEditor.AddParameterViewModel;
using COMETwebapp.ViewModels.Components.SystemRepresentation;
Expand Down Expand Up @@ -180,12 +181,13 @@ public void OpenAddParameterPopup()
/// <summary>
/// Add a new <see cref="ElementDefinition"/> based on an existing <see cref="ElementBase"/>
/// </summary>
/// <param name="elementBase">The <see cref="ElementBase"/></param>
public async Task CopyAndAddNewElement(ElementBase elementBase)
/// <param name="elementDefinitionTree">The <see cref="ElementDefinitionTree"/> to copy the node to</param>
/// <param name="elementBase">The <see cref="ElementBase"/> to copy</param>
public async Task CopyAndAddNewElement(ElementDefinitionTree elementDefinitionTree, ElementBase elementBase)
{
this.IsLoading = true;

if (elementBase.GetContainerOfType<Iteration>() == this.CurrentThing)
if (elementBase.GetContainerOfType<Iteration>() == elementDefinitionTree.ViewModel.Iteration)
{
var copyCreator = new CopyElementDefinitionCreator(this.sessionService.Session);

Expand All @@ -209,7 +211,7 @@ public async Task CopyAndAddNewElement(ElementBase elementBase)

try
{
await copyCreator.Copy((ElementDefinition)elementBase, this.CurrentThing);
await copyCreator.Copy((ElementDefinition)elementBase, elementDefinitionTree.ViewModel.Iteration);
}
catch (Exception exception)
{
Expand All @@ -230,15 +232,15 @@ public async Task CopyAndAddNewElement(ElementBase elementBase)
/// <param name="toElementBase">The <see cref="ElementBase"/> where to add the new <see cref="ElementUsage"/> to</param>
public async Task AddNewElementUsage(ElementBase fromElementBase, ElementBase toElementBase)
{
if (fromElementBase.GetContainerOfType<Iteration>() == this.CurrentThing && toElementBase.GetContainerOfType<Iteration>() == this.CurrentThing)
if (fromElementBase.GetContainerOfType<Iteration>() == toElementBase.GetContainerOfType<Iteration>())
{
this.IsLoading = true;

var thingCreator = new ThingCreator();

try
{
await thingCreator.CreateElementUsage((ElementDefinition)toElementBase, (ElementDefinition)fromElementBase, this.sessionService.Session.OpenIterations.First(x => x.Key == this.CurrentThing).Value.Item1, this.sessionService.Session);
await thingCreator.CreateElementUsage((ElementDefinition)toElementBase, (ElementDefinition)fromElementBase, this.sessionService.Session.OpenIterations.First(x => x.Key == toElementBase.GetContainerOfType<Iteration>()).Value.Item1, this.sessionService.Session);
}
catch (Exception exception)
{
Expand Down

0 comments on commit bd46ec2

Please sign in to comment.