Skip to content

Commit

Permalink
Implement Copy Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander van Delft committed Jan 13, 2025
1 parent 47bc7b4 commit 9f19ac0
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 19 deletions.
9 changes: 8 additions & 1 deletion COMET.Web.Common/Enumerations/BrowserSessionSettingKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace COMET.Web.Common.Enumerations
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;

using CDP4Dal.Operations;

/// <summary>
/// En enumeration of possible keys to be used to store and retrieve cached BrowserSessionSettings
/// </summary>
Expand All @@ -45,6 +47,11 @@ public enum BrowserSessionSettingKey
/// <summary>
/// Key to handle the last selected <see cref="DomainOfExpertise"/>
/// </summary>
LastUsedDomainOfExpertise
LastUsedDomainOfExpertise,

/// <summary>
/// Key to handle the type of <see cref="OperationKind"/> to use when copying data from one model to another
/// </summary>
CopyElementDefinitionOperationKind
}
}
5 changes: 3 additions & 2 deletions COMET.Web.Common/Utilities/CopyCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ public CopyCreator(ISession session)
/// </summary>
/// <param name="elementDefinition">The <see cref="ElementDefinition"/> to copy</param>
/// <param name="targetIteration">The target container</param>
public async Task CopyAsync(ElementDefinition elementDefinition, Iteration targetIteration)
/// <param name="operationKind">The <see cref="OperationKind"/> that defines the kind of copy operation.</param>
public async Task CopyAsync(ElementDefinition elementDefinition, Iteration targetIteration, OperationKind operationKind = OperationKind.CopyDefaultValuesChangeOwner)
{
// copy the payload to this iteration
var copyOperationHelper = new CopyPermissionHelper(this.session, false);
var copyPermissionResult = await copyOperationHelper.ComputeCopyPermissionAsync(elementDefinition, targetIteration);

if (copyPermissionResult.ErrorList.Any() || copyPermissionResult.CopyableThings.Any())
{
await this.WriteCopyOperationAsync(elementDefinition, targetIteration, OperationKind.CopyKeepValuesChangeOwner);
await this.WriteCopyOperationAsync(elementDefinition, targetIteration, operationKind);
}
}

Expand Down
4 changes: 2 additions & 2 deletions COMET.Web.Common/wwwroot/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,9 @@
}

.treeview-scrollarea {
height: calc(90vh - 185px);
height: calc(90vh - 220px);
}

.cardview-detailspanel-scrollarea {
height: calc(90vh - 145px);
height: calc(90vh - 165px);
}
31 changes: 31 additions & 0 deletions COMETwebapp/Components/MultiModelEditor/CopySettings.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!------------------------------------------------------------------------------
// Copyright (c) 2023-2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of CDP4-COMET WEB Community Edition
// The CDP4-COMET WEB Community Edition is the Starion Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The CDP4-COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// 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/.
------------------------------------------------------------------------------->
@inherits DisposableComponent
When a user drops an ElementDefinition on this Engineering Model, data from the original ElementDefinition is copied using the following settings:
<DxRadioGroup
Items="@this.ViewModel.AvailableOperationKinds"
TextFieldName="Key"
ValueFieldName="Value"
@bind-Value="@this.ViewModel.SelectedOperationKind" />
<div class="modal-footer m-top-10px">
<DxButton RenderStyle="ButtonRenderStyle.Primary" Text="Save Settings" Click="async () => await this.SaveSettings()" />
</div>
61 changes: 61 additions & 0 deletions COMETwebapp/Components/MultiModelEditor/CopySettings.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CopySettings.razor.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// 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/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Components.MultiModelEditor
{
using COMET.Web.Common.Components;

using COMETwebapp.ViewModels.Components.MultiModelEditor.CopySettings;

using Microsoft.AspNetCore.Components;

/// <summary>
/// Partial class for the component <see cref="CopySettings" />
/// </summary>
public partial class CopySettings : DisposableComponent
{
/// <summary>
/// The <see cref="ICopySettingsViewModel" /> for the component
/// </summary>
[Parameter]
public ICopySettingsViewModel ViewModel { get; set; }

/// <summary>
/// Action to perform after settings are saved.
/// </summary>
[Parameter]
public EventCallback OnAfterSaveSettings { get; set; }

/// <summary>
/// Save the settings
/// </summary>
/// <returns>an awaitable <see cref="Task"/></returns>
private async Task SaveSettings()
{
await this.ViewModel.SaveSettings();
await this.InvokeAsync(this.StateHasChanged);
await this.OnAfterSaveSettings.InvokeAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ else
</tr>
</table>
</p>
<div class="@(this.dragOverNode == this.TreeView && this.AllowNodeDrop && this.AllowDrop ? "treeview-drag-over" : "")"
<div class="drop-area-color @(this.dragOverNode == this.TreeView && this.AllowNodeDrop && this.AllowDrop ? "treeview-drag-over" : "")"
dropzone="@(this.AllowDrop ? "move" : "")"
ondragover="@(this.AllowDrop ? "event.preventDefault();" : "")"
@ondragenter="@(() => this.DragEnterAsync(this.TreeView))"
@ondragleave="@(() => this.DragLeaveAsync(this.TreeView))"
@ondrop="@(() => this.DropAsync(null))"
style="padding:2px;width:100%;border:dotted 1px;border-radius: 5px;height:25px;color:cadetblue;@(this.AllowDrop ? "" : "visibility:hidden;")">
style="padding:2px;border:dotted 1px;border-radius: 5px;height:25px;@(this.AllowDrop ? "" : "visibility:hidden;")">
Drop here to create new element...
</div>
<div class="@this.ScrollableAreaCssClass" style="overflow-y:auto;">
Expand Down
27 changes: 21 additions & 6 deletions COMETwebapp/Components/MultiModelEditor/MultiModelEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
@inherits SingleIterationApplicationBase<COMETwebapp.ViewModels.Components.MultiModelEditor.IMultiModelEditorViewModel>;

<LoadingComponent IsVisible="@this.ViewModel.IsLoading">
<div style= "padding-bottom:5px;">
<span>
<DxButton Click="() => {this.ViewModel.OpenCopySettingsPopup();}" CssClass="drop-area-background-color" title="Open drop settings" IconCssClass="oi oi-transfer"></DxButton>
</span>
<span>
Selected copy mode: @this.ViewModel.CopySettingsViewModel.SelectedOperationKindDescription
</span>
</div>
<ValidationMessageComponent ValidationMessage="@(this.ErrorMessage)" />
<div class="selected-data-item-page" style="flex-wrap:nowrap!important;">
<div class="selected-data-item-table d-flex" style="flex: 1 1 50%!important;gap: 10px;min-width:600px;">
Expand All @@ -34,13 +42,13 @@
ScrollableAreaCssClass="treeview-scrollarea"
InitialIteration="@this.ViewModel.CurrentThing"
SelectionChanged="model =>
{
if (model != null)
{
if (model != null)
{
this.TargetTree.ClearSelection();
}
this.OnElementSelected(model);
}"
this.TargetTree.ClearSelection();
}
this.OnElementSelected(model);
}"
AllowDrag="true"
AllowDrop="true"
OnCalculateDropIsAllowed="@(async x => await this.SetDropIsAllowedAsync(x))"
Expand Down Expand Up @@ -107,4 +115,11 @@
<AddParameter ViewModel="@this.ViewModel.AddParameterViewModel"/>
</BodyContentTemplate>
</DxPopup>

<DxPopup CloseOnOutsideClick="false" HeaderText="Set Copy Settings" @bind-Visible="@this.ViewModel.IsOnCopySettingsMode" Width="40vw">
<BodyContentTemplate>
<CopySettings ViewModel="this.ViewModel.CopySettingsViewModel" OnAfterSaveSettings="this.StateHasChanged"/>
</BodyContentTemplate>
</DxPopup>

</LoadingComponent>
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected override void OnViewModelAssigned()

this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsOnCreationMode).SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsOnAddingParameterMode).SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsOnCopySettingsMode).SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions COMETwebapp/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace COMETwebapp.Extensions
using COMETwebapp.ViewModels.Components.ReferenceData;
using COMETwebapp.ViewModels.Pages;
using COMETwebapp.ViewModels.Components.SiteDirectory;
using COMETwebapp.ViewModels.Components.MultiModelEditor.CopySettings;

/// <summary>
/// Extension class for the <see cref="IServiceCollection" />
Expand Down Expand Up @@ -107,6 +108,7 @@ public static void RegisterViewModels(this IServiceCollection serviceCollection)
serviceCollection.AddTransient<IElementDefinitionTableViewModel, ElementDefinitionTableViewModel>();
serviceCollection.AddTransient<IElementDefinitionTreeViewModel, ElementDefinitionTreeViewModel>();
serviceCollection.AddTransient<IMultiModelEditorViewModel, MultiModelEditorViewModel>();
serviceCollection.AddTransient<ICopySettingsViewModel, CopySettingsViewModel>();
serviceCollection.AddTransient<IBookEditorBodyViewModel, BookEditorBodyViewModel>();
serviceCollection.AddTransient<IMeasurementUnitsTableViewModel, MeasurementUnitsTableViewModel>();
serviceCollection.AddTransient<IMeasurementScalesTableViewModel, MeasurementScalesTableViewModel>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CopySettingsViewModel.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// 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/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.ViewModels.Components.MultiModelEditor.CopySettings
{
using CDP4Dal.Operations;

using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Model;
using COMET.Web.Common.Services.Cache;
using COMET.Web.Common.Utilities.DisposableObject;

using Microsoft.AspNetCore.Components;

/// <summary>
/// View model for the <see cref="CopySettingsViewModel" /> component
/// </summary>
public class CopySettingsViewModel : DisposableObject, ICopySettingsViewModel
{
/// <summary>
/// Holds a reference to the Injected <see cref="ICacheService"/>
/// </summary>
private readonly ICacheService cacheService;

/// <summary>
/// Gets a collection of <see cref="OperationKind"/> instance that can be selected as Copy Operation
/// </summary>
public CopyOperationKinds AvailableOperationKinds { get; } = new();

/// <summary>
/// Gets or sets the selected <see cref="OperationKind"/>
/// </summary>
public OperationKind SelectedOperationKind { get; set; } = OperationKind.Copy;

/// <summary>
/// The selected copy <see cref="OperationKind"/>'s descriptive text
/// </summary>
public string SelectedOperationKindDescription => this.AvailableOperationKinds.Single(x => x.Value == this.SelectedOperationKind).Key;

/// <summary>
/// The callback executed when the method <see cref="SaveSettings" /> was executed
/// </summary>
public EventCallback OnSaveSettings { get; set; }

/// <summary>
/// Create a new instance of the <see cref="ICacheService"/> class
/// </summary>
/// <param name="cacheService">The Injected <see cref="ICacheService"/></param>
public CopySettingsViewModel(ICacheService cacheService)
{
this.cacheService = cacheService;

if (this.cacheService.TryGetOrAddBrowserSessionSetting(BrowserSessionSettingKey.CopyElementDefinitionOperationKind, OperationKind.Copy, out var selectedOperationKind) && selectedOperationKind is OperationKind operationKind)
{
this.SelectedOperationKind = operationKind;
}
}

/// <summary>
/// Initializes the current view model
/// </summary>
public void InitializeViewModel()
{
}

/// <summary>
/// Saves the Settings
/// </summary>
/// <returns>An awaitable <see cref="Task"/></returns>
public async Task SaveSettings()
{
this.cacheService.AddOrUpdateBrowserSessionSetting(BrowserSessionSettingKey.CopyElementDefinitionOperationKind, this.SelectedOperationKind);
await this.OnSaveSettings.InvokeAsync();
}
}

/// <summary>
/// Defines a collection of descriptive strings that belongs to an <see cref="OperationKind"/>
/// </summary>
public class CopyOperationKinds : Dictionary<string, OperationKind>
{
/// <summary>
/// Creates a new instance of the <see cref="CopyOperationKinds"/>
/// </summary>
public CopyOperationKinds()
{
this.Add("Set Parameter values to default, keep original owner", OperationKind.Copy);
this.Add("Set Parameter values to default, change owner to active domain", OperationKind.CopyDefaultValuesChangeOwner);
this.Add("Keep parameter values, keep original owner", OperationKind.CopyKeepValues);
this.Add("Keep parameter values, change owner to active domain", OperationKind.CopyKeepValuesChangeOwner);
}
}
}
Loading

0 comments on commit 9f19ac0

Please sign in to comment.