From 870e28c1bd85375a3ab12cd6990e0b7df7b0ac7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rua?= <140734849+joao4all@users.noreply.github.com> Date: Wed, 29 May 2024 13:35:59 +0100 Subject: [PATCH] Fix #627 [Model Editor] Panel Editor - add Parameter and add Element Definition improvements (#649) --- .../Selectors/DomainOfExpertiseSelector.razor | 6 +- .../DomainOfExpertiseSelector.razor.cs | 10 --- .../Selectors/MeasurementScaleSelector.razor | 35 +++++++++ .../MeasurementScaleSelector.razor.cs | 44 +++++++++++ .../Selectors/ParameterTypeSelector.razor | 22 +++--- .../Selectors/ParameterTypeSelector.razor.cs | 6 ++ .../Extensions/ThingExtensions.cs | 10 +++ .../Selectors/SelectorModelBaseWrapper.cs | 55 ++++++++++++++ .../DomainOfExpertiseSelectorViewModel.cs | 2 +- .../IMeasurementScaleSelectorViewModel.cs | 51 +++++++++++++ .../IParameterTypeSelectorViewModel.cs | 6 ++ .../MeasurementScaleSelectorViewModel.cs | 76 +++++++++++++++++++ .../ParameterTypeSelectorViewModel.cs | 67 +++++++++++----- .../AddParameterViewModelTestFixture.cs | 8 +- ...mentDefinitionTableViewModelTestFixture.cs | 4 + .../Components/ModelEditor/AddParameter.razor | 11 ++- .../ElementDefinitionCreation.razor | 12 +-- .../ElementDefinitionCreation.razor.cs | 2 - .../ModelEditor/ElementDefinitionTable.razor | 4 +- .../AddParameterViewModel.cs | 56 ++++++++------ .../IAddParameterViewModel.cs | 11 ++- .../ElementDefinitionCreationViewModel.cs | 3 + 22 files changed, 415 insertions(+), 86 deletions(-) create mode 100644 COMET.Web.Common/Components/Selectors/MeasurementScaleSelector.razor create mode 100644 COMET.Web.Common/Components/Selectors/MeasurementScaleSelector.razor.cs create mode 100644 COMET.Web.Common/Model/Selectors/SelectorModelBaseWrapper.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Selectors/IMeasurementScaleSelectorViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Selectors/MeasurementScaleSelectorViewModel.cs diff --git a/COMET.Web.Common/Components/Selectors/DomainOfExpertiseSelector.razor b/COMET.Web.Common/Components/Selectors/DomainOfExpertiseSelector.razor index d7f59370..c91fdd61 100644 --- a/COMET.Web.Common/Components/Selectors/DomainOfExpertiseSelector.razor +++ b/COMET.Web.Common/Components/Selectors/DomainOfExpertiseSelector.razor @@ -20,6 +20,7 @@ // limitations under the License. -------------------------------------------------------------------------------> @namespace COMET.Web.Common.Components.Selectors +@using COMET.Web.Common.Extensions @if (this.ViewModel.SessionService != null) { @@ -33,17 +34,18 @@ FilteringMode="DataGridFilteringMode.Contains" ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Never" NullText="Select a Domain Of Expertise" + AllowUserInput="true" CssClass="@(this.CssClass)">
- @GetDomainNameAndShortnameToDisplay(domainOfExpertise) + @(domainOfExpertise.GetSelectorNameAndShortname())
@if (domainOfExpertise != null) {
- @GetDomainNameAndShortnameToDisplay(domainOfExpertise) + @(domainOfExpertise.GetSelectorNameAndShortname())
}
diff --git a/COMET.Web.Common/Components/Selectors/DomainOfExpertiseSelector.razor.cs b/COMET.Web.Common/Components/Selectors/DomainOfExpertiseSelector.razor.cs index 0d953b94..cf83c2d2 100644 --- a/COMET.Web.Common/Components/Selectors/DomainOfExpertiseSelector.razor.cs +++ b/COMET.Web.Common/Components/Selectors/DomainOfExpertiseSelector.razor.cs @@ -52,15 +52,5 @@ public partial class DomainOfExpertiseSelector /// [Parameter] public string CssClass { get; set; } - - /// - /// Gets the domain and shortname to display, in the following format: name [shortname] - /// - /// The domain of expertise to get the name and shortname - /// A string that contains name and shortname - private static string GetDomainNameAndShortnameToDisplay(DomainOfExpertise domainOfExpertise) - { - return $"{domainOfExpertise.Name} [{domainOfExpertise.ShortName}]"; - } } } diff --git a/COMET.Web.Common/Components/Selectors/MeasurementScaleSelector.razor b/COMET.Web.Common/Components/Selectors/MeasurementScaleSelector.razor new file mode 100644 index 00000000..21e54827 --- /dev/null +++ b/COMET.Web.Common/Components/Selectors/MeasurementScaleSelector.razor @@ -0,0 +1,35 @@ + +@namespace COMET.Web.Common.Components.Selectors +@using COMET.Web.Common.Model.Selectors +@using CDP4Common.SiteDirectoryData +@inherits DisposableComponent + + diff --git a/COMET.Web.Common/Components/Selectors/MeasurementScaleSelector.razor.cs b/COMET.Web.Common/Components/Selectors/MeasurementScaleSelector.razor.cs new file mode 100644 index 00000000..ca952602 --- /dev/null +++ b/COMET.Web.Common/Components/Selectors/MeasurementScaleSelector.razor.cs @@ -0,0 +1,44 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Components.Selectors +{ + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.ViewModels.Components.Selectors; + + using Microsoft.AspNetCore.Components; + + /// + /// Component used to select a + /// + public partial class MeasurementScaleSelector : DisposableComponent + { + /// + /// Gets or sets the + /// + [Parameter] + public IMeasurementScaleSelectorViewModel ViewModel { get; set; } + } +} diff --git a/COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor b/COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor index 6148b895..7edaef2b 100644 --- a/COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor +++ b/COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor @@ -1,7 +1,7 @@  @namespace COMET.Web.Common.Components.Selectors - +@using COMET.Web.Common.Extensions @using CDP4Common.SiteDirectoryData +@using COMET.Web.Common.Model.Selectors @inherits BelongsToIterationSelector @if (this.ViewModel.CurrentIteration != null) @@ -30,11 +31,14 @@ {
@(this.DisplayText)
} - + + } \ No newline at end of file diff --git a/COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor.cs b/COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor.cs index f8ae2a19..2e47ab54 100644 --- a/COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor.cs +++ b/COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor.cs @@ -38,5 +38,11 @@ public partial class ParameterTypeSelector /// [Parameter] public string DisplayText { get; set; } = "Filter on Parameter Type:"; + + /// + /// Condition to check if name and shortname shall be displayed in the selector. If false, only the name is displayed + /// + [Parameter] + public bool DisplayNameAndShortname { get; set; } } } diff --git a/COMET.Web.Common/Extensions/ThingExtensions.cs b/COMET.Web.Common/Extensions/ThingExtensions.cs index 066bef4f..ab0d79b1 100644 --- a/COMET.Web.Common/Extensions/ThingExtensions.cs +++ b/COMET.Web.Common/Extensions/ThingExtensions.cs @@ -570,5 +570,15 @@ public static string GetShortNameOrName(this Thing thing) return thingDesignation; } + + /// + /// Gets the thing and shortname to display, in the following format: name [shortname] + /// + /// The thing to get the name and shortname + /// A string that contains name and shortname + internal static string GetSelectorNameAndShortname(this DefinedThing thing) + { + return $"{thing.Name} [{thing.ShortName}]"; + } } } diff --git a/COMET.Web.Common/Model/Selectors/SelectorModelBaseWrapper.cs b/COMET.Web.Common/Model/Selectors/SelectorModelBaseWrapper.cs new file mode 100644 index 00000000..589c4898 --- /dev/null +++ b/COMET.Web.Common/Model/Selectors/SelectorModelBaseWrapper.cs @@ -0,0 +1,55 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Model.Selectors +{ + using CDP4Common.CommonData; + + using COMET.Web.Common.Extensions; + + /// + /// The wrapper to be used to display and select data in the + /// + public class SelectorModelBaseWrapper where T : DefinedThing + { + /// + /// Creates a new instance of the + /// + /// The thing to be wrapped + public SelectorModelBaseWrapper(T thing) + { + this.WrappedThing = thing; + } + + /// + /// The thing to be selected + /// + public T WrappedThing { get; set; } + + /// + /// The text to display for thing selection + /// + public string DisplayText => this.WrappedThing?.GetSelectorNameAndShortname(); + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/DomainOfExpertiseSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/DomainOfExpertiseSelectorViewModel.cs index 77419cb0..011f6074 100644 --- a/COMET.Web.Common/ViewModels/Components/Selectors/DomainOfExpertiseSelectorViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Selectors/DomainOfExpertiseSelectorViewModel.cs @@ -55,7 +55,7 @@ public class DomainOfExpertiseSelectorViewModel : BelongsToIterationSelectorView public DomainOfExpertiseSelectorViewModel(ISessionService sessionService, ICDPMessageBus messageBus) { this.SessionService = sessionService; - this.AvailableDomainsOfExpertise = sessionService.GetSiteDirectory().Domain.OrderBy(x => x.Name); + this.AvailableDomainsOfExpertise = sessionService.GetSiteDirectory().Domain.OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase); this.Disposables.Add(this.WhenAnyValue(x => x.SelectedDomainOfExpertise).SubscribeAsync(async domain => await this.OnSelectedDomainOfExpertiseChange.InvokeAsync(domain))); this.Disposables.Add(messageBus.Listen().Subscribe(this.OnDomainChanged)); diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/IMeasurementScaleSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/IMeasurementScaleSelectorViewModel.cs new file mode 100644 index 00000000..4292b1a3 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Selectors/IMeasurementScaleSelectorViewModel.cs @@ -0,0 +1,51 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Selectors +{ + using CDP4Common.SiteDirectoryData; + + using Microsoft.AspNetCore.Components; + + /// + /// View Model that enables the user to select a + /// + public interface IMeasurementScaleSelectorViewModel + { + /// + /// Gets or sets the callback that is executed when the property has changed + /// + EventCallback OnSelectedMeasurementScaleChange { get; set; } + + /// + /// A collection of available + /// + IEnumerable AvailableMeasurementScales { get; set; } + + /// + /// The currently selected + /// + MeasurementScale SelectedMeasurementScale { get; set; } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/IParameterTypeSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/IParameterTypeSelectorViewModel.cs index a0d2b7bb..f8eaf623 100644 --- a/COMET.Web.Common/ViewModels/Components/Selectors/IParameterTypeSelectorViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Selectors/IParameterTypeSelectorViewModel.cs @@ -47,5 +47,11 @@ public interface IParameterTypeSelectorViewModel : IBelongsToIterationSelectorVi /// /// A collection of for void FilterAvailableParameterTypes(IEnumerable parameterTypesId); + + /// + /// Excludes a collection of s from the + /// + /// A collection of for + void ExcludeAvailableParameterTypes(IEnumerable parameterTypesId); } } diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/MeasurementScaleSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/MeasurementScaleSelectorViewModel.cs new file mode 100644 index 00000000..e6f0455e --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Selectors/MeasurementScaleSelectorViewModel.cs @@ -0,0 +1,76 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Selectors +{ + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.Extensions; + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.Utilities.DisposableObject; + + using Microsoft.AspNetCore.Components; + + using ReactiveUI; + + /// + /// View Model that enables the user to select a + /// + public class MeasurementScaleSelectorViewModel : DisposableObject, IMeasurementScaleSelectorViewModel + { + /// + /// Backing field for + /// + private MeasurementScale selectedDomainOfExpertise; + + /// + /// Creates a new instance of + /// + /// The + public MeasurementScaleSelectorViewModel(ISessionService sessionService) + { + this.AvailableMeasurementScales = sessionService.GetSiteDirectory().AvailableReferenceDataLibraries().SelectMany(x => x.Scale).OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase); + this.Disposables.Add(this.WhenAnyValue(x => x.SelectedMeasurementScale).SubscribeAsync(this.OnSelectedMeasurementScaleChange.InvokeAsync)); + } + + /// + /// Gets or sets the callback that is executed when the property has changed + /// + public EventCallback OnSelectedMeasurementScaleChange { get; set; } + + /// + /// A collection of available + /// + public IEnumerable AvailableMeasurementScales { get; set; } + + /// + /// The currently selected + /// + public MeasurementScale SelectedMeasurementScale + { + get => this.selectedDomainOfExpertise; + set => this.RaiseAndSetIfChanged(ref this.selectedDomainOfExpertise, value); + } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/ParameterTypeSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/ParameterTypeSelectorViewModel.cs index bc7e7b7b..08fceeaa 100644 --- a/COMET.Web.Common/ViewModels/Components/Selectors/ParameterTypeSelectorViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Selectors/ParameterTypeSelectorViewModel.cs @@ -1,30 +1,30 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2023-2024 Starion Group S.A. +// Copyright (c) 2024 Starion Group S.A. // -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// 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. +// 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. // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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. // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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 . // // -------------------------------------------------------------------------------------------------------------------- namespace COMET.Web.Common.ViewModels.Components.Selectors { + using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; using ReactiveUI; @@ -44,6 +44,12 @@ public class ParameterTypeSelectorViewModel : BelongsToIterationSelectorViewMode /// private ParameterType selectedParameterType; + /// + /// Gets or sets the value to check if only the parameter types used in the current should be + /// queried + /// + public bool QueryOnlyUsedParameterTypes { get; set; } = true; + /// /// The currently selected /// @@ -59,7 +65,8 @@ public ParameterType SelectedParameterType public IEnumerable AvailableParameterTypes { get; private set; } = Enumerable.Empty(); /// - /// Filter the collection of the with provided values + /// Filter the collection of the with provided + /// values /// /// A collection of for public void FilterAvailableParameterTypes(IEnumerable parameterTypesId) @@ -68,13 +75,39 @@ public void FilterAvailableParameterTypes(IEnumerable parameterTypesId) this.SelectedParameterType = this.AvailableParameterTypes.FirstOrDefault(x => x.Iid == this.SelectedParameterType?.Iid); } + /// + /// Excludes a collection of s from the + /// + /// A collection of for + public void ExcludeAvailableParameterTypes(IEnumerable parameterTypesId) + { + this.AvailableParameterTypes = this.allAvailableParameterTypes.Where(x => !parameterTypesId.Contains(x.Iid)); + } + /// /// Updates this view model properties /// protected override void UpdateProperties() { this.SelectedParameterType = null; - this.allAvailableParameterTypes = this.CurrentIteration?.QueryUsedParameterTypes().OrderBy(x => x.Name) ?? Enumerable.Empty(); + IEnumerable parameterTypes; + + if (this.QueryOnlyUsedParameterTypes) + { + parameterTypes = this.CurrentIteration? + .QueryUsedParameterTypes() + .OrderBy(x => x.Name) ?? Enumerable.Empty(); + } + else + { + var siteDirectory = this.CurrentIteration.IterationSetup.GetContainerOfType(); + + parameterTypes = siteDirectory + .AvailableReferenceDataLibraries() + .SelectMany(x => x.ParameterType); + } + + this.allAvailableParameterTypes = parameterTypes.OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase); this.AvailableParameterTypes = new List(this.allAvailableParameterTypes); } } diff --git a/COMETwebapp.Tests/ViewModels/Components/ModelEditor/AddParameterViewModelTestFixture.cs b/COMETwebapp.Tests/ViewModels/Components/ModelEditor/AddParameterViewModelTestFixture.cs index 4d9f94a6..e641dbf9 100644 --- a/COMETwebapp.Tests/ViewModels/Components/ModelEditor/AddParameterViewModelTestFixture.cs +++ b/COMETwebapp.Tests/ViewModels/Components/ModelEditor/AddParameterViewModelTestFixture.cs @@ -99,6 +99,10 @@ public void Setup() { ActiveDomain = { this.domain } } + }, + IterationSetup = new IterationSetup() + { + Container = new SiteDirectory() } }; @@ -120,7 +124,7 @@ public async Task VerifyAddParameter() Assert.Multiple(() => { this.sessionService.Verify(x => x.CreateOrUpdateThings(It.IsAny(), It.Is>(c => c.Count == 2)), Times.Once); - Assert.That(this.viewModel.MeasurementScales, Is.Empty); + Assert.That(this.viewModel.MeasurementScaleSelectorViewModel.AvailableMeasurementScales, Is.Empty); }); this.viewModel.ParameterTypeSelectorViewModel.SelectedParameterType = new SimpleQuantityKind @@ -128,7 +132,7 @@ public async Task VerifyAddParameter() PossibleScale = { new OrdinalScale() } }; - Assert.That(this.viewModel.MeasurementScales, Is.Not.Empty); + Assert.That(this.viewModel.MeasurementScaleSelectorViewModel.AvailableMeasurementScales, Is.Not.Empty); } [Test] diff --git a/COMETwebapp.Tests/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModelTestFixture.cs b/COMETwebapp.Tests/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModelTestFixture.cs index de4e648c..d51e0408 100644 --- a/COMETwebapp.Tests/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModelTestFixture.cs +++ b/COMETwebapp.Tests/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModelTestFixture.cs @@ -102,6 +102,10 @@ public void Setup() Container = new EngineeringModel { EngineeringModelSetup = new EngineeringModelSetup() + }, + IterationSetup = new IterationSetup() + { + Container = new SiteDirectory() } }; diff --git a/COMETwebapp/Components/ModelEditor/AddParameter.razor b/COMETwebapp/Components/ModelEditor/AddParameter.razor index c407be33..13ea774a 100644 --- a/COMETwebapp/Components/ModelEditor/AddParameter.razor +++ b/COMETwebapp/Components/ModelEditor/AddParameter.razor @@ -24,22 +24,21 @@ - + + DisplayText="@(string.Empty)" + DisplayNameAndShortname="true"/> @if (this.ViewModel.Parameter.ParameterType is QuantityKind) { - + } @@ -60,7 +59,7 @@ - + diff --git a/COMETwebapp/Components/ModelEditor/ElementDefinitionCreation.razor b/COMETwebapp/Components/ModelEditor/ElementDefinitionCreation.razor index 8bd32b80..5ac110c4 100644 --- a/COMETwebapp/Components/ModelEditor/ElementDefinitionCreation.razor +++ b/COMETwebapp/Components/ModelEditor/ElementDefinitionCreation.razor @@ -41,11 +41,13 @@ - + + + diff --git a/COMETwebapp/Components/ModelEditor/ElementDefinitionCreation.razor.cs b/COMETwebapp/Components/ModelEditor/ElementDefinitionCreation.razor.cs index 60755cc9..89d5ca01 100644 --- a/COMETwebapp/Components/ModelEditor/ElementDefinitionCreation.razor.cs +++ b/COMETwebapp/Components/ModelEditor/ElementDefinitionCreation.razor.cs @@ -27,8 +27,6 @@ namespace COMETwebapp.Components.ModelEditor using Microsoft.AspNetCore.Components; - using ReactiveUI; - /// /// Partial class for the component /// diff --git a/COMETwebapp/Components/ModelEditor/ElementDefinitionTable.razor b/COMETwebapp/Components/ModelEditor/ElementDefinitionTable.razor index e63b631e..95cec68d 100644 --- a/COMETwebapp/Components/ModelEditor/ElementDefinitionTable.razor +++ b/COMETwebapp/Components/ModelEditor/ElementDefinitionTable.razor @@ -90,13 +90,13 @@ - + - + diff --git a/COMETwebapp/ViewModels/Components/ModelEditor/AddParameterViewModel/AddParameterViewModel.cs b/COMETwebapp/ViewModels/Components/ModelEditor/AddParameterViewModel/AddParameterViewModel.cs index 2af0c125..661ce49f 100644 --- a/COMETwebapp/ViewModels/Components/ModelEditor/AddParameterViewModel/AddParameterViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ModelEditor/AddParameterViewModel/AddParameterViewModel.cs @@ -47,30 +47,38 @@ public class AddParameterViewModel : DisposableObject, IAddParameterViewModel /// private readonly ISessionService sessionService; - /// - /// Gets or sets the current - /// - private Iteration CurrentIteration { get; set; } - /// /// Initializes a new instance of the class. /// /// the - /// The + /// The public AddParameterViewModel(ISessionService sessionService, ICDPMessageBus messageBus) { this.sessionService = sessionService; this.Disposables.Add(this.WhenAnyValue(x => x.ParameterTypeSelectorViewModel.SelectedParameterType).Subscribe(this.OnParameterTypeChange)); + var callbackFactory = new EventCallbackFactory(); this.DomainOfExpertiseSelectorViewModel = new DomainOfExpertiseSelectorViewModel(sessionService, messageBus) { - OnSelectedDomainOfExpertiseChange = new EventCallbackFactory().Create(this, selectedOwner => - { - this.Parameter.Owner = selectedOwner; - }) + OnSelectedDomainOfExpertiseChange = callbackFactory.Create(this, selectedOwner => { this.Parameter.Owner = selectedOwner; }) + }; + + this.MeasurementScaleSelectorViewModel = new MeasurementScaleSelectorViewModel(sessionService) + { + OnSelectedMeasurementScaleChange = callbackFactory.Create(this, selectedScale => { this.Parameter.Scale = selectedScale; }) }; } + /// + /// Gets or sets the current + /// + private Iteration CurrentIteration { get; set; } + + /// + /// Gets the + /// + public IMeasurementScaleSelectorViewModel MeasurementScaleSelectorViewModel { get; private set; } + /// /// The callback executed when the method was executed /// @@ -79,7 +87,7 @@ public AddParameterViewModel(ISessionService sessionService, ICDPMessageBus mess /// /// Gets the /// - public IParameterTypeSelectorViewModel ParameterTypeSelectorViewModel { get; private set; } = new ParameterTypeSelectorViewModel(); + public IParameterTypeSelectorViewModel ParameterTypeSelectorViewModel { get; private set; } = new ParameterTypeSelectorViewModel { QueryOnlyUsedParameterTypes = false }; /// /// The to create or edit @@ -106,11 +114,6 @@ public AddParameterViewModel(ISessionService sessionService, ICDPMessageBus mess /// public IEnumerable ParameterGroups => this.SelectedElementDefinition.ParameterGroup; - /// - /// The collection of to list for selection, if the parameter type is quantity kind - /// - public IEnumerable MeasurementScales { get; set; } = Enumerable.Empty(); - /// /// Sets the /// @@ -123,13 +126,14 @@ public void SetSelectedElementDefinition(ElementDefinition selectedElementDefini } this.SelectedElementDefinition = selectedElementDefinition; - - var allParameterTypes = this.CurrentIteration.QueryUsedParameterTypes(); var elementDefinitionParameterTypes = this.SelectedElementDefinition.Parameter.Select(x => x.ParameterType); - var filteredParameterTypes = allParameterTypes.Where(x => !elementDefinitionParameterTypes.Contains(x)).Select(x => x.Iid); - this.ParameterTypeSelectorViewModel.FilterAvailableParameterTypes(filteredParameterTypes); - - this.DomainOfExpertiseSelectorViewModel.AvailableDomainsOfExpertise = selectedElementDefinition.GetContainerOfType().EngineeringModelSetup.ActiveDomain; + this.ParameterTypeSelectorViewModel.ExcludeAvailableParameterTypes(elementDefinitionParameterTypes.Select(x => x.Iid)); + + this.DomainOfExpertiseSelectorViewModel.AvailableDomainsOfExpertise = selectedElementDefinition + .GetContainerOfType() + .EngineeringModelSetup.ActiveDomain + .OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase); + this.DomainOfExpertiseSelectorViewModel.SetSelectedDomainOfExpertiseOrReset(true); } @@ -181,10 +185,14 @@ private void OnParameterTypeChange(ParameterType parameterType) { this.Parameter.ParameterType = parameterType; - if (this.Parameter.ParameterType is QuantityKind quantityKind) + if (this.Parameter.ParameterType is not QuantityKind quantityKind) { - this.MeasurementScales = quantityKind.AllPossibleScale; + return; } + + this.Parameter.Scale = quantityKind.DefaultScale; + this.MeasurementScaleSelectorViewModel.AvailableMeasurementScales = quantityKind.AllPossibleScale.OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase); + this.MeasurementScaleSelectorViewModel.SelectedMeasurementScale = quantityKind.DefaultScale; } } } diff --git a/COMETwebapp/ViewModels/Components/ModelEditor/AddParameterViewModel/IAddParameterViewModel.cs b/COMETwebapp/ViewModels/Components/ModelEditor/AddParameterViewModel/IAddParameterViewModel.cs index 393df3e5..a8582ff9 100644 --- a/COMETwebapp/ViewModels/Components/ModelEditor/AddParameterViewModel/IAddParameterViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ModelEditor/AddParameterViewModel/IAddParameterViewModel.cs @@ -25,7 +25,6 @@ namespace COMETwebapp.ViewModels.Components.ModelEditor.AddParameterViewModel { using CDP4Common.EngineeringModelData; - using CDP4Common.SiteDirectoryData; using COMET.Web.Common.ViewModels.Components.Selectors; @@ -51,11 +50,6 @@ public interface IAddParameterViewModel /// IParameterTypeSelectorViewModel ParameterTypeSelectorViewModel { get; } - /// - /// The collection of to list for selection, if the parameter type is quantity kind - /// - IEnumerable MeasurementScales { get; set; } - /// /// The collection of to list for selection /// @@ -76,6 +70,11 @@ public interface IAddParameterViewModel /// IDomainOfExpertiseSelectorViewModel DomainOfExpertiseSelectorViewModel { get; } + /// + /// Gets the + /// + IMeasurementScaleSelectorViewModel MeasurementScaleSelectorViewModel { get; } + /// /// Adds a parameter of type selected from to the /// diff --git a/COMETwebapp/ViewModels/Components/ModelEditor/ElementDefinitionCreationViewModel.cs b/COMETwebapp/ViewModels/Components/ModelEditor/ElementDefinitionCreationViewModel.cs index f290d3e1..5fe4f21b 100644 --- a/COMETwebapp/ViewModels/Components/ModelEditor/ElementDefinitionCreationViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ModelEditor/ElementDefinitionCreationViewModel.cs @@ -102,6 +102,7 @@ public ElementDefinitionCreationViewModel(ISessionService sessionService, ICDPMe public void InitializeViewModel(Iteration iteration) { this.DomainOfExpertiseSelectorViewModel.CurrentIteration = iteration; + this.DomainOfExpertiseSelectorViewModel.AvailableDomainsOfExpertise = ((EngineeringModel)iteration.Container).EngineeringModelSetup.ActiveDomain.OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase); } /// @@ -112,6 +113,8 @@ public void InitializeViewModel(Iteration iteration) /// public void OnInitialized() { + this.AvailableCategories = []; + foreach (var referenceDataLibrary in this.sessionService.Session.RetrieveSiteDirectory().AvailableReferenceDataLibraries()) { this.AvailableCategories = this.AvailableCategories.Concat(referenceDataLibrary.DefinedCategory).Where(category => category.PermissibleClass.Contains(ClassKind.ElementDefinition)).ToList();