Skip to content

Commit

Permalink
Bugfixes, make copy two-way and show pills
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander van Delft committed Dec 20, 2024
1 parent 96b1cbd commit 304ffbe
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
@using COMET.Web.Common.Model
@using COMETwebapp.ViewModels.Components.MultiModelEditor.Rows
@using CDP4JsonSerializer.JsonConverter
@inject IJSRuntime JSRuntime
<!------------------------------------------------------------------------------
<!------------------------------------------------------------------------------
// Copyright (c) 2023-2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
Expand All @@ -23,6 +19,11 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
------------------------------------------------------------------------------->
@using COMET.Web.Common.Model
@using COMETwebapp.ViewModels.Components.MultiModelEditor.Rows
@using CDP4JsonSerializer.JsonConverter
@inject IJSRuntime JSRuntime

<div style = "height:50px">
@if (this.IsModelSelectionEnabled)
{
Expand Down Expand Up @@ -60,7 +61,6 @@ else
var dataItem = (ElementBaseTreeRowViewModel)context.DataItem;
var draggable = this.AllowDrag && this.AllowNodeDrag.Invoke(this, dataItem);
var isTopElement = dataItem is ElementDefinitionTreeTreeRowViewModel { IsTopElement: true };

var style = isTopElement ? "font-weight-bold" : string.Empty;
}

Expand All @@ -75,13 +75,29 @@ else
@ondragenter="@(async () => await this.DragEnter(dataItem))"
@ondragleave="@(async () => await this.DragLeave(dataItem))"
@ondrop="@(async () => await this.Drop(dataItem))">
@dataItem.ElementName
@dataItem.ElementName <span>
<button class="starion-pill" title="Owning Domain Of Expertise: @dataItem.OwnerShortName">@dataItem.OwnerShortName</button>
</span>
@foreach (var category in @dataItem.ElementBase.GetAllCategories())
{
<span>
<button class="starion-pill" style="background-color:aliceblue !important;" title="Category: @category.ShortName">@category.ShortName</button>
</span>
}
</div>
}
else
{
<div>
@dataItem.ElementName
@dataItem.ElementName <span>
<button class="starion-pill" title="Owning Domain Of Expertise: @dataItem.OwnerShortName">@dataItem.OwnerShortName</button>
</span>
@foreach (var category in @dataItem.ElementBase.GetAllCategories())
{
<span>
<button class="starion-pill" style="background-color:aliceblue !important;" title="Category: @category.ShortName">@category.ShortName</button>
</span>
}
</div>
}
</NodeTextTemplate>
Expand Down
42 changes: 22 additions & 20 deletions COMETwebapp/Components/MultiModelEditor/MultiModelEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
------------------------------------------------------------------------------->

@using COMETwebapp.Components.ModelEditor
@using COMETwebapp.ViewModels.Components.MultiModelEditor.Rows
@inherits SingleIterationApplicationBase<COMETwebapp.ViewModels.Components.MultiModelEditor.IMultiModelEditorViewModel>;

Expand All @@ -31,35 +32,36 @@
<h4>Source Model</h4>
<ElementDefinitionTree
@ref="this.SourceTree"
IsModelSelectionEnabled="true"
Iteration="@this.ViewModel.CurrentThing"
SelectionChanged="model => { if (model != null) this.TargetTree.ClearSelection(); this.OnElementSelected(model);}"
AllowDrag="true"
AllowDrop="false"
AllowDrop="true"
OnCalculateDropIsAllowed="@(async x => await this.SetDropIsAllowed(x))"
OnDragEnter="@(async x => await this.OnDragEnter(x))"
OnDragLeave="@(async x => await this.OnDragLeave(x))"
OnDragStart="@(async x => await this.OnDragStart(x))"
OnDragEnd="@(async x => await this.OnDragEnd(x))"
OnDrop="@(async x => await this.OnDrop(x))"
AllowNodeDrag="(tree, model) => model is ElementDefinitionTreeTreeRowViewModel"
SelectionChanged="model =>
{
if (model != null) this.TargetTree.ClearSelection();
this.OnElementSelected(model);
}">
IsModelSelectionEnabled="true">
</ElementDefinitionTree>
</div>
<div>
<h4>Target Model</h4>
<ElementDefinitionTree
@ref="this.TargetTree"
Iteration="@this.ViewModel.CurrentThing"
SelectionChanged="model => { if (model != null) this.SourceTree.ClearSelection(); this.OnElementSelected(model);}"
AllowDrag="true"
AllowDrop="true"
OnCalculateDropIsAllowed="@(async x => await this.SetDropIsAllowed(x))"
OnDragEnter="@(async x => await this.OnDragEnter(x))"
OnDragLeave="@(async x => await this.OnDragLeave(x))"
OnDragStart="@(async x => await this.OnDragStart(x))"
OnDragEnd="@(async x => await this.OnDragEnd(x))"
OnDrop="@(async x => await this.OnDrop(x))"
AllowNodeDrag="(tree, model) => model is ElementDefinitionTreeTreeRowViewModel"
IsModelSelectionEnabled="false">
@ref="this.TargetTree"
Iteration="@this.ViewModel.CurrentThing"
SelectionChanged="model => { if (model != null) this.SourceTree.ClearSelection(); this.OnElementSelected(model);}"
AllowDrag="true"
AllowDrop="true"
OnCalculateDropIsAllowed="@(async x => await this.SetDropIsAllowed(x))"
OnDragEnter="@(async x => await this.OnDragEnter(x))"
OnDragLeave="@(async x => await this.OnDragLeave(x))"
OnDragStart="@(async x => await this.OnDragStart(x))"
OnDragEnd="@(async x => await this.OnDragEnd(x))"
OnDrop="@(async x => await this.OnDrop(x))"
AllowNodeDrag="(tree, model) => model is ElementDefinitionTreeTreeRowViewModel"
IsModelSelectionEnabled="false">
</ElementDefinitionTree>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ protected override void InitializeValues(Dictionary<string, string> parameters)
/// <summary>
/// Method executed when a <see cref="ElementDefinitionRowViewModel" /> is selected
/// </summary>
/// <param name="args">The <see cref="GridRowClickEventArgs" /></param>
private void OnElementSelected(ElementBaseTreeRowViewModel args)
/// <param name="elementRowViewModel">The <see cref="ElementBaseTreeRowViewModel" /></param>
private void OnElementSelected(ElementBaseTreeRowViewModel elementRowViewModel)
{
this.ViewModel.SelectElement(args?.ElementBase);
this.ViewModel.SelectElement(elementRowViewModel?.ElementBase);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace COMETwebapp.ViewModels.Components.MultiModelEditor.Rows
{
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;

using COMETwebapp.ViewModels.Components.ModelEditor.Rows;

Expand All @@ -45,14 +46,20 @@ public abstract class ElementBaseTreeRowViewModel : ReactiveObject
/// </summary>
private string elementName;

/// <summary>
/// Backing field for <see cref="OwnerShortName"/>
/// </summary>
private string ownerShortName;

/// <summary>
/// Initializes a new instance of the <see cref="ElementDefinitionRowViewModel" /> class.
/// <param name="elementBase">the <see cref="ElementBase" /></param>
/// <param name="elementBase">the <see cref="CDP4Common.EngineeringModelData.ElementBase" /></param>
/// </summary>
protected ElementBaseTreeRowViewModel(ElementBase elementBase)
{
this.ElementBase = elementBase;
this.ElementName = elementBase.Name;
this.OwnerShortName = elementBase.Owner.ShortName;
}

/// <summary>
Expand All @@ -62,6 +69,15 @@ protected ElementBaseTreeRowViewModel()
{
}

/// <summary>
/// The shortname of the owning <see cref="DomainOfExpertise" />
/// </summary>
public string OwnerShortName
{
get => this.ownerShortName;
set => this.RaiseAndSetIfChanged(ref this.ownerShortName, value);
}

/// <summary>
/// The name of the <see cref="CDP4Common.EngineeringModelData.ElementBase" />
/// </summary>
Expand All @@ -72,7 +88,7 @@ public string ElementName
}

/// <summary>
/// The <see cref="ElementBase" />
/// The <see cref="CDP4Common.EngineeringModelData.ElementBase" />
/// </summary>
public ElementBase ElementBase
{
Expand All @@ -88,6 +104,7 @@ public void UpdateProperties(ElementBaseTreeRowViewModel elementBaseTreeRow)
{
this.ElementBase = elementBaseTreeRow.elementBase;
this.ElementName = elementBaseTreeRow.elementName;
this.OwnerShortName = elementBaseTreeRow.OwnerShortName;
}
}
}

0 comments on commit 304ffbe

Please sign in to comment.