From 697f5bce240dc3a17eedf3926e36778d167a8c1f Mon Sep 17 00:00:00 2001 From: Joao Rua Date: Tue, 23 Apr 2024 12:27:52 +0100 Subject: [PATCH] cyclic ratio, interval, ordinal and rate scales creation/edit implemented + mappings and scale value definitions TODO - Support logarithmic scale data - Show error message in case of invalid data - Validation - Unit tests --- .../MappingToReferenceScalesTable.razor | 69 ++++++++ .../MappingToReferenceScalesTable.razor.cs | 138 +++++++++++++++ .../MeasurementScalesTable.razor | 160 ++++++++++++++++++ .../MeasurementScalesTable.razor.cs | 24 +-- .../ScaleValueDefinitionsTable.razor | 64 +++++++ .../ScaleValueDefinitionsTable.razor.cs | 128 ++++++++++++++ .../MeasurementScalesTable.razor | 118 ------------- .../ReferenceData/ReferenceDataPage.razor.cs | 1 + .../Common/Rows/BaseDataItemRowViewModel.cs | 2 +- .../IMeasurementScalesTableViewModel.cs | 44 +++++ .../MeasurementScalesTableViewModel.cs | 140 ++++++++++++++- .../MeasurementUnitsTableViewModel.cs | 2 +- .../MappingToReferenceScaleRowViewModel.cs | 109 ++++++++++++ .../Rows/ScaleValueDefinitionRowViewModel.cs | 61 +++++++ COMETwebapp/_Imports.razor | 1 + 15 files changed, 920 insertions(+), 141 deletions(-) create mode 100644 COMETwebapp/Components/ReferenceData/MeasurementScales/MappingToReferenceScalesTable.razor create mode 100644 COMETwebapp/Components/ReferenceData/MeasurementScales/MappingToReferenceScalesTable.razor.cs create mode 100644 COMETwebapp/Components/ReferenceData/MeasurementScales/MeasurementScalesTable.razor rename COMETwebapp/Components/ReferenceData/{ => MeasurementScales}/MeasurementScalesTable.razor.cs (84%) create mode 100644 COMETwebapp/Components/ReferenceData/MeasurementScales/ScaleValueDefinitionsTable.razor create mode 100644 COMETwebapp/Components/ReferenceData/MeasurementScales/ScaleValueDefinitionsTable.razor.cs delete mode 100644 COMETwebapp/Components/ReferenceData/MeasurementScalesTable.razor create mode 100644 COMETwebapp/ViewModels/Components/ReferenceData/Rows/MappingToReferenceScaleRowViewModel.cs create mode 100644 COMETwebapp/ViewModels/Components/ReferenceData/Rows/ScaleValueDefinitionRowViewModel.cs diff --git a/COMETwebapp/Components/ReferenceData/MeasurementScales/MappingToReferenceScalesTable.razor b/COMETwebapp/Components/ReferenceData/MeasurementScales/MappingToReferenceScalesTable.razor new file mode 100644 index 00000000..6e328bf0 --- /dev/null +++ b/COMETwebapp/Components/ReferenceData/MeasurementScales/MappingToReferenceScalesTable.razor @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + @{ + var row = (MappingToReferenceScaleRowViewModel)context.DataItem; + + + + + } + + + + + + + + + + + + + + + +
+ +
+
diff --git a/COMETwebapp/Components/ReferenceData/MeasurementScales/MappingToReferenceScalesTable.razor.cs b/COMETwebapp/Components/ReferenceData/MeasurementScales/MappingToReferenceScalesTable.razor.cs new file mode 100644 index 00000000..89995efa --- /dev/null +++ b/COMETwebapp/Components/ReferenceData/MeasurementScales/MappingToReferenceScalesTable.razor.cs @@ -0,0 +1,138 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023-2024 RHEA System 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 RHEA 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.Components.ReferenceData.MeasurementScales +{ + using CDP4Common.SiteDirectoryData; + + using COMETwebapp.ViewModels.Components.ReferenceData.Rows; + + using DevExpress.Blazor; + + using Microsoft.AspNetCore.Components; + + /// + /// Support class for the + /// + public partial class MappingToReferenceScalesTable + { + /// + /// A collection of mapping to reference scale to display for selection + /// + [Parameter] + public IEnumerable MappingToReferenceScales { get; set; } + + /// + /// The method that is executed when the mapping to reference scales change + /// + [Parameter] + public EventCallback> MappingToReferenceScalesChanged { get; set; } + + /// + /// A collection of dependent scale value definitions to display for selection + /// + [Parameter] + public IEnumerable DependentScaleValueDefinitions { get; set; } + + /// + /// A collection of reference scale value definitions to display for selection + /// + [Parameter] + public IEnumerable ReferenceScaleValueDefinitions { get; set; } + + /// + /// Gets or sets the condition to check if a mapping to reference scale should be created + /// + public bool ShouldCreate { get; private set; } + + /// + /// The mapping to reference scale that will be handled for both edit and add forms + /// + private MappingToReferenceScale MappingToReferenceScale { get; set; } = new(); + + /// + /// Gets or sets the grid control that is being customized. + /// + private IGrid Grid { get; set; } + + /// + /// Method that is invoked when the edit/add mapping to reference scale form is being saved + /// + private void OnEditMappingToReferenceScaleSaving() + { + var mappingToReferenceScalesList = this.MappingToReferenceScales.ToList(); + + if (this.ShouldCreate) + { + mappingToReferenceScalesList.Add(this.MappingToReferenceScale); + this.MappingToReferenceScales = mappingToReferenceScalesList; + } + else + { + var indexToUpdate = mappingToReferenceScalesList.FindIndex(x => x.Iid == this.MappingToReferenceScale.Iid); + mappingToReferenceScalesList[indexToUpdate] = this.MappingToReferenceScale; + } + + this.MappingToReferenceScales = mappingToReferenceScalesList; + this.MappingToReferenceScalesChanged.InvokeAsync(this.MappingToReferenceScales); + } + + /// + /// Method that is invoked when a mapping to reference scale row is being removed + /// + private void RemoveMappingToReferenceScale(MappingToReferenceScaleRowViewModel row) + { + var mappingToReferenceScalesList = this.MappingToReferenceScales.ToList(); + mappingToReferenceScalesList.Remove(row.MappingToReferenceScale); + + this.MappingToReferenceScales = mappingToReferenceScalesList; + this.MappingToReferenceScalesChanged.InvokeAsync(this.MappingToReferenceScales); + } + + /// + /// Method invoked when creating a new Mapping To Reference Scale + /// + /// A + private void CustomizeEditMappingToReferenceScale(GridCustomizeEditModelEventArgs e) + { + var dataItem = (MappingToReferenceScaleRowViewModel)e.DataItem; + this.ShouldCreate = e.IsNew; + + this.MappingToReferenceScale = dataItem == null + ? new MappingToReferenceScale() { Iid = Guid.NewGuid() } + : dataItem.MappingToReferenceScale.Clone(true); + + e.EditModel = this.MappingToReferenceScale; + } + + /// + /// Method used to retrieve the available rows, given the + /// + /// A collection of s to display + private List GetRows() + { + return this.MappingToReferenceScales.Select(x => new MappingToReferenceScaleRowViewModel(x)).ToList(); + } + } +} diff --git a/COMETwebapp/Components/ReferenceData/MeasurementScales/MeasurementScalesTable.razor b/COMETwebapp/Components/ReferenceData/MeasurementScales/MeasurementScalesTable.razor new file mode 100644 index 00000000..a7c5821c --- /dev/null +++ b/COMETwebapp/Components/ReferenceData/MeasurementScales/MeasurementScalesTable.razor @@ -0,0 +1,160 @@ + +@using COMETwebapp.Wrappers +@inherits SelectedDeprecatableDataItemBase + + + + + + + + + + + + + + + + + @{ + var row = (MeasurementScaleRowViewModel)context.DataItem; + + + + } + + + + + + + + + + + @if (this.ShouldCreateThing) + { + + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @if (this.ViewModel.Thing is CyclicRatioScale ciclicRatioScale) + { + + + + + } + + @if (this.ViewModel.Thing is OrdinalScale ordinalScale) + { + + + + + } + + + + + + + + + + + + + + + + + + + + + @this.ViewModel.PopupDialog +
+ + +
+
\ No newline at end of file diff --git a/COMETwebapp/Components/ReferenceData/MeasurementScalesTable.razor.cs b/COMETwebapp/Components/ReferenceData/MeasurementScales/MeasurementScalesTable.razor.cs similarity index 84% rename from COMETwebapp/Components/ReferenceData/MeasurementScalesTable.razor.cs rename to COMETwebapp/Components/ReferenceData/MeasurementScales/MeasurementScalesTable.razor.cs index 7fb378c7..a7f9e1d0 100644 --- a/COMETwebapp/Components/ReferenceData/MeasurementScalesTable.razor.cs +++ b/COMETwebapp/Components/ReferenceData/MeasurementScales/MeasurementScalesTable.razor.cs @@ -22,7 +22,7 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMETwebapp.Components.ReferenceData +namespace COMETwebapp.Components.ReferenceData.MeasurementScales { using System.Threading.Tasks; @@ -61,15 +61,9 @@ protected override void OnInitialized() /// Method that is invoked when the edit/add thing form is being saved /// /// A - protected override Task OnEditThingSaving() + protected override async Task OnEditThingSaving() { - if (!this.ShouldCreateThing) - { - // update measurement scale - } - - // create measurement scale - return Task.CompletedTask; + await this.ViewModel.CreateOrEditMeasurementScale(this.ShouldCreateThing); } /// @@ -80,16 +74,8 @@ protected override void CustomizeEditThing(GridCustomizeEditModelEventArgs e) { var dataItem = (MeasurementScaleRowViewModel)e.DataItem; this.ShouldCreateThing = e.IsNew; - - if (dataItem == null) - { - e.EditModel = new OrdinalScale(); - this.ViewModel.Thing = new OrdinalScale(); - return; - } - - e.EditModel = dataItem; - this.ViewModel.Thing = dataItem.Thing.Clone(true); + this.ViewModel.SelectMeasurementScale(dataItem == null ? new OrdinalScale() : dataItem.Thing.Clone(true)); + e.EditModel = this.ViewModel.Thing; } } } diff --git a/COMETwebapp/Components/ReferenceData/MeasurementScales/ScaleValueDefinitionsTable.razor b/COMETwebapp/Components/ReferenceData/MeasurementScales/ScaleValueDefinitionsTable.razor new file mode 100644 index 00000000..db353c80 --- /dev/null +++ b/COMETwebapp/Components/ReferenceData/MeasurementScales/ScaleValueDefinitionsTable.razor @@ -0,0 +1,64 @@ + + + + + + + + + + + + + @{ + var row = (ScaleValueDefinitionRowViewModel)context.DataItem; + + + + + } + + + + + + + + + + + + + + + + + +
+ +
+
diff --git a/COMETwebapp/Components/ReferenceData/MeasurementScales/ScaleValueDefinitionsTable.razor.cs b/COMETwebapp/Components/ReferenceData/MeasurementScales/ScaleValueDefinitionsTable.razor.cs new file mode 100644 index 00000000..02be374b --- /dev/null +++ b/COMETwebapp/Components/ReferenceData/MeasurementScales/ScaleValueDefinitionsTable.razor.cs @@ -0,0 +1,128 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023-2024 RHEA System 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 RHEA 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.Components.ReferenceData.MeasurementScales +{ + using CDP4Common.SiteDirectoryData; + + using COMETwebapp.ViewModels.Components.ReferenceData.Rows; + + using DevExpress.Blazor; + + using DynamicData; + + using Microsoft.AspNetCore.Components; + + /// + /// Support class for the + /// + public partial class ScaleValueDefinitionsTable + { + /// + /// A collection of scale value definitions to display for selection + /// + [Parameter] + public IEnumerable ScaleValueDefinitions { get; set; } + + /// + /// The method that is executed when the scale value definitions change + /// + [Parameter] + public EventCallback> ScaleValueDefinitionsChanged { get; set; } + + /// + /// Gets or sets the condition to check if a scale value definition should be created + /// + public bool ShouldCreate { get; private set; } + + /// + /// The scale value definition that will be handled for both edit and add forms + /// + private ScaleValueDefinition ScaleValueDefinition { get; set; } = new(); + + /// + /// Gets or sets the grid control that is being customized. + /// + private IGrid Grid { get; set; } + + /// + /// Method that is invoked when the edit/add scale value definition form is being saved + /// + private void OnEditScaleValueDefinitionSaving() + { + var valueDefinitionsList = this.ScaleValueDefinitions.ToList(); + + if (this.ShouldCreate) + { + valueDefinitionsList.Add(this.ScaleValueDefinition); + this.ScaleValueDefinitions = valueDefinitionsList; + } + else + { + var indexToUpdate = valueDefinitionsList.FindIndex(x => x.Iid == this.ScaleValueDefinition.Iid); + valueDefinitionsList[indexToUpdate] = this.ScaleValueDefinition; + } + + this.ScaleValueDefinitions = valueDefinitionsList; + this.ScaleValueDefinitionsChanged.InvokeAsync(this.ScaleValueDefinitions); + } + + /// + /// Method that is invoked when a scale value definition row is being removed + /// + private void RemoveScaleValueDefinition(ScaleValueDefinitionRowViewModel row) + { + var valueDefinitionsList = this.ScaleValueDefinitions.ToList(); + valueDefinitionsList.Remove(row.Thing); + + this.ScaleValueDefinitions = valueDefinitionsList; + this.ScaleValueDefinitionsChanged.InvokeAsync(this.ScaleValueDefinitions); + } + + /// + /// Method invoked when creating a new scale value definition + /// + /// A + private void CustomizeEditScaleValueDefinition(GridCustomizeEditModelEventArgs e) + { + var dataItem = (ScaleValueDefinitionRowViewModel)e.DataItem; + this.ShouldCreate = e.IsNew; + + this.ScaleValueDefinition = dataItem == null + ? new ScaleValueDefinition() { Iid = Guid.NewGuid() } + : dataItem.Thing.Clone(true); + + e.EditModel = this.ScaleValueDefinition; + } + + /// + /// Method used to retrieve the available rows, given the + /// + /// A collection of s to display + private List GetRows() + { + return this.ScaleValueDefinitions.Select(x => new ScaleValueDefinitionRowViewModel(x)).ToList(); + } + } +} diff --git a/COMETwebapp/Components/ReferenceData/MeasurementScalesTable.razor b/COMETwebapp/Components/ReferenceData/MeasurementScalesTable.razor deleted file mode 100644 index 20e18865..00000000 --- a/COMETwebapp/Components/ReferenceData/MeasurementScalesTable.razor +++ /dev/null @@ -1,118 +0,0 @@ - -@using COMETwebapp.ViewModels.Components.ReferenceData.Rows -@using CDP4Common.SiteDirectoryData -@inherits COMETwebapp.Components.Common.SelectedDeprecatableDataItemBase - - - - - - - - - - - - - - - - - @{ - var row = (MeasurementScaleRowViewModel)context.DataItem; - - - - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @this.ViewModel.PopupDialog -
- - -
-
\ No newline at end of file diff --git a/COMETwebapp/Pages/ReferenceData/ReferenceDataPage.razor.cs b/COMETwebapp/Pages/ReferenceData/ReferenceDataPage.razor.cs index 47a1059e..20521d60 100644 --- a/COMETwebapp/Pages/ReferenceData/ReferenceDataPage.razor.cs +++ b/COMETwebapp/Pages/ReferenceData/ReferenceDataPage.razor.cs @@ -25,6 +25,7 @@ namespace COMETwebapp.Pages.ReferenceData { using COMETwebapp.Components.ReferenceData; + using COMETwebapp.Components.ReferenceData.MeasurementScales; using DevExpress.Blazor; diff --git a/COMETwebapp/ViewModels/Components/Common/Rows/BaseDataItemRowViewModel.cs b/COMETwebapp/ViewModels/Components/Common/Rows/BaseDataItemRowViewModel.cs index d255f865..a2362197 100644 --- a/COMETwebapp/ViewModels/Components/Common/Rows/BaseDataItemRowViewModel.cs +++ b/COMETwebapp/ViewModels/Components/Common/Rows/BaseDataItemRowViewModel.cs @@ -57,7 +57,7 @@ protected BaseDataItemRowViewModel(T thing) this.Thing = thing; this.ShortName = thing is IShortNamedThing shortNamedThing ? shortNamedThing.ShortName : thing.UserFriendlyShortName; this.Name = thing is INamedThing namedThing ? namedThing.Name : thing.UserFriendlyName; - this.ContainerName = thing.Container is IShortNamedThing shortNamedContainer ? shortNamedContainer.ShortName : thing.Container.UserFriendlyShortName; + this.ContainerName = thing.Container is IShortNamedThing shortNamedContainer ? shortNamedContainer.ShortName : thing.Container?.UserFriendlyShortName; } /// diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementScales/IMeasurementScalesTableViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementScales/IMeasurementScalesTableViewModel.cs index c29ac99d..17d1633b 100644 --- a/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementScales/IMeasurementScalesTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementScales/IMeasurementScalesTableViewModel.cs @@ -28,6 +28,7 @@ namespace COMETwebapp.ViewModels.Components.ReferenceData.MeasurementScales using COMETwebapp.ViewModels.Components.Common.DeprecatableDataItemTable; using COMETwebapp.ViewModels.Components.ReferenceData.Rows; + using COMETwebapp.Wrappers; /// /// View model used to manage s @@ -48,5 +49,48 @@ public interface IMeasurementScalesTableViewModel : IDeprecatableDataItemTableVi /// Gets the available s /// IEnumerable NumberSetKinds { get; } + + /// + /// Gets the available measurement scale types s + /// + IEnumerable MeasurementScaleTypes { get; } + + /// + /// Gets or sets the selected measurement scale type + /// + ClassKindWrapper SelectedMeasurementScaleType { get; set; } + + /// + /// Gets the selected s + /// + IEnumerable SelectedScaleValueDefinitions { get; set; } + + /// + /// Gets or sets the selected reference data library + /// + ReferenceDataLibrary SelectedReferenceDataLibrary { get; set; } + + /// + /// Gets the selected s + /// + IEnumerable SelectedMappingToReferenceScale { get; set; } + + /// + /// Gets the available s for reference scale value selection + /// + IEnumerable ReferenceScaleValueDefinitions { get; } + + /// + /// Selects the current + /// + /// The measurement scale to be set + void SelectMeasurementScale(MeasurementScale measurementScale); + + /// + /// Creates or edits a + /// + /// The value to check if a new should be created + /// A + Task CreateOrEditMeasurementScale(bool shouldCreate); } } diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementScales/MeasurementScalesTableViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementScales/MeasurementScalesTableViewModel.cs index 5ed8089c..395a1c71 100644 --- a/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementScales/MeasurementScalesTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementScales/MeasurementScalesTableViewModel.cs @@ -24,6 +24,7 @@ namespace COMETwebapp.ViewModels.Components.ReferenceData.MeasurementScales { + using CDP4Common.CommonData; using CDP4Common.SiteDirectoryData; using CDP4Dal; @@ -33,6 +34,11 @@ namespace COMETwebapp.ViewModels.Components.ReferenceData.MeasurementScales using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.Common.DeprecatableDataItemTable; using COMETwebapp.ViewModels.Components.ReferenceData.Rows; + using COMETwebapp.Wrappers; + + using DynamicData; + + using ReactiveUI; using MeasurementScale = CDP4Common.SiteDirectoryData.MeasurementScale; @@ -41,6 +47,19 @@ namespace COMETwebapp.ViewModels.Components.ReferenceData.MeasurementScales /// public class MeasurementScalesTableViewModel : DeprecatableDataItemTableViewModel, IMeasurementScalesTableViewModel { + /// + /// The backing field for + /// + private ClassKindWrapper selectedMeasurementScaleType; + + /// + /// Gets the available s + /// + private static readonly IEnumerable AvailableMeasurementScaleTypes = + [ + ClassKind.CyclicRatioScale, ClassKind.IntervalScale, ClassKind.LogarithmicScale, ClassKind.OrdinalScale, ClassKind.RatioScale + ]; + /// /// Initializes a new instance of the class. /// @@ -51,6 +70,7 @@ public class MeasurementScalesTableViewModel : DeprecatableDataItemTableViewMode public MeasurementScalesTableViewModel(ISessionService sessionService, IShowHideDeprecatedThingsService showHideDeprecatedThingsService, ICDPMessageBus messageBus, ILogger logger) : base(sessionService, messageBus, showHideDeprecatedThingsService, logger) { + this.Thing = new OrdinalScale(); } /// @@ -58,23 +78,139 @@ public MeasurementScalesTableViewModel(ISessionService sessionService, IShowHide /// public IEnumerable ReferenceDataLibraries { get; private set; } + /// + /// Gets the available s for reference scale value selection + /// + public IEnumerable ReferenceScaleValueDefinitions => this.SelectedReferenceDataLibrary?.Scale + .SelectMany(x => x.ValueDefinition) + .Where(x => this.SelectedScaleValueDefinitions.All(selected => selected.ShortName != x.ShortName)); + /// /// Gets the available s /// - public IEnumerable MeasurementUnits { get; private set; } + public IEnumerable MeasurementUnits => this.SelectedReferenceDataLibrary?.QueryMeasurementUnitsFromChainOfRdls(); + + /// + /// Gets the available measurement scale types s + /// + public IEnumerable MeasurementScaleTypes { get; private set; } = AvailableMeasurementScaleTypes.Select(x => new ClassKindWrapper(x)); /// /// Gets the available s /// public IEnumerable NumberSetKinds { get; private set; } = Enum.GetValues(); + /// + /// Gets or sets the selected reference data library + /// + public ReferenceDataLibrary SelectedReferenceDataLibrary { get; set; } + + /// + /// Gets the selected s + /// + public IEnumerable SelectedScaleValueDefinitions { get; set; } + + /// + /// Gets the selected s + /// + public IEnumerable SelectedMappingToReferenceScale { get; set; } + + /// + /// Gets or sets the selected measurement scale type + /// + public ClassKindWrapper SelectedMeasurementScaleType + { + get => this.selectedMeasurementScaleType; + set + { + this.SelectMeasurementScaleType(value); + this.RaiseAndSetIfChanged(ref this.selectedMeasurementScaleType, value); + } + } + + /// + /// Selects the current + /// + /// The measurement scale to be set + public void SelectMeasurementScale(MeasurementScale measurementScale) + { + this.Thing = measurementScale; + + this.SelectedScaleValueDefinitions = measurementScale.ValueDefinition; + this.SelectedMappingToReferenceScale = measurementScale.MappingToReferenceScale; + this.SelectedReferenceDataLibrary = (ReferenceDataLibrary)measurementScale.Container ?? this.ReferenceDataLibraries.FirstOrDefault(); + } + /// /// Initializes the /// public override void InitializeViewModel() { base.InitializeViewModel(); - this.ReferenceDataLibraries = this.SessionService.Session.RetrieveSiteDirectory().AvailableReferenceDataLibraries(); + + this.ReferenceDataLibraries = this.SessionService + .GetSiteDirectory() + .AvailableReferenceDataLibraries() + .Where(x => x.Unit.Count > 0); + + this.SelectedReferenceDataLibrary = this.ReferenceDataLibraries.FirstOrDefault(); + this.SelectedMeasurementScaleType = this.MeasurementScaleTypes.First(); + } + + /// + /// Creates or edits a + /// + /// The value to check if a new should be created + /// A + public async Task CreateOrEditMeasurementScale(bool shouldCreate) + { + var hasRdlChanged = this.SelectedReferenceDataLibrary != this.Thing.Container; + var rdlClone = this.SelectedReferenceDataLibrary.Clone(false); + var thingsToCreate = new List(); + + if (shouldCreate || hasRdlChanged) + { + rdlClone.Scale.Add(this.Thing); + thingsToCreate.Add(rdlClone); + } + + var scaleValueDefinitionsToCreate = this.SelectedScaleValueDefinitions.Where(x => !this.Thing.ValueDefinition.Contains(x)).ToList(); + this.Thing.ValueDefinition.AddRange(scaleValueDefinitionsToCreate); + thingsToCreate.AddRange(scaleValueDefinitionsToCreate); + + var scaleValueDefinitionsToRemove = this.Thing.ValueDefinition.Where(x => !this.SelectedScaleValueDefinitions.Contains(x)).ToList(); + this.Thing.ValueDefinition.RemoveMany(scaleValueDefinitionsToRemove); + thingsToCreate.AddRange(scaleValueDefinitionsToRemove); + + var mappingToReferenceScalesToCreate = this.SelectedMappingToReferenceScale.Where(x => !this.Thing.MappingToReferenceScale.Contains(x)).ToList(); + this.Thing.MappingToReferenceScale.AddRange(mappingToReferenceScalesToCreate); + thingsToCreate.AddRange(mappingToReferenceScalesToCreate); + + var mappingToReferenceScalesToRemove = this.Thing.MappingToReferenceScale.Where(x => !this.SelectedMappingToReferenceScale.Contains(x)).ToList(); + this.Thing.MappingToReferenceScale.RemoveMany(mappingToReferenceScalesToRemove); + thingsToCreate.AddRange(mappingToReferenceScalesToRemove); + + thingsToCreate.Add(this.Thing); + + var result = await this.SessionService.CreateOrUpdateThings(rdlClone, thingsToCreate); + await this.SessionService.RefreshSession(); + } + + /// + /// Selects a new measurement scale type for the attribute + /// + /// The new kind to which the will be set + private void SelectMeasurementScaleType(ClassKindWrapper newKind) + { + this.Thing = newKind.ClassKind switch + { + ClassKind.CyclicRatioScale => new CyclicRatioScale(), + ClassKind.IntervalScale => new IntervalScale(), + ClassKind.LogarithmicScale => new LogarithmicScale(), + ClassKind.OrdinalScale => new OrdinalScale(), + ClassKind.RatioScale => new RatioScale(), + _ => this.Thing + }; } } } diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementUnits/MeasurementUnitsTableViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementUnits/MeasurementUnitsTableViewModel.cs index 78bd7dbe..30525aa6 100644 --- a/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementUnits/MeasurementUnitsTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ReferenceData/MeasurementUnits/MeasurementUnitsTableViewModel.cs @@ -51,7 +51,7 @@ public class MeasurementUnitsTableViewModel : DeprecatableDataItemTableViewModel private ClassKindWrapper selectedMeasurementUnitType; /// - /// FGets the available s + /// Gets the available s /// private static readonly IEnumerable AvailableMeasurementUnitTypes = [ClassKind.SimpleUnit, ClassKind.DerivedUnit, ClassKind.LinearConversionUnit, ClassKind.PrefixedUnit]; diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/Rows/MappingToReferenceScaleRowViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/Rows/MappingToReferenceScaleRowViewModel.cs new file mode 100644 index 00000000..272d136e --- /dev/null +++ b/COMETwebapp/ViewModels/Components/ReferenceData/Rows/MappingToReferenceScaleRowViewModel.cs @@ -0,0 +1,109 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, João Rua +// +// This file is part of CDP4-COMET WEB Community Edition +// The CDP4-COMET WEB Community Edition is the RHEA 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.ViewModels.Components.ReferenceData.Rows +{ + using CDP4Common.SiteDirectoryData; + + using ReactiveUI; + + /// + /// Row View Model for s + /// + public class MappingToReferenceScaleRowViewModel : ReactiveObject + { + /// + /// Backing field for + /// + private string reference; + + /// + /// Backing field for + /// + private string referenceValue; + + /// + /// Backing field for + /// + private string dependent; + + /// + /// Backing field for + /// + private string dependentValue; + + /// + /// Initializes a new instance of the class. + /// + /// The associated + public MappingToReferenceScaleRowViewModel(MappingToReferenceScale mappingToReferenceScale) + { + this.Reference = mappingToReferenceScale.ReferenceScaleValue.ShortName; + this.ReferenceValue = mappingToReferenceScale.ReferenceScaleValue.Value; + this.Dependent = mappingToReferenceScale.DependentScaleValue.ShortName; + this.DependentValue = mappingToReferenceScale.DependentScaleValue.Value; + } + + /// + /// Gets or sets the row's + /// + public MappingToReferenceScale MappingToReferenceScale { get; set; } + + /// + /// The reference of the + /// + public string Reference + { + get => this.reference; + set => this.RaiseAndSetIfChanged(ref this.reference, value); + } + + /// + /// The reference value of the + /// + public string ReferenceValue + { + get => this.referenceValue; + set => this.RaiseAndSetIfChanged(ref this.referenceValue, value); + } + + /// + /// The dependent of the + /// + public string Dependent + { + get => this.dependent; + set => this.RaiseAndSetIfChanged(ref this.dependent, value); + } + + /// + /// The dependent value of the + /// + public string DependentValue + { + get => this.dependentValue; + set => this.RaiseAndSetIfChanged(ref this.dependentValue, value); + } + } +} diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/Rows/ScaleValueDefinitionRowViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/Rows/ScaleValueDefinitionRowViewModel.cs new file mode 100644 index 00000000..164e7356 --- /dev/null +++ b/COMETwebapp/ViewModels/Components/ReferenceData/Rows/ScaleValueDefinitionRowViewModel.cs @@ -0,0 +1,61 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, João Rua +// +// This file is part of CDP4-COMET WEB Community Edition +// The CDP4-COMET WEB Community Edition is the RHEA 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.ViewModels.Components.ReferenceData.Rows +{ + using CDP4Common.SiteDirectoryData; + + using COMETwebapp.ViewModels.Components.Common.Rows; + + using ReactiveUI; + + /// + /// Row View Model for s + /// + public class ScaleValueDefinitionRowViewModel : BaseDataItemRowViewModel + { + /// + /// Backing field for + /// + private string value; + + /// + /// Initializes a new instance of the class. + /// + /// The associated + public ScaleValueDefinitionRowViewModel(ScaleValueDefinition scaleValueDefinition) : base(scaleValueDefinition) + { + this.Value = scaleValueDefinition.Value; + } + + /// + /// The value of the + /// + public string Value + { + get => this.value; + set => this.RaiseAndSetIfChanged(ref this.value, value); + } + } +} diff --git a/COMETwebapp/_Imports.razor b/COMETwebapp/_Imports.razor index f39e2a67..4231c982 100644 --- a/COMETwebapp/_Imports.razor +++ b/COMETwebapp/_Imports.razor @@ -31,6 +31,7 @@ @using COMETwebapp.Components.SystemRepresentation @using COMETwebapp.Components.Viewer.PropertiesPanel @using COMETwebapp.ViewModels.Components.SiteDirectory.Rows +@using COMETwebapp.ViewModels.Components.ReferenceData.Rows @using COMETwebapp.ViewModels.Components.EngineeringModel.Rows @using BlazorStrap @using DevExpress.Blazor