From 7ecf6b7a73b860278ac4b5d3ed31589c0a63d86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Th=C3=A9ate?= <97221392+antoineatrhea@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:12:26 +0200 Subject: [PATCH] Fix #293: SingleEngineeringModel principle implemented (#473) --- .../COMET.Web.Common.Tests.csproj | 3 +- ...IterationApplicationTemplateTestFixture.cs | 121 +++-- .../EngineeringModelSelectorTestFixture.cs | 98 +++++ ...tionApplicationBaseViewModelTestFixture.cs | 114 ++--- ...ApplicationTemplateViewModelTestFixture.cs | 54 +-- ...eeringModelSelectorViewModelTestFixture.cs | 95 ++++ COMET.Web.Common/COMET.Web.Common.csproj | 12 +- .../Applications/ApplicationBase.razor | 24 + .../ApplicationBase.razor.cs} | 94 ++-- .../Applications/ApplicationTemplate.razor | 24 + .../Applications/ApplicationTemplate.razor.cs | 78 ++++ ...ingleEngineeringModelApplicationBase.razor | 24 + ...leEngineeringModelApplicationBase.razor.cs | 65 +++ ...eEngineeringModelApplicationTemplate.razor | 55 +++ ...gineeringModelApplicationTemplate.razor.cs | 38 ++ .../SingleIterationApplicationBase.razor | 6 +- .../SingleIterationApplicationBase.razor.cs | 75 ++++ .../SingleIterationApplicationTemplate.razor | 11 +- ...ingleIterationApplicationTemplate.razor.cs | 108 +++++ .../SingleThingApplicationBase.razor | 25 ++ .../SingleThingApplicationBase.razor.cs | 72 +++ .../SingleThingApplicationTemplate.razor | 25 ++ .../SingleThingApplicationTemplate.razor.cs | 97 ++++ .../Selectors/EngineeringModelSelector.razor | 34 ++ .../EngineeringModelSelector.razor.cs | 45 ++ ...ingleIterationApplicationTemplate.razor.cs | 176 -------- .../Extensions/ServiceCollectionExtensions.cs | 1 + .../Pages/ApplicationPageTemplate.razor | 22 + .../Pages/ApplicationPageTemplate.razor.cs | 37 ++ .../SingleEngineeringModelPageTemplate.razor | 24 + ...ingleEngineeringModelPageTemplate.razor.cs | 65 +++ .../Pages/SingleIterationPageTemplate.razor | 2 +- .../SessionManagement/ISessionService.cs | 5 + .../SessionManagement/SessionService.cs | 19 +- .../Applications/ApplicationBaseViewModel.cs | 87 ++++ .../ApplicationTemplateViewModel.cs | 50 +++ .../Applications/IApplicationBaseViewModel.cs | 45 ++ .../IApplicationTemplateViewModel.cs | 41 ++ ...ngineeringModelApplicationBaseViewModel.cs | 36 ++ ...eeringModelApplicationTemplateViewModel.cs | 42 ++ ...SingleIterationApplicationBaseViewModel.cs | 21 +- ...leIterationApplicationTemplateViewModel.cs | 57 +-- .../ISingleThingApplicationBaseViewModel.cs | 41 ++ ...SingleThingApplicationTemplateViewModel.cs | 64 +++ ...ngineeringModelApplicationBaseViewModel.cs | 45 ++ ...eeringModelApplicationTemplateViewModel.cs | 72 +++ ...SingleIterationApplicationBaseViewModel.cs | 85 +--- ...leIterationApplicationTemplateViewModel.cs | 79 +--- .../SingleThingApplicationBaseViewModel.cs | 73 +++ ...SingleThingApplicationTemplateViewModel.cs | 111 +++++ .../EngineeringModelSelectorViewModel.cs | 78 ++++ .../IEngineeringModelSelectorViewModel.cs | 52 +++ .../Selectors/IIterationSelectorViewModel.cs | 13 +- .../Selectors/IThingSelectorViewModel.cs | 49 +++ .../Selectors/IterationSelectorViewModel.cs | 6 +- COMET.Web.Common/_Imports.razor | 1 + .../BookEditor/BookEditorBodyTestFixture.cs | 2 - .../ModelDashboardBodyTestFixture.cs | 13 +- .../ElementDefinitionTableTestFixture.cs | 44 +- .../ParameterEditorBodyTestFixture.cs | 5 + .../SubscriptionDashboardBodyTestFixture.cs | 9 +- .../SystemRepresentationBodyTestFixture.cs | 22 +- .../UserManagementTableTestFixture.cs | 5 + .../ModelDashboardTestFixture.cs | 9 +- .../ParameterEditorTestFixture.cs | 9 +- .../Pages/Viewer/ViewerTestFixture.cs | 70 ++- ...mentDefinitionTableViewModelTestFixture.cs | 12 +- ...ParameterEditorBodyViewModelTestFixture.cs | 4 +- ...iptionDashboardBodyViewModelTestFixture.cs | 6 +- .../Viewer/ViewerBodyViewModelTestFixture.cs | 2 +- COMETwebapp.sln.DotSettings | 2 +- COMETwebapp/COMETwebapp.csproj | 2 +- .../BookEditor/BookEditorBody.razor | 2 +- .../ModelDashboard/ModelDashboardBody.razor | 2 +- .../ModelEditor/ElementDefinitionTable.razor | 2 +- .../ParameterEditor/ParameterEditorBody.razor | 2 +- .../SubscriptionDashboardBody.razor | 2 +- .../SystemRepresentationBody.razor | 2 +- .../UserManagement/UserManagementTable.razor | 2 +- .../Components/Viewer/ViewerBody.razor | 2 +- .../BookEditor/BookEditorBodyViewModel.cs | 11 +- .../BookEditor/IBookEditorBodyViewModel.cs | 3 +- .../IModelDashboardBodyViewModel.cs | 2 +- .../ModelDashboardBodyViewModel.cs | 24 +- .../ElementDefinitionTableViewModel.cs | 344 ++++++++------- .../IElementDefinitionTableViewModel.cs | 16 +- .../IParameterEditorBodyViewModel.cs | 2 +- .../ParameterEditorBodyViewModel.cs | 18 +- .../ReferenceData/CategoriesTableViewModel.cs | 63 +-- .../ICategoriesTableViewModel.cs | 5 +- .../IParameterTypeTableViewModel.cs | 21 +- .../ParameterTypeTableViewModel.cs | 42 +- .../ISubscriptionDashboardBodyViewModel.cs | 2 +- .../SubscriptionDashboardBodyViewModel.cs | 24 +- .../ISystemRepresentationBodyViewModel.cs | 2 +- .../SystemRepresentationBodyViewModel.cs | 414 +++++++++--------- .../IUserManagementTableViewModel.cs | 2 +- .../UserManagementTableViewModel.cs | 154 +++---- .../Components/Viewer/IViewerBodyViewModel.cs | 2 +- .../Components/Viewer/ViewerBodyViewModel.cs | 15 +- COMETwebapp/_Imports.razor | 1 + 101 files changed, 3027 insertions(+), 1268 deletions(-) rename COMET.Web.Common.Tests/Components/{ => Applications}/SingleIterationApplicationTemplateTestFixture.cs (80%) create mode 100644 COMET.Web.Common.Tests/Components/Selectors/EngineeringModelSelectorTestFixture.cs rename COMET.Web.Common.Tests/ViewModels/Components/{ => Applications}/SingleIterationApplicationBaseViewModelTestFixture.cs (89%) rename COMET.Web.Common.Tests/ViewModels/Components/{ => Applications}/SingleIterationApplicationTemplateViewModelTestFixture.cs (79%) create mode 100644 COMET.Web.Common.Tests/ViewModels/Components/Selectors/EngineeringModelSelectorViewModelTestFixture.cs create mode 100644 COMET.Web.Common/Components/Applications/ApplicationBase.razor rename COMET.Web.Common/Components/{SingleIterationApplicationBase.razor.cs => Applications/ApplicationBase.razor.cs} (62%) create mode 100644 COMET.Web.Common/Components/Applications/ApplicationTemplate.razor create mode 100644 COMET.Web.Common/Components/Applications/ApplicationTemplate.razor.cs create mode 100644 COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationBase.razor create mode 100644 COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationBase.razor.cs create mode 100644 COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationTemplate.razor create mode 100644 COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationTemplate.razor.cs rename COMET.Web.Common/Components/{ => Applications}/SingleIterationApplicationBase.razor (79%) create mode 100644 COMET.Web.Common/Components/Applications/SingleIterationApplicationBase.razor.cs rename COMET.Web.Common/Components/{ => Applications}/SingleIterationApplicationTemplate.razor (80%) create mode 100644 COMET.Web.Common/Components/Applications/SingleIterationApplicationTemplate.razor.cs create mode 100644 COMET.Web.Common/Components/Applications/SingleThingApplicationBase.razor create mode 100644 COMET.Web.Common/Components/Applications/SingleThingApplicationBase.razor.cs create mode 100644 COMET.Web.Common/Components/Applications/SingleThingApplicationTemplate.razor create mode 100644 COMET.Web.Common/Components/Applications/SingleThingApplicationTemplate.razor.cs create mode 100644 COMET.Web.Common/Components/Selectors/EngineeringModelSelector.razor create mode 100644 COMET.Web.Common/Components/Selectors/EngineeringModelSelector.razor.cs delete mode 100644 COMET.Web.Common/Components/SingleIterationApplicationTemplate.razor.cs create mode 100644 COMET.Web.Common/Pages/ApplicationPageTemplate.razor create mode 100644 COMET.Web.Common/Pages/ApplicationPageTemplate.razor.cs create mode 100644 COMET.Web.Common/Pages/SingleEngineeringModelPageTemplate.razor create mode 100644 COMET.Web.Common/Pages/SingleEngineeringModelPageTemplate.razor.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/ApplicationBaseViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/ApplicationTemplateViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/IApplicationBaseViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/IApplicationTemplateViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/ISingleEngineeringModelApplicationBaseViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/ISingleEngineeringModelApplicationTemplateViewModel.cs rename COMET.Web.Common/ViewModels/Components/{ => Applications}/ISingleIterationApplicationBaseViewModel.cs (72%) rename COMET.Web.Common/ViewModels/Components/{ => Applications}/ISingleIterationApplicationTemplateViewModel.cs (54%) create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/ISingleThingApplicationBaseViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/ISingleThingApplicationTemplateViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/SingleEngineeringModelApplicationBaseViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/SingleEngineeringModelApplicationTemplateViewModel.cs rename COMET.Web.Common/ViewModels/Components/{ => Applications}/SingleIterationApplicationBaseViewModel.cs (51%) rename COMET.Web.Common/ViewModels/Components/{ => Applications}/SingleIterationApplicationTemplateViewModel.cs (53%) create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/SingleThingApplicationBaseViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Applications/SingleThingApplicationTemplateViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Selectors/EngineeringModelSelectorViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Selectors/IEngineeringModelSelectorViewModel.cs create mode 100644 COMET.Web.Common/ViewModels/Components/Selectors/IThingSelectorViewModel.cs diff --git a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj index 55c1006c..1c357f38 100644 --- a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj +++ b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -65,6 +65,7 @@ + diff --git a/COMET.Web.Common.Tests/Components/SingleIterationApplicationTemplateTestFixture.cs b/COMET.Web.Common.Tests/Components/Applications/SingleIterationApplicationTemplateTestFixture.cs similarity index 80% rename from COMET.Web.Common.Tests/Components/SingleIterationApplicationTemplateTestFixture.cs rename to COMET.Web.Common.Tests/Components/Applications/SingleIterationApplicationTemplateTestFixture.cs index d3cad8cc..0e50713c 100644 --- a/COMET.Web.Common.Tests/Components/SingleIterationApplicationTemplateTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/Applications/SingleIterationApplicationTemplateTestFixture.cs @@ -23,7 +23,7 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.Tests.Components +namespace COMET.Web.Common.Tests.Components.Applications { using Bunit; @@ -34,6 +34,7 @@ namespace COMET.Web.Common.Tests.Components using CDP4Dal.Events; using COMET.Web.Common.Components; + using COMET.Web.Common.Components.Applications; using COMET.Web.Common.Components.Selectors; using COMET.Web.Common.Extensions; using COMET.Web.Common.Model.Configuration; @@ -42,6 +43,7 @@ namespace COMET.Web.Common.Tests.Components using COMET.Web.Common.Services.StringTableService; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using DynamicData; @@ -73,7 +75,7 @@ public void Setup() var session = new Mock(); session.Setup(x => x.DataSourceUri).Returns("http://localhost:5000"); sessionService.Setup(x => x.Session).Returns(session.Object); - sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny())).Returns(new DomainOfExpertise(){Iid = Guid.NewGuid()}); + sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny())).Returns(new DomainOfExpertise { Iid = Guid.NewGuid() }); this.viewModel.Setup(x => x.SessionService).Returns(sessionService.Object); var mockConfigurationService = new Mock(); mockConfigurationService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); @@ -91,15 +93,59 @@ public void Teardown() this.context.CleanContext(); } + [Test] + public void VerifyWithIterationIdParameter() + { + this.openIterations.Add(new Iteration + { + Iid = Guid.NewGuid(), + IterationSetup = new IterationSetup + { + Container = new EngineeringModelSetup + { + Iid = Guid.NewGuid() + } + } + }); + + var renderer = this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, Guid.NewGuid()); }); + + Assert.That(renderer.Instance.IterationId, Is.EqualTo(Guid.Empty)); + + _ = this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.openIterations.Items.First().Iid); }); + + this.viewModel.Verify(x => x.OnThingSelect(this.openIterations.Items.First()), Times.Once); + + this.viewModel.Setup(x => x.SelectedThing).Returns(new Iteration + { + Iid = Guid.NewGuid(), + IterationSetup = new IterationSetup + { + Container = new EngineeringModelSetup + { + Iid = Guid.NewGuid() + } + } + }); + + renderer = this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.openIterations.Items.First().Iid); }); + + Assert.Multiple(() => + { + Assert.That(renderer.Instance.IterationId, Is.EqualTo(this.openIterations.Items.First().Iid)); + this.viewModel.Verify(x => x.OnThingSelect(this.openIterations.Items.First()), Times.Once); + }); + } + [Test] public void VerifyWithoutIterationIdParameter() { - this.openIterations.Add(new Iteration() + this.openIterations.Add(new Iteration { Iid = Guid.NewGuid(), - IterationSetup = new IterationSetup() + IterationSetup = new IterationSetup { - Container = new EngineeringModelSetup() + Container = new EngineeringModelSetup { Iid = Guid.NewGuid() } @@ -121,12 +167,12 @@ public void VerifyWithoutIterationIdParameter() Assert.Multiple(() => { Assert.That(navigationManager.Uri, Is.EqualTo("http://localhost/")); - this.viewModel.Verify(x => x.SelectIteration(this.openIterations.Items.First()), Times.Once); + this.viewModel.Verify(x => x.OnThingSelect(this.openIterations.Items.First()), Times.Once); }); - this.viewModel.Setup(x => x.SelectedIteration).Returns(this.openIterations.Items.First()); + this.viewModel.Setup(x => x.SelectedThing).Returns(this.openIterations.Items.First()); renderer.Instance.SetCorrectUrl(); - var iteration = this.viewModel.Object.SelectedIteration; + var iteration = this.viewModel.Object.SelectedThing; Assert.Multiple(() => { @@ -154,13 +200,13 @@ public void VerifyWithoutIterationIdParameter() }); Assert.That(() => renderer.FindComponent(), Throws.Exception); - this.viewModel.Verify(x => x.AskToSelectIteration(), Times.Once); - this.viewModel.Setup(x => x.IsOnIterationSelectionMode).Returns(true); + this.viewModel.Verify(x => x.AskToSelectThing(), Times.Once); + this.viewModel.Setup(x => x.IsOnSelectionMode).Returns(true); this.viewModel.Setup(x => x.IterationSelectorViewModel).Returns(new IterationSelectorViewModel()); renderer.Render(); Assert.That(() => renderer.FindComponent(), Throws.Nothing); this.openIterations.Clear(); - this.viewModel.Setup(x => x.SelectedIteration).Returns((Iteration)null); + this.viewModel.Setup(x => x.SelectedThing).Returns((Iteration)null); renderer.Instance.SetCorrectUrl(); Assert.Multiple(() => @@ -170,58 +216,5 @@ public void VerifyWithoutIterationIdParameter() Assert.That(() => CDPMessageBus.Current.SendMessage(new DomainChangedEvent(null, null)), Throws.Nothing); }); } - - [Test] - public void VerifyWithIterationIdParameter() - { - this.openIterations.Add(new Iteration() - { - Iid = Guid.NewGuid(), - IterationSetup = new IterationSetup() - { - Container = new EngineeringModelSetup() - { - Iid = Guid.NewGuid() - } - } - }); - - var renderer = this.context.RenderComponent(parameters => - { - parameters.Add(p => p.IterationId, Guid.NewGuid()); - }); - - Assert.That(renderer.Instance.IterationId, Is.EqualTo(Guid.Empty)); - - _ = this.context.RenderComponent(parameters => - { - parameters.Add(p => p.IterationId, this.openIterations.Items.First().Iid); - }); - - this.viewModel.Verify(x => x.SelectIteration(this.openIterations.Items.First()), Times.Once); - - this.viewModel.Setup(x => x.SelectedIteration).Returns(new Iteration() - { - Iid = Guid.NewGuid(), - IterationSetup = new IterationSetup() - { - Container = new EngineeringModelSetup() - { - Iid = Guid.NewGuid() - } - } - }); - - renderer = this.context.RenderComponent(parameters => - { - parameters.Add(p => p.IterationId, this.openIterations.Items.First().Iid); - }); - - Assert.Multiple(() => - { - Assert.That(renderer.Instance.IterationId, Is.EqualTo(this.openIterations.Items.First().Iid)); - this.viewModel.Verify(x => x.SelectIteration(this.openIterations.Items.First()), Times.Once); - }); - } } } diff --git a/COMET.Web.Common.Tests/Components/Selectors/EngineeringModelSelectorTestFixture.cs b/COMET.Web.Common.Tests/Components/Selectors/EngineeringModelSelectorTestFixture.cs new file mode 100644 index 00000000..d122604d --- /dev/null +++ b/COMET.Web.Common.Tests/Components/Selectors/EngineeringModelSelectorTestFixture.cs @@ -0,0 +1,98 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.Components.Selectors +{ + using Bunit; + + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.Components.Selectors; + using COMET.Web.Common.Test.Helpers; + using COMET.Web.Common.ViewModels.Components.Selectors; + + using DevExpress.Blazor; + + using Moq; + + using NUnit.Framework; + + using TestContext = Bunit.TestContext; + + [TestFixture] + public class EngineeringModelSelectorTestFixture + { + private TestContext context; + private Mock viewModel; + private List setups; + + [SetUp] + public void Setup() + { + this.context = new TestContext(); + this.context.ConfigureDevExpressBlazor(); + + this.setups = new List(); + this.viewModel = new Mock(); + this.viewModel.Setup(x => x.AvailableEngineeringModelSetups).Returns(this.setups); + this.setups.Add(new EngineeringModelSetup(){Name = "model A"}); + this.setups.Add(new EngineeringModelSetup(){Name = "model B"}); + } + + [TearDown] + public void Teardown() + { + this.context.CleanContext(); + } + + [Test] + public async Task VerifyEngineeringModelSelectorComponent() + { + var renderer = this.context.RenderComponent(parameters => + { + parameters.Add(p => p.ViewModel, this.viewModel.Object); + }); + + Assert.That(renderer.Instance.ViewModel, Is.EqualTo(this.viewModel.Object)); + + var listBox = renderer.FindComponent>(); + var submitButton = renderer.FindComponent(); + + Assert.Multiple(() => + { + Assert.That(listBox.Instance.Data.Count(), Is.EqualTo(2)); + Assert.That(submitButton.Instance.Enabled, Is.False); + }); + + this.viewModel.Setup(x => x.SelectedEngineeringModelSetup).Returns(this.setups[^1]); + renderer.Render(); + + Assert.That(submitButton.Instance.Enabled, Is.True); + + await renderer.InvokeAsync(submitButton.Instance.Click.InvokeAsync); + this.viewModel.Verify(x => x.Submit(), Times.Once); + } + } +} diff --git a/COMET.Web.Common.Tests/ViewModels/Components/SingleIterationApplicationBaseViewModelTestFixture.cs b/COMET.Web.Common.Tests/ViewModels/Components/Applications/SingleIterationApplicationBaseViewModelTestFixture.cs similarity index 89% rename from COMET.Web.Common.Tests/ViewModels/Components/SingleIterationApplicationBaseViewModelTestFixture.cs rename to COMET.Web.Common.Tests/ViewModels/Components/Applications/SingleIterationApplicationBaseViewModelTestFixture.cs index 048f81bc..3ea64d1e 100644 --- a/COMET.Web.Common.Tests/ViewModels/Components/SingleIterationApplicationBaseViewModelTestFixture.cs +++ b/COMET.Web.Common.Tests/ViewModels/Components/Applications/SingleIterationApplicationBaseViewModelTestFixture.cs @@ -23,7 +23,7 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.Tests.ViewModels.Components +namespace COMET.Web.Common.Tests.ViewModels.Components.Applications { using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; @@ -33,7 +33,7 @@ namespace COMET.Web.Common.Tests.ViewModels.Components using CDP4Dal.Events; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using Moq; @@ -45,6 +45,36 @@ public class SingleIterationApplicationBaseViewModelTestFixture private SingleIterationApplicationViewModel viewModel; private Mock sessionService; + private class SingleIterationApplicationViewModel : SingleIterationApplicationBaseViewModel + { + public int OnSessionRefreshCount; + + /// + /// Initializes a new instance of the class. + /// + /// The + public SingleIterationApplicationViewModel(ISessionService sessionService) : base(sessionService) + { + } + + public IReadOnlyList AddedThingsReadOnlyList => this.AddedThings.AsReadOnly(); + + public void Initialize(IEnumerable types) + { + this.InitializeSubscriptions(types); + } + + /// + /// Handles the refresh of the current + /// + /// A + protected override Task OnSessionRefreshed() + { + this.OnSessionRefreshCount++; + return Task.CompletedTask; + } + } + [SetUp] public void Setup() { @@ -59,15 +89,23 @@ public void Teardown() } [Test] - public void VerifyProperties() + public void VerifyObjectChangeSubscriptions() { - Assert.Multiple(() => - { - Assert.That(this.viewModel.CurrentDomain, Is.Null); - Assert.That(this.viewModel.IsLoading, Is.False); - Assert.That(this.viewModel.HasSetInitialValuesOnce, Is.False); - Assert.That(this.viewModel.CurrentIteration, Is.Null); - }); + this.viewModel.Initialize(new List { typeof(ElementBase) }); + var elementDefinition = new ElementDefinition { Container = new Iteration() }; + + CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Added); + Assert.That(this.viewModel.AddedThingsReadOnlyList, Is.Empty); + + this.viewModel.CurrentThing = new Iteration { Iid = Guid.NewGuid() }; + + CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Added); + Assert.That(this.viewModel.AddedThingsReadOnlyList, Is.Empty); + + this.viewModel.CurrentThing.Element.Add(elementDefinition); + + CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Added); + Assert.That(this.viewModel.AddedThingsReadOnlyList, Has.Count.EqualTo(1)); } [Test] @@ -77,14 +115,14 @@ public void VerifyOnIterationOrDomainChanged() var domain = new DomainOfExpertise(); this.sessionService.Setup(x => x.GetDomainOfExpertise(iteration)).Returns(domain); Assert.That(this.viewModel.CurrentDomain, Is.Null); - this.viewModel.CurrentIteration = iteration; + this.viewModel.CurrentThing = iteration; this.viewModel.HasSetInitialValuesOnce = true; Assert.That(this.viewModel.CurrentDomain, Is.EqualTo(domain)); var newDomain = new DomainOfExpertise(); this.sessionService.Setup(x => x.GetDomainOfExpertise(iteration)).Returns(newDomain); CDPMessageBus.Current.SendMessage(new DomainChangedEvent(iteration, newDomain)); Assert.That(this.viewModel.CurrentDomain, Is.EqualTo(newDomain)); - this.viewModel.CurrentIteration = null; + this.viewModel.CurrentThing = null; Assert.That(this.viewModel.CurrentDomain, Is.Null); } @@ -97,53 +135,15 @@ public void VerifyOnSessionRefresh() } [Test] - public void VerifyObjectChangeSubscriptions() - { - this.viewModel.Initialize(new List{typeof(ElementBase)}); - var elementDefinition = new ElementDefinition(){Container = new Iteration()}; - - CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Added); - Assert.That(this.viewModel.AddedThingsReadOnlyList, Is.Empty); - - this.viewModel.CurrentIteration = new Iteration(){Iid = Guid.NewGuid()}; - - CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Added); - Assert.That(this.viewModel.AddedThingsReadOnlyList, Is.Empty); - - this.viewModel.CurrentIteration.Element.Add(elementDefinition); - - CDPMessageBus.Current.SendObjectChangeEvent(elementDefinition, EventKind.Added); - Assert.That(this.viewModel.AddedThingsReadOnlyList, Has.Count.EqualTo(1)); - } - - private class SingleIterationApplicationViewModel : SingleIterationApplicationBaseViewModel + public void VerifyProperties() { - public int OnSessionRefreshCount; - - /// - /// Initializes a new instance of the class. - /// - /// The - public SingleIterationApplicationViewModel(ISessionService sessionService) : base(sessionService) - { - } - - /// - /// Handles the refresh of the current - /// - /// A - protected override Task OnSessionRefreshed() - { - this.OnSessionRefreshCount++; - return Task.CompletedTask; - } - - public void Initialize(IEnumerable types) + Assert.Multiple(() => { - this.InitializeSubscriptions(types); - } - - public IReadOnlyList AddedThingsReadOnlyList => this.AddedThings.AsReadOnly(); + Assert.That(this.viewModel.CurrentDomain, Is.Null); + Assert.That(this.viewModel.IsLoading, Is.False); + Assert.That(this.viewModel.HasSetInitialValuesOnce, Is.False); + Assert.That(this.viewModel.CurrentThing, Is.Null); + }); } } } diff --git a/COMET.Web.Common.Tests/ViewModels/Components/SingleIterationApplicationTemplateViewModelTestFixture.cs b/COMET.Web.Common.Tests/ViewModels/Components/Applications/SingleIterationApplicationTemplateViewModelTestFixture.cs similarity index 79% rename from COMET.Web.Common.Tests/ViewModels/Components/SingleIterationApplicationTemplateViewModelTestFixture.cs rename to COMET.Web.Common.Tests/ViewModels/Components/Applications/SingleIterationApplicationTemplateViewModelTestFixture.cs index 825c4145..7bca2313 100644 --- a/COMET.Web.Common.Tests/ViewModels/Components/SingleIterationApplicationTemplateViewModelTestFixture.cs +++ b/COMET.Web.Common.Tests/ViewModels/Components/Applications/SingleIterationApplicationTemplateViewModelTestFixture.cs @@ -23,13 +23,13 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.Tests.ViewModels.Components +namespace COMET.Web.Common.Tests.ViewModels.Components.Applications { using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using DynamicData; @@ -62,6 +62,20 @@ public void Teardown() this.viewModel.Dispose(); } + [Test] + public void VerifyOnOpenIterationCountChanged() + { + this.openIterations.Add(new Iteration()); + Assert.That(this.viewModel.SelectedThing, Is.Not.Null); + this.viewModel.SelectedThing = null; + this.openIterations.Add(new Iteration()); + Assert.That(this.viewModel.SelectedThing, Is.Null); + this.openIterations.RemoveAt(1); + Assert.That(this.viewModel.SelectedThing, Is.Not.Null); + this.openIterations.Clear(); + Assert.That(this.viewModel.SelectedThing, Is.Null); + } + [Test] public void VerifyProperties() { @@ -69,31 +83,17 @@ public void VerifyProperties() { Assert.That(this.viewModel.SessionService, Is.EqualTo(this.sessionService.Object)); Assert.That(this.viewModel.IterationSelectorViewModel, Is.EqualTo(this.iterationSelectorViewModel.Object)); - Assert.That(this.viewModel.SelectedIteration, Is.Null); - Assert.That(this.viewModel.IsOnIterationSelectionMode, Is.False); + Assert.That(this.viewModel.SelectedThing, Is.Null); + Assert.That(this.viewModel.IsOnSelectionMode, Is.False); }); } - [Test] - public void VerifyOnOpenIterationCountChanged() - { - this.openIterations.Add(new Iteration()); - Assert.That(this.viewModel.SelectedIteration, Is.Not.Null); - this.viewModel.SelectedIteration = null; - this.openIterations.Add(new Iteration()); - Assert.That(this.viewModel.SelectedIteration, Is.Null); - this.openIterations.RemoveAt(1); - Assert.That(this.viewModel.SelectedIteration, Is.Not.Null); - this.openIterations.Clear(); - Assert.That(this.viewModel.SelectedIteration, Is.Null); - } - [Test] public void VerifySelectIteration() { var iterations = new List { - new () + new() { Iid = Guid.NewGuid(), IterationSetup = new IterationSetup(Guid.NewGuid(), null, null) @@ -102,27 +102,27 @@ public void VerifySelectIteration() Container = new EngineeringModelSetup(Guid.NewGuid(), null, null) } }, - new () + new() { Iid = Guid.NewGuid() } }; this.openIterations.AddRange(iterations); - this.viewModel.AskToSelectIteration(); - + this.viewModel.AskToSelectThing(); + Assert.Multiple(() => { this.iterationSelectorViewModel.Verify(x => x.UpdateProperties(this.openIterations.Items), Times.Once); - Assert.That(this.viewModel.IsOnIterationSelectionMode, Is.True); + Assert.That(this.viewModel.IsOnSelectionMode, Is.True); }); - this.viewModel.SelectIteration(iterations.First()); - + this.viewModel.OnThingSelect(iterations[0]); + Assert.Multiple(() => { - Assert.That(this.viewModel.IsOnIterationSelectionMode, Is.False); - Assert.That(this.viewModel.SelectedIteration, Is.EqualTo(iterations.First())); + Assert.That(this.viewModel.IsOnSelectionMode, Is.False); + Assert.That(this.viewModel.SelectedThing, Is.EqualTo(iterations[0])); }); } } diff --git a/COMET.Web.Common.Tests/ViewModels/Components/Selectors/EngineeringModelSelectorViewModelTestFixture.cs b/COMET.Web.Common.Tests/ViewModels/Components/Selectors/EngineeringModelSelectorViewModelTestFixture.cs new file mode 100644 index 00000000..daa5189e --- /dev/null +++ b/COMET.Web.Common.Tests/ViewModels/Components/Selectors/EngineeringModelSelectorViewModelTestFixture.cs @@ -0,0 +1,95 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.ViewModels.Components.Selectors +{ + using CDP4Common.EngineeringModelData; + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.ViewModels.Components.Selectors; + + using Microsoft.AspNetCore.Components; + + using NUnit.Framework; + + [TestFixture] + public class EngineeringModelSelectorViewModelTestFixture + { + private EngineeringModelSelectorViewModel viewModel; + + [SetUp] + public void SetUp() + { + this.viewModel = new EngineeringModelSelectorViewModel(); + } + + [Test] + public void VerifyProperties() + { + Assert.Multiple(() => + { + Assert.That(this.viewModel.AvailableEngineeringModelSetups, Is.Null); + Assert.That(this.viewModel.SelectedEngineeringModelSetup, Is.Null); + Assert.That(this.viewModel.OnSubmit.HasDelegate, Is.False); + }); + + this.viewModel.UpdateProperties(new List { new() { EngineeringModelSetup = new EngineeringModelSetup() } }); + + Assert.Multiple(() => + { + Assert.That(this.viewModel.AvailableEngineeringModelSetups, Is.Not.Empty); + Assert.That(this.viewModel.SelectedEngineeringModelSetup, Is.Null); + }); + + this.viewModel.SelectedEngineeringModelSetup = this.viewModel.AvailableEngineeringModelSetups.First(); + Assert.That(this.viewModel.SelectedEngineeringModelSetup, Is.Not.Null); + } + + [Test] + public async Task VerifySubmit() + { + EngineeringModel engineeringModel = default; + this.viewModel.OnSubmit = new EventCallbackFactory().Create(this, x => { engineeringModel = x; }); + + Assert.That( () => this.viewModel.Submit(), Throws.Exception); + var engineeringModelId = Guid.NewGuid(); + + this.viewModel.UpdateProperties(new List + { + new() + { + Iid = engineeringModelId, EngineeringModelSetup = new EngineeringModelSetup + { + EngineeringModelIid = engineeringModelId + } + } + }); + + this.viewModel.SelectedEngineeringModelSetup = this.viewModel.AvailableEngineeringModelSetups.First(); + await this.viewModel.Submit(); + Assert.That(engineeringModel.Iid, Is.EqualTo(this.viewModel.SelectedEngineeringModelSetup.EngineeringModelIid)); + } + } +} diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 73dc57d8..58e35c37 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -53,4 +53,14 @@ Always + + + + + <_ContentIncludedByDefault Remove="Components\Applications\ApplicationTemplate.razor" /> + <_ContentIncludedByDefault Remove="Components\SingleThingApplicationTemplate.razor" /> + + + + \ No newline at end of file diff --git a/COMET.Web.Common/Components/Applications/ApplicationBase.razor b/COMET.Web.Common/Components/Applications/ApplicationBase.razor new file mode 100644 index 00000000..0fb2c4e2 --- /dev/null +++ b/COMET.Web.Common/Components/Applications/ApplicationBase.razor @@ -0,0 +1,24 @@ + +@namespace COMET.Web.Common.Components.Applications +@typeparam TViewModel where TViewModel: class, COMET.Web.Common.ViewModels.Components.Applications.IApplicationBaseViewModel +@inherits DisposableComponent \ No newline at end of file diff --git a/COMET.Web.Common/Components/SingleIterationApplicationBase.razor.cs b/COMET.Web.Common/Components/Applications/ApplicationBase.razor.cs similarity index 62% rename from COMET.Web.Common/Components/SingleIterationApplicationBase.razor.cs rename to COMET.Web.Common/Components/Applications/ApplicationBase.razor.cs index 84b8069a..cacc9a93 100644 --- a/COMET.Web.Common/Components/SingleIterationApplicationBase.razor.cs +++ b/COMET.Web.Common/Components/Applications/ApplicationBase.razor.cs @@ -1,8 +1,8 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // Copyright (c) 2023 RHEA System 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 // // This file is part of COMET WEB Community Edition // The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 @@ -23,13 +23,12 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.Components +namespace COMET.Web.Common.Components.Applications { - using CDP4Common.EngineeringModelData; - using COMET.Web.Common.Extensions; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Utilities; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.WebUtilities; @@ -37,10 +36,10 @@ namespace COMET.Web.Common.Components using ReactiveUI; /// - /// Base component for any application that will need only one + /// Base component for any application /// - /// An - public abstract partial class SingleIterationApplicationBase + /// An + public abstract partial class ApplicationBase { /// /// The @@ -55,10 +54,15 @@ public abstract partial class SingleIterationApplicationBase public NavigationManager NavigationManager { get; set; } /// - /// The + /// The + /// + [Inject] + public IConfigurationService ConfigurationService { get; set; } + + /// + /// Gets or sets the number of required URL Parameters /// - [CascadingParameter] - public Iteration CurrentIteration { get; set; } + protected int NumberOfUrlRequiredParameters { get; set; } = 1; /// /// Method invoked when the component is ready to start, having received its @@ -70,9 +74,8 @@ protected override void OnInitialized() this.Disposables.Add(this.ViewModel); - this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.CurrentIteration - , x => x.ViewModel.IsLoading) - .Subscribe(_ => this.InvokeAsync(this.StateHasChanged))); + this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsLoading) + .SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged))); } /// @@ -83,23 +86,30 @@ protected override void OnParametersSet() { base.OnParametersSet(); - this.ViewModel.CurrentIteration = this.CurrentIteration; - - if (!this.ViewModel.HasSetInitialValuesOnce) + if (this.ViewModel.HasSetInitialValuesOnce) { - this.InitializeValues(this.NavigationManager.Uri.GetParametersFromUrl()); - this.ViewModel.HasSetInitialValuesOnce = true; + return; } + + this.InitializeValues(this.NavigationManager.Uri.GetParametersFromUrl()); + this.ViewModel.HasSetInitialValuesOnce = true; } /// - /// Initializes values of the component and of the ViewModel based on parameters provided from the url + /// Sets the URL parameters that are required for this application /// - /// A for parameters - protected abstract void InitializeValues(Dictionary parameters); + /// A of current URL parameters that comes form the URI + /// A of parameters that have to be included + protected virtual void SetUrlParameters(Dictionary currentOptions, Dictionary urlParameters) + { + if (currentOptions.TryGetValue(QueryKeys.ServerKey, out var serverValue)) + { + urlParameters[QueryKeys.ServerKey] = serverValue; + } + } /// - /// Updates the url of the with the + /// Updates the url of the with the /// /// /// A of additional parameters @@ -109,29 +119,21 @@ protected void UpdateUrlWithParameters(Dictionary additionalPara var currentOptions = this.NavigationManager.Uri.GetParametersFromUrl(); var requiredOptions = new Dictionary(); - if (currentOptions.TryGetValue(QueryKeys.IterationKey, out var iterationValue)) - { - requiredOptions[QueryKeys.IterationKey] = iterationValue; - } - - if (currentOptions.TryGetValue(QueryKeys.DomainKey, out var domainValue)) - { - requiredOptions[QueryKeys.DomainKey] = domainValue; - } - - if (currentOptions.TryGetValue(QueryKeys.ServerKey, out var serverValue)) - { - requiredOptions[QueryKeys.ServerKey] = serverValue; - } + this.SetUrlParameters(currentOptions, requiredOptions); - if (currentOptions.TryGetValue(QueryKeys.ModelKey, out var modelValue)) + if (!string.IsNullOrEmpty(this.ConfigurationService.ServerConfiguration.ServerAddress)) { - requiredOptions[QueryKeys.ModelKey] = modelValue; + if (requiredOptions.TryGetValue(QueryKeys.ServerKey, out _) || requiredOptions.Count != this.NumberOfUrlRequiredParameters - 1) + { + return; + } } - - if (requiredOptions.Count != 4) + else { - return; + if (requiredOptions.Count != this.NumberOfUrlRequiredParameters) + { + return; + } } foreach (var additionalParameter in additionalParameters) @@ -141,5 +143,11 @@ protected void UpdateUrlWithParameters(Dictionary additionalPara this.NavigationManager.NavigateTo(QueryHelpers.AddQueryString($"/{pageName}", requiredOptions)); } + + /// + /// Initializes values of the component and of the ViewModel based on parameters provided from the url + /// + /// A for parameters + protected abstract void InitializeValues(Dictionary parameters); } } diff --git a/COMET.Web.Common/Components/Applications/ApplicationTemplate.razor b/COMET.Web.Common/Components/Applications/ApplicationTemplate.razor new file mode 100644 index 00000000..72ed67af --- /dev/null +++ b/COMET.Web.Common/Components/Applications/ApplicationTemplate.razor @@ -0,0 +1,24 @@ + +@namespace COMET.Web.Common.Components.Applications +@typeparam TViewModel where TViewModel: class, COMET.Web.Common.ViewModels.Components.Applications.IApplicationTemplateViewModel +@inherits DisposableComponent diff --git a/COMET.Web.Common/Components/Applications/ApplicationTemplate.razor.cs b/COMET.Web.Common/Components/Applications/ApplicationTemplate.razor.cs new file mode 100644 index 00000000..1591f5f7 --- /dev/null +++ b/COMET.Web.Common/Components/Applications/ApplicationTemplate.razor.cs @@ -0,0 +1,78 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Components.Applications +{ + using System.ComponentModel; + + using COMET.Web.Common.Services.ConfigurationService; + using COMET.Web.Common.Utilities; + using COMET.Web.Common.ViewModels.Components.Applications; + + using Microsoft.AspNetCore.Components; + + /// + /// Shared component that will englobe all applications + /// + /// Any + public partial class ApplicationTemplate + { + /// + /// Body of the application + /// + [Parameter] + public RenderFragment Body { get; set; } + + /// + /// Gets or Sets the + /// + [Inject] + public TViewModel ViewModel { get; set; } + + /// + /// The + /// + [Inject] + public NavigationManager NavigationManager { get; set; } + + /// + /// The + /// + [Inject] + public IConfigurationService ConfigurationService { get; set; } + + /// + /// Set URL parameters based on the current context + /// + /// A of URL parameters + protected virtual void SetUrlParameters(Dictionary currentOptions) + { + if (string.IsNullOrEmpty(this.ConfigurationService.ServerConfiguration.ServerAddress)) + { + currentOptions[QueryKeys.ServerKey] = this.ViewModel.SessionService.Session.DataSourceUri; + } + } + } +} diff --git a/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationBase.razor b/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationBase.razor new file mode 100644 index 00000000..66c5abbb --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationBase.razor @@ -0,0 +1,24 @@ + +@namespace COMET.Web.Common.Components.Applications +@typeparam TViewModel where TViewModel: class, COMET.Web.Common.ViewModels.Components.Applications.ISingleEngineeringModelApplicationBaseViewModel +@inherits SingleThingApplicationBase \ No newline at end of file diff --git a/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationBase.razor.cs b/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationBase.razor.cs new file mode 100644 index 00000000..0396033d --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationBase.razor.cs @@ -0,0 +1,65 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Components.Applications +{ + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.Utilities; + using COMET.Web.Common.ViewModels.Components.Applications; + + /// + /// Base component for any application that will need only one + /// + /// An + public abstract partial class SingleEngineeringModelApplicationBase + { + /// + /// Method invoked when the component is ready to start, having received its + /// initial parameters from its parent in the render tree. + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + this.NumberOfUrlRequiredParameters = 2; + } + + /// + /// Sets the URL parameters that are required for this application + /// + /// A of current URL parameters that comes form the URI + /// A of parameters that have to be included + protected override void SetUrlParameters(Dictionary currentOptions, Dictionary urlParameters) + { + base.SetUrlParameters(currentOptions, urlParameters); + + if (currentOptions.TryGetValue(QueryKeys.ModelKey, out var modelValue)) + { + urlParameters[QueryKeys.ModelKey] = modelValue; + } + } + } +} diff --git a/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationTemplate.razor b/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationTemplate.razor new file mode 100644 index 00000000..d9480a1b --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationTemplate.razor @@ -0,0 +1,55 @@ + +@namespace COMET.Web.Common.Components.Applications +@inherits SingleThingApplicationTemplate + + + + + +@if (this.ViewModel.SessionService.OpenIterations.Count == 0) +{ + + + +} +else +{ +
+
+ @if (this.ViewModel.SelectedThing is not null) + { + @if (this.ShowActiveModel) + { + + } + +
+ @this.Body +
+
+ } +
+
+} \ No newline at end of file diff --git a/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationTemplate.razor.cs b/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationTemplate.razor.cs new file mode 100644 index 00000000..06a50c2b --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleEngineeringModelApplicationTemplate.razor.cs @@ -0,0 +1,38 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Components.Applications +{ + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.ViewModels.Components.Applications; + + /// + /// Shared component that will englobe all applications where only one needs to be selected + /// + public partial class SingleEngineeringModelApplicationTemplate + { + } +} diff --git a/COMET.Web.Common/Components/SingleIterationApplicationBase.razor b/COMET.Web.Common/Components/Applications/SingleIterationApplicationBase.razor similarity index 79% rename from COMET.Web.Common/Components/SingleIterationApplicationBase.razor rename to COMET.Web.Common/Components/Applications/SingleIterationApplicationBase.razor index 4ba825c4..95b4d246 100644 --- a/COMET.Web.Common/Components/SingleIterationApplicationBase.razor +++ b/COMET.Web.Common/Components/Applications/SingleIterationApplicationBase.razor @@ -19,6 +19,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -------------------------------------------------------------------------------> -@namespace COMET.Web.Common.Components -@typeparam TViewModel where TViewModel: COMET.Web.Common.ViewModels.Components.ISingleIterationApplicationBaseViewModel -@inherits DisposableComponent +@namespace COMET.Web.Common.Components.Applications +@typeparam TViewModel where TViewModel: class, COMET.Web.Common.ViewModels.Components.Applications.ISingleIterationApplicationBaseViewModel +@inherits SingleThingApplicationBase diff --git a/COMET.Web.Common/Components/Applications/SingleIterationApplicationBase.razor.cs b/COMET.Web.Common/Components/Applications/SingleIterationApplicationBase.razor.cs new file mode 100644 index 00000000..abfab26c --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleIterationApplicationBase.razor.cs @@ -0,0 +1,75 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Components.Applications +{ + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.Utilities; + using COMET.Web.Common.ViewModels.Components.Applications; + + /// + /// Base component for any application that will need only one + /// + /// An + public abstract partial class SingleIterationApplicationBase + { + /// + /// Method invoked when the component is ready to start, having received its + /// initial parameters from its parent in the render tree. + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + this.NumberOfUrlRequiredParameters = 4; + } + + /// + /// Sets the URL parameters that are required for this application + /// + /// A of current URL parameters that comes form the URI + /// A of parameters that have to be included + protected override void SetUrlParameters(Dictionary currentOptions, Dictionary urlParameters) + { + base.SetUrlParameters(currentOptions, urlParameters); + + if (currentOptions.TryGetValue(QueryKeys.IterationKey, out var iterationValue)) + { + urlParameters[QueryKeys.IterationKey] = iterationValue; + } + + if (currentOptions.TryGetValue(QueryKeys.DomainKey, out var domainValue)) + { + urlParameters[QueryKeys.DomainKey] = domainValue; + } + + if (currentOptions.TryGetValue(QueryKeys.ModelKey, out var modelValue)) + { + urlParameters[QueryKeys.ModelKey] = modelValue; + } + } + } +} diff --git a/COMET.Web.Common/Components/SingleIterationApplicationTemplate.razor b/COMET.Web.Common/Components/Applications/SingleIterationApplicationTemplate.razor similarity index 80% rename from COMET.Web.Common/Components/SingleIterationApplicationTemplate.razor rename to COMET.Web.Common/Components/Applications/SingleIterationApplicationTemplate.razor index a0228ce5..549782a6 100644 --- a/COMET.Web.Common/Components/SingleIterationApplicationTemplate.razor +++ b/COMET.Web.Common/Components/Applications/SingleIterationApplicationTemplate.razor @@ -19,11 +19,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -------------------------------------------------------------------------------> -@namespace COMET.Web.Common.Components +@namespace COMET.Web.Common.Components.Applications +@inherits SingleThingApplicationTemplate -@inherits DisposableComponent - - @@ -39,13 +38,13 @@ else {
- @if (this.ViewModel.SelectedIteration is not null) + @if (this.ViewModel.SelectedThing is not null) { @if (this.ShowActiveModel) { } - +
@this.Body
diff --git a/COMET.Web.Common/Components/Applications/SingleIterationApplicationTemplate.razor.cs b/COMET.Web.Common/Components/Applications/SingleIterationApplicationTemplate.razor.cs new file mode 100644 index 00000000..a90bf3bc --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleIterationApplicationTemplate.razor.cs @@ -0,0 +1,108 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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.Applications +{ + using CDP4Common.EngineeringModelData; + + using CDP4Dal; + using CDP4Dal.Events; + + using COMET.Web.Common.Extensions; + using COMET.Web.Common.Utilities; + + using Microsoft.AspNetCore.Components; + + /// + /// Shared component that will englobe all applications where only one needs to be selected + /// + public partial class SingleIterationApplicationTemplate + { + /// + /// The of selected + /// + [Parameter] + public Guid IterationId { get; set; } + + /// + /// Method invoked when the component is ready to start, having received its + /// initial parameters from its parent in the render tree. + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + this.Disposables.Add(CDPMessageBus.Current.Listen() + .Subscribe(_ => this.InvokeAsync(this.SetCorrectUrl))); + } + + /// + /// Method invoked when the component has received parameters from its parent in + /// the render tree, and the incoming values have been assigned to properties. + /// + protected override void OnParametersSet() + { + base.OnParametersSet(); + + if (this.IterationId == Guid.Empty) + { + switch (this.ViewModel.SessionService.OpenIterations.Count) + { + case 1: + this.ViewModel.OnThingSelect(this.ViewModel.SessionService.OpenIterations.Items.First()); + break; + case > 1: + this.ViewModel.AskToSelectThing(); + break; + } + } + else if (this.IterationId != Guid.Empty && this.ViewModel.SelectedThing == null) + { + var iteration = this.ViewModel.SessionService.OpenIterations.Items.FirstOrDefault(x => x.Iid == this.IterationId); + + if (iteration != null) + { + this.ViewModel.OnThingSelect(iteration); + } + else + { + this.IterationId = Guid.Empty; + } + } + } + + /// + /// Set URL parameters based on the current context + /// + /// A of URL parameters + protected override void SetUrlParameters(Dictionary currentOptions) + { + base.SetUrlParameters(currentOptions); + + currentOptions[QueryKeys.IterationKey] = this.ViewModel.SelectedThing.Iid.ToShortGuid(); + currentOptions[QueryKeys.ModelKey] = this.ViewModel.SelectedThing.IterationSetup.Container.Iid.ToShortGuid(); + currentOptions[QueryKeys.DomainKey] = this.ViewModel.SessionService.GetDomainOfExpertise(this.ViewModel.SelectedThing).Iid.ToShortGuid(); + } + } +} diff --git a/COMET.Web.Common/Components/Applications/SingleThingApplicationBase.razor b/COMET.Web.Common/Components/Applications/SingleThingApplicationBase.razor new file mode 100644 index 00000000..3cc00eb8 --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleThingApplicationBase.razor @@ -0,0 +1,25 @@ + +@namespace COMET.Web.Common.Components.Applications +@typeparam TThing where TThing: CDP4Common.CommonData.Thing +@typeparam TViewModel where TViewModel: class, COMET.Web.Common.ViewModels.Components.Applications.ISingleThingApplicationBaseViewModel +@inherits ApplicationBase diff --git a/COMET.Web.Common/Components/Applications/SingleThingApplicationBase.razor.cs b/COMET.Web.Common/Components/Applications/SingleThingApplicationBase.razor.cs new file mode 100644 index 00000000..bdfb15f6 --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleThingApplicationBase.razor.cs @@ -0,0 +1,72 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Components.Applications +{ + using CDP4Common.CommonData; + + using COMET.Web.Common.ViewModels.Components.Applications; + + using Microsoft.AspNetCore.Components; + + using ReactiveUI; + + /// + /// Base component for any application that will need only one + /// + /// A + /// An + public abstract partial class SingleThingApplicationBase + { + /// + /// The + /// + [CascadingParameter] + public TThing CurrentThing { get; set; } + + /// + /// Method invoked when the component is ready to start, having received its + /// initial parameters from its parent in the render tree. + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.CurrentThing) + .Subscribe(_ => this.InvokeAsync(this.StateHasChanged))); + } + + /// + /// Method invoked when the component has received parameters from its parent in + /// the render tree, and the incoming values have been assigned to properties. + /// + protected override void OnParametersSet() + { + this.ViewModel.CurrentThing = this.CurrentThing; + + base.OnParametersSet(); + } + } +} diff --git a/COMET.Web.Common/Components/Applications/SingleThingApplicationTemplate.razor b/COMET.Web.Common/Components/Applications/SingleThingApplicationTemplate.razor new file mode 100644 index 00000000..702e22d1 --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleThingApplicationTemplate.razor @@ -0,0 +1,25 @@ + +@namespace COMET.Web.Common.Components.Applications +@typeparam TThing where TThing: CDP4Common.CommonData.Thing +@typeparam TViewModel where TViewModel: class, COMET.Web.Common.ViewModels.Components.Applications.ISingleThingApplicationTemplateViewModel +@inherits ApplicationTemplate \ No newline at end of file diff --git a/COMET.Web.Common/Components/Applications/SingleThingApplicationTemplate.razor.cs b/COMET.Web.Common/Components/Applications/SingleThingApplicationTemplate.razor.cs new file mode 100644 index 00000000..39bad464 --- /dev/null +++ b/COMET.Web.Common/Components/Applications/SingleThingApplicationTemplate.razor.cs @@ -0,0 +1,97 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Components.Applications +{ + using System.Reactive.Linq; + + using CDP4Common.CommonData; + + using COMET.Web.Common.Extensions; + using COMET.Web.Common.ViewModels.Components.Applications; + + using Microsoft.AspNetCore.Components; + using Microsoft.AspNetCore.WebUtilities; + + using ReactiveUI; + + /// + /// Shared component that will englobe all applications where only one needs to be selected + /// + /// Any + /// Any + public abstract partial class SingleThingApplicationTemplate + { + /// + /// A property to show the active model + /// + [Parameter] + public bool ShowActiveModel { get; set; } + + /// + /// Method invoked when the component is ready to start, having received its + /// initial parameters from its parent in the render tree. + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsOnSelectionMode) + .Merge(this.ViewModel.SessionService.OpenIterations.CountChanged.Select(_ => true)) + .Subscribe(_ => this.InvokeAsync(this.StateHasChanged))); + + this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.SelectedThing) + .Subscribe(_ => this.SetCorrectUrl())); + } + + /// + /// Sets the correct url based on the selected + /// + internal void SetCorrectUrl() + { + var urlPage = this.NavigationManager.Uri.Replace(this.NavigationManager.BaseUri, string.Empty).Split('?')[0]; + var currentOptions = this.NavigationManager.Uri.GetParametersFromUrl(); + + if (this.ViewModel.SelectedThing != null) + { + this.SetUrlParameters(currentOptions); + } + else + { + currentOptions.Clear(); + } + + var targetOptions = new Dictionary(); + + foreach (var currentOption in currentOptions.Where(x => !string.IsNullOrEmpty(x.Value))) + { + targetOptions[currentOption.Key] = currentOption.Value; + } + + var targetUrl = QueryHelpers.AddQueryString(urlPage, targetOptions); + this.NavigationManager.NavigateTo(targetUrl); + } + } +} diff --git a/COMET.Web.Common/Components/Selectors/EngineeringModelSelector.razor b/COMET.Web.Common/Components/Selectors/EngineeringModelSelector.razor new file mode 100644 index 00000000..b84555e5 --- /dev/null +++ b/COMET.Web.Common/Components/Selectors/EngineeringModelSelector.razor @@ -0,0 +1,34 @@ + +@namespace COMET.Web.Common.Components.Selectors +@using CDP4Common.SiteDirectoryData + + + + + + + \ No newline at end of file diff --git a/COMET.Web.Common/Components/Selectors/EngineeringModelSelector.razor.cs b/COMET.Web.Common/Components/Selectors/EngineeringModelSelector.razor.cs new file mode 100644 index 00000000..e48d2ef4 --- /dev/null +++ b/COMET.Web.Common/Components/Selectors/EngineeringModelSelector.razor.cs @@ -0,0 +1,45 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Components.Selectors +{ + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.ViewModels.Components.Selectors; + + using Microsoft.AspNetCore.Components; + + /// + /// Selector for + /// + public partial class EngineeringModelSelector + { + /// + /// Gets or sets the + /// + [Parameter] + public IEngineeringModelSelectorViewModel ViewModel { get; set; } + } +} diff --git a/COMET.Web.Common/Components/SingleIterationApplicationTemplate.razor.cs b/COMET.Web.Common/Components/SingleIterationApplicationTemplate.razor.cs deleted file mode 100644 index 11a294e0..00000000 --- a/COMET.Web.Common/Components/SingleIterationApplicationTemplate.razor.cs +++ /dev/null @@ -1,176 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2023 RHEA System S.A. -// -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar -// -// This file is part of COMET WEB Community Edition -// The COMET WEB Community Edition is the RHEA 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 -{ - using System; - using System.Reactive.Linq; - - using CDP4Common.EngineeringModelData; - - using CDP4Dal; - using CDP4Dal.Events; - - using COMET.Web.Common.Extensions; - using COMET.Web.Common.Services.ConfigurationService; - using COMET.Web.Common.Utilities; - using COMET.Web.Common.ViewModels.Components; - - using Microsoft.AspNetCore.Components; - using Microsoft.AspNetCore.WebUtilities; - - using ReactiveUI; - - /// - /// Shared component that will englobe all applications where only one needs to be selected - /// - public partial class SingleIterationApplicationTemplate: DisposableComponent - { - /// - /// Body of the application - /// - [Parameter] - public RenderFragment Body { get; set; } - - /// - /// A property to show the active model - /// - [Parameter] - public bool ShowActiveModel { get; set; } - - /// - /// The of selected - /// - [Parameter] - public Guid IterationId { get; set; } - - /// - /// The - /// - [Inject] - public ISingleIterationApplicationTemplateViewModel ViewModel { get; set; } - - /// - /// The - /// - [Inject] - public NavigationManager NavigationManager { get; set; } - - /// - /// The - /// - [Inject] - public IConfigurationService ServerConnectionService { get; set; } - - /// - /// Method invoked when the component is ready to start, having received its - /// initial parameters from its parent in the render tree. - /// - protected override void OnInitialized() - { - base.OnInitialized(); - - this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsOnIterationSelectionMode) - .Merge(this.ViewModel.SessionService.OpenIterations.CountChanged.Select(_ => true)) - .Subscribe(_ => this.InvokeAsync(this.StateHasChanged))); - - this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.SelectedIteration) - .Select(_ => true) - .Merge(CDPMessageBus.Current.Listen().Select(_ => true)) - .Subscribe(_ => this.InvokeAsync(this.SetCorrectUrl))); - } - - /// - /// Method invoked when the component has received parameters from its parent in - /// the render tree, and the incoming values have been assigned to properties. - /// - protected override void OnParametersSet() - { - base.OnParametersSet(); - - if (this.IterationId == Guid.Empty) - { - switch (this.ViewModel.SessionService.OpenIterations.Count) - { - case 1: - this.ViewModel.SelectIteration(this.ViewModel.SessionService.OpenIterations.Items.First()); - break; - case > 1: - this.ViewModel.AskToSelectIteration(); - break; - } - } - else if(this.IterationId != Guid.Empty && this.ViewModel.SelectedIteration == null) - { - var iteration = this.ViewModel.SessionService.OpenIterations.Items.FirstOrDefault(x => x.Iid == this.IterationId); - - if (iteration != null) - { - this.ViewModel.SelectIteration(iteration); - } - else - { - this.IterationId = Guid.Empty; - } - } - } - - /// - /// Sets the correct url based on the selected - /// - internal void SetCorrectUrl() - { - var urlPage = this.NavigationManager.Uri.Replace(this.NavigationManager.BaseUri, string.Empty).Split('?')[0]; - - var currentOptions = this.NavigationManager.Uri.GetParametersFromUrl(); - - if (this.ViewModel.SelectedIteration != null) - { - currentOptions[QueryKeys.IterationKey] = this.ViewModel.SelectedIteration.Iid.ToShortGuid(); - currentOptions[QueryKeys.ModelKey] = this.ViewModel.SelectedIteration.IterationSetup.Container.Iid.ToShortGuid(); - - if (string.IsNullOrEmpty(this.ServerConnectionService.ServerConfiguration.ServerAddress)) - { - currentOptions[QueryKeys.ServerKey] = this.ViewModel.SessionService.Session.DataSourceUri; - - } - currentOptions[QueryKeys.DomainKey] = this.ViewModel.SessionService.GetDomainOfExpertise(this.ViewModel.SelectedIteration).Iid.ToShortGuid(); - } - else - { - currentOptions.Clear(); - } - - var targetOptions = new Dictionary(); - - foreach (var currentOption in currentOptions.Where(x => !string.IsNullOrEmpty(x.Value))) - { - targetOptions[currentOption.Key] = currentOption.Value; - } - - var targetUrl = QueryHelpers.AddQueryString(urlPage, targetOptions); - this.NavigationManager.NavigateTo(targetUrl); - } - } -} diff --git a/COMET.Web.Common/Extensions/ServiceCollectionExtensions.cs b/COMET.Web.Common/Extensions/ServiceCollectionExtensions.cs index 3d9bb1b1..c6272e65 100644 --- a/COMET.Web.Common/Extensions/ServiceCollectionExtensions.cs +++ b/COMET.Web.Common/Extensions/ServiceCollectionExtensions.cs @@ -35,6 +35,7 @@ namespace COMET.Web.Common.Extensions using COMET.Web.Common.Services.StringTableService; using COMET.Web.Common.Services.VersionService; using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Publications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMET.Web.Common.ViewModels.Shared.TopMenuEntry; diff --git a/COMET.Web.Common/Pages/ApplicationPageTemplate.razor b/COMET.Web.Common/Pages/ApplicationPageTemplate.razor new file mode 100644 index 00000000..c40182b3 --- /dev/null +++ b/COMET.Web.Common/Pages/ApplicationPageTemplate.razor @@ -0,0 +1,22 @@ + +@attribute [Authorize] diff --git a/COMET.Web.Common/Pages/ApplicationPageTemplate.razor.cs b/COMET.Web.Common/Pages/ApplicationPageTemplate.razor.cs new file mode 100644 index 00000000..da910ba4 --- /dev/null +++ b/COMET.Web.Common/Pages/ApplicationPageTemplate.razor.cs @@ -0,0 +1,37 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Pages +{ + using Microsoft.AspNetCore.Components; + + /// + /// Base abstract component for any page for an Application + /// + public abstract partial class ApplicationPageTemplate: ComponentBase + { + } +} diff --git a/COMET.Web.Common/Pages/SingleEngineeringModelPageTemplate.razor b/COMET.Web.Common/Pages/SingleEngineeringModelPageTemplate.razor new file mode 100644 index 00000000..be127b97 --- /dev/null +++ b/COMET.Web.Common/Pages/SingleEngineeringModelPageTemplate.razor @@ -0,0 +1,24 @@ + +@namespace COMET.Web.Common.Pages +@inherits ApplicationPageTemplate + diff --git a/COMET.Web.Common/Pages/SingleEngineeringModelPageTemplate.razor.cs b/COMET.Web.Common/Pages/SingleEngineeringModelPageTemplate.razor.cs new file mode 100644 index 00000000..8b990901 --- /dev/null +++ b/COMET.Web.Common/Pages/SingleEngineeringModelPageTemplate.razor.cs @@ -0,0 +1,65 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Pages +{ + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.Extensions; + + using Microsoft.AspNetCore.Components; + + /// + /// Base abstract component for any page that should use only one + /// + public abstract partial class SingleEngineeringModelPageTemplate + { + /// + /// The of an as a short string + /// + [Parameter] + [SupplyParameterFromQuery] + public string ModelId { get; set; } + + /// + /// The of the requested + /// + protected Guid RequestedEngineeringModel { get; private set; } + + /// + /// Method invoked when the component has received parameters from its parent in + /// the render tree, and the incoming values have been assigned to properties. + /// + protected override void OnParametersSet() + { + base.OnParametersSet(); + + if (!string.IsNullOrEmpty(this.ModelId)) + { + this.RequestedEngineeringModel = this.ModelId.FromShortGuid(); + } + } + } +} diff --git a/COMET.Web.Common/Pages/SingleIterationPageTemplate.razor b/COMET.Web.Common/Pages/SingleIterationPageTemplate.razor index b82503ea..1bfa5af1 100644 --- a/COMET.Web.Common/Pages/SingleIterationPageTemplate.razor +++ b/COMET.Web.Common/Pages/SingleIterationPageTemplate.razor @@ -20,4 +20,4 @@ // limitations under the License. -------------------------------------------------------------------------------> @namespace COMET.Web.Common.Pages -@attribute [Authorize] +@inherits ApplicationPageTemplate \ No newline at end of file diff --git a/COMET.Web.Common/Services/SessionManagement/ISessionService.cs b/COMET.Web.Common/Services/SessionManagement/ISessionService.cs index 944d90b0..68e4a680 100644 --- a/COMET.Web.Common/Services/SessionManagement/ISessionService.cs +++ b/COMET.Web.Common/Services/SessionManagement/ISessionService.cs @@ -53,6 +53,11 @@ public interface ISessionService ///
bool IsSessionOpen { get; set; } + /// + /// Gets a readonly collection of open + /// + IReadOnlyCollection OpenEngineeringModels { get; } + /// /// Retrieves the that is loaded in the /// diff --git a/COMET.Web.Common/Services/SessionManagement/SessionService.cs b/COMET.Web.Common/Services/SessionManagement/SessionService.cs index eb213819..34b7a22a 100644 --- a/COMET.Web.Common/Services/SessionManagement/SessionService.cs +++ b/COMET.Web.Common/Services/SessionManagement/SessionService.cs @@ -1,4 +1,4 @@ -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2023 RHEA System S.A. // @@ -54,6 +54,11 @@ public class SessionService : ReactiveObject, ISessionService ///
private readonly Logger logger = LogManager.GetCurrentClassLogger(); + /// + /// Gets a readonly collection of open + /// + public IReadOnlyCollection OpenEngineeringModels => this.QueryOpenEngineeringModels(); + /// /// Gets or sets the /// @@ -103,7 +108,7 @@ public async Task ReadIteration(IterationSetup iterationSetup, DomainOfExpertise { var modelSetup = (EngineeringModelSetup)iterationSetup.Container; var model = new EngineeringModel(modelSetup.EngineeringModelIid, this.Session.Assembler.Cache, this.Session.Credentials.Uri); - + var iteration = new Iteration(iterationSetup.IterationIid, this.Session.Assembler.Cache, this.Session.Credentials.Uri) { Container = model @@ -440,5 +445,15 @@ public DomainOfExpertise GetDomainOfExpertise(Iteration iteration) return participantInformation.Item1; } + + /// + /// Queries all open + /// + /// A collection of + private List QueryOpenEngineeringModels() + { + return this.OpenIterations.Items.Select(x => (EngineeringModel)x.Container) + .DistinctBy(x => x.Iid).ToList(); + } } } diff --git a/COMET.Web.Common/ViewModels/Components/Applications/ApplicationBaseViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/ApplicationBaseViewModel.cs new file mode 100644 index 00000000..2929e485 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/ApplicationBaseViewModel.cs @@ -0,0 +1,87 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using System.Reactive.Linq; + + using CDP4Dal; + using CDP4Dal.Events; + + using COMET.Web.Common.Extensions; + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.Utilities.HaveObjectChangedTracking; + + using ReactiveUI; + + /// + /// Base view model for any application + /// + public abstract class ApplicationBaseViewModel : HaveObjectChangedTracking, IApplicationBaseViewModel + { + /// + /// Backing field for + /// + private bool isLoading; + + /// + /// Initialize a new instance of + /// + /// The + protected ApplicationBaseViewModel(ISessionService sessionService) + { + this.Disposables.Add(CDPMessageBus.Current.Listen() + .Where(x => x.Status == SessionStatus.EndUpdate) + .SubscribeAsync(_ => this.OnSessionRefreshed())); + + this.SessionService = sessionService; + } + + /// + /// The + /// + protected ISessionService SessionService { get; private set; } + + /// + /// Value asserting that the view model has set initial values at least once + /// + public bool HasSetInitialValuesOnce { get; set; } + + /// + /// Value asserting that the current is loading + /// + public bool IsLoading + { + get => this.isLoading; + set => this.RaiseAndSetIfChanged(ref this.isLoading, value); + } + + /// + /// Handles the refresh of the current + /// + /// A + protected abstract Task OnSessionRefreshed(); + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/ApplicationTemplateViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/ApplicationTemplateViewModel.cs new file mode 100644 index 00000000..c8f42b81 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/ApplicationTemplateViewModel.cs @@ -0,0 +1,50 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.Utilities.DisposableObject; + + /// + /// Base ViewModel that will englobe all applications + /// + public class ApplicationTemplateViewModel : DisposableObject, IApplicationTemplateViewModel + { + /// + /// Initializes a new + /// + /// The + protected ApplicationTemplateViewModel(ISessionService sessionService) + { + this.SessionService = sessionService; + } + + /// + /// Gets the + /// + public ISessionService SessionService { get; } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/IApplicationBaseViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/IApplicationBaseViewModel.cs new file mode 100644 index 00000000..633b6b86 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/IApplicationBaseViewModel.cs @@ -0,0 +1,45 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using COMET.Web.Common.Utilities.DisposableObject; + + /// + /// Base view model for any application + /// + public interface IApplicationBaseViewModel : IDisposableObject + { + /// + /// Value asserting that the view model has set initial values at least once + /// + bool HasSetInitialValuesOnce { get; set; } + + /// + /// Value asserting that the current is loading + /// + bool IsLoading { get; set; } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/IApplicationTemplateViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/IApplicationTemplateViewModel.cs new file mode 100644 index 00000000..6a5b7177 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/IApplicationTemplateViewModel.cs @@ -0,0 +1,41 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.Utilities.DisposableObject; + + /// + /// Base ViewModel that will englobe all applications + /// + public interface IApplicationTemplateViewModel: IDisposableObject + { + /// + /// Gets the + /// + ISessionService SessionService { get; } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/ISingleEngineeringModelApplicationBaseViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/ISingleEngineeringModelApplicationBaseViewModel.cs new file mode 100644 index 00000000..227409f7 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/ISingleEngineeringModelApplicationBaseViewModel.cs @@ -0,0 +1,36 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using CDP4Common.EngineeringModelData; + + /// + /// Base view model for any application that will need only one + /// + public interface ISingleEngineeringModelApplicationBaseViewModel : ISingleThingApplicationBaseViewModel + { + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/ISingleEngineeringModelApplicationTemplateViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/ISingleEngineeringModelApplicationTemplateViewModel.cs new file mode 100644 index 00000000..0760922c --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/ISingleEngineeringModelApplicationTemplateViewModel.cs @@ -0,0 +1,42 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.ViewModels.Components.Selectors; + + /// + /// ViewModel that will englobe all applications where only one needs to be selected + /// + public interface ISingleEngineeringModelApplicationTemplateViewModel: ISingleThingApplicationTemplateViewModel + { + /// + /// Gets the + /// + IEngineeringModelSelectorViewModel EngineeringModelSelectorViewModel { get; } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/ISingleIterationApplicationBaseViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/ISingleIterationApplicationBaseViewModel.cs similarity index 72% rename from COMET.Web.Common/ViewModels/Components/ISingleIterationApplicationBaseViewModel.cs rename to COMET.Web.Common/ViewModels/Components/Applications/ISingleIterationApplicationBaseViewModel.cs index a425f28d..fe2ed723 100644 --- a/COMET.Web.Common/ViewModels/Components/ISingleIterationApplicationBaseViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Applications/ISingleIterationApplicationBaseViewModel.cs @@ -23,36 +23,19 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.ViewModels.Components +namespace COMET.Web.Common.ViewModels.Components.Applications { using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; - using COMET.Web.Common.Utilities.DisposableObject; - /// /// Base view model for any application that will need only one /// - public interface ISingleIterationApplicationBaseViewModel : IDisposableObject + public interface ISingleIterationApplicationBaseViewModel : ISingleThingApplicationBaseViewModel { - /// - /// The current to work with - /// - Iteration CurrentIteration { get; set; } - - /// - /// Value asserting that the view model has set initial values at least once - /// - bool HasSetInitialValuesOnce { get; set; } - /// /// Gets the current /// DomainOfExpertise CurrentDomain { get; } - - /// - /// Value asserting that the current is loading - /// - bool IsLoading { get; set; } } } diff --git a/COMET.Web.Common/ViewModels/Components/ISingleIterationApplicationTemplateViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/ISingleIterationApplicationTemplateViewModel.cs similarity index 54% rename from COMET.Web.Common/ViewModels/Components/ISingleIterationApplicationTemplateViewModel.cs rename to COMET.Web.Common/ViewModels/Components/Applications/ISingleIterationApplicationTemplateViewModel.cs index 22a72634..5d51385e 100644 --- a/COMET.Web.Common/ViewModels/Components/ISingleIterationApplicationTemplateViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Applications/ISingleIterationApplicationTemplateViewModel.cs @@ -1,4 +1,4 @@ -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2023 RHEA System S.A. // @@ -22,53 +22,26 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.ViewModels.Components +namespace COMET.Web.Common.ViewModels.Components.Applications { using CDP4Common.EngineeringModelData; - using COMET.Web.Common.Model; - using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.Model; using COMET.Web.Common.ViewModels.Components.Selectors; /// /// ViewModel that will englobe all applications where only one needs to be selected /// - public interface ISingleIterationApplicationTemplateViewModel - { - /// - /// Gets the - /// - ISessionService SessionService { get; } - - /// - /// Gets the - /// - IIterationSelectorViewModel IterationSelectorViewModel { get; } - - /// - /// Value asserting that the user should select an - /// - bool IsOnIterationSelectionMode { get; set; } - - /// - /// The of the that will be used - /// - Iteration SelectedIteration { get; set; } - - /// - /// The that will be used - /// - IterationData SelectedIterationData { get; set; } - - /// - /// Selects an - /// - /// The selected - void SelectIteration(Iteration iteration); - - /// - /// Asks the user to selects the that he wants to works with - /// - void AskToSelectIteration(); - } + public interface ISingleIterationApplicationTemplateViewModel : ISingleThingApplicationTemplateViewModel + { + /// + /// The that will be used + /// + IterationData SelectedIterationData { get; set; } + + /// + /// Gets the + /// + IIterationSelectorViewModel IterationSelectorViewModel { get; } + } } diff --git a/COMET.Web.Common/ViewModels/Components/Applications/ISingleThingApplicationBaseViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/ISingleThingApplicationBaseViewModel.cs new file mode 100644 index 00000000..30e562d9 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/ISingleThingApplicationBaseViewModel.cs @@ -0,0 +1,41 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using CDP4Common.CommonData; + + /// + /// Base view model for any application that will need only one + /// + /// Any + public interface ISingleThingApplicationBaseViewModel : IApplicationBaseViewModel where TThing : Thing + { + /// + /// The current to work with + /// + TThing CurrentThing { get; set; } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/ISingleThingApplicationTemplateViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/ISingleThingApplicationTemplateViewModel.cs new file mode 100644 index 00000000..9f9b69b6 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/ISingleThingApplicationTemplateViewModel.cs @@ -0,0 +1,64 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using CDP4Common.CommonData; + + using COMET.Web.Common.ViewModels.Components.Selectors; + + /// + /// ViewModel that will englobe all applications where only one needs to be selected + /// + /// Any + public interface ISingleThingApplicationTemplateViewModel: IApplicationTemplateViewModel where TThing : Thing + { + /// + /// Value asserting that the user should select an + /// + bool IsOnSelectionMode { get; set; } + + /// + /// Gets or sets the selected + /// + TThing SelectedThing { get; set; } + + /// + /// Gets the + /// + IThingSelectorViewModel SelectorViewModel { get; } + + /// + /// Asks the user to selects the that he wants to works with + /// + void AskToSelectThing(); + + /// + /// Selects a + /// + /// The newly selected + void OnThingSelect(TThing thing); + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/SingleEngineeringModelApplicationBaseViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/SingleEngineeringModelApplicationBaseViewModel.cs new file mode 100644 index 00000000..22a4952d --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/SingleEngineeringModelApplicationBaseViewModel.cs @@ -0,0 +1,45 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.Services.SessionManagement; + + /// + /// Base view model for any application that will need only one + /// + public abstract class SingleEngineeringModelApplicationBaseViewModel : SingleThingApplicationBaseViewModel, ISingleEngineeringModelApplicationBaseViewModel + { + /// + /// Initializes a new + /// + /// The + protected SingleEngineeringModelApplicationBaseViewModel(ISessionService sessionService) : base(sessionService) + { + } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/SingleEngineeringModelApplicationTemplateViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/SingleEngineeringModelApplicationTemplateViewModel.cs new file mode 100644 index 00000000..95dfca1d --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/SingleEngineeringModelApplicationTemplateViewModel.cs @@ -0,0 +1,72 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using CDP4Common.EngineeringModelData; + + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.ViewModels.Components.Selectors; + + /// + /// ViewModel that will englobe all applications where only one needs to be selected + /// + public class SingleEngineeringModelApplicationTemplateViewModel : SingleThingApplicationTemplateViewModel, ISingleEngineeringModelApplicationTemplateViewModel + { + /// + /// Initializes a new + /// + /// The + /// The + public SingleEngineeringModelApplicationTemplateViewModel(ISessionService sessionService, IEngineeringModelSelectorViewModel modelSelector) : base(sessionService, modelSelector) + { + this.Disposables.Add(this.SessionService.OpenIterations.CountChanged.Subscribe(_ => this.OnOpenIterationCountChanged())); + } + + /// + /// Gets the + /// + public IEngineeringModelSelectorViewModel EngineeringModelSelectorViewModel => this.SelectorViewModel as IEngineeringModelSelectorViewModel; + + /// + /// Updates this view model properties + /// + protected override void UpdateProperties() + { + this.SelectorViewModel.UpdateProperties(this.SessionService.OpenEngineeringModels); + } + + /// + /// Handles the change of opened + /// + private void OnOpenIterationCountChanged() + { + if (this.SessionService.OpenEngineeringModels.Count is 0 or 1) + { + this.SelectedThing = this.SessionService.OpenEngineeringModels.FirstOrDefault(); + } + } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/SingleIterationApplicationBaseViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/SingleIterationApplicationBaseViewModel.cs similarity index 51% rename from COMET.Web.Common/ViewModels/Components/SingleIterationApplicationBaseViewModel.cs rename to COMET.Web.Common/ViewModels/Components/Applications/SingleIterationApplicationBaseViewModel.cs index e748090b..b6ea55e4 100644 --- a/COMET.Web.Common/ViewModels/Components/SingleIterationApplicationBaseViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Applications/SingleIterationApplicationBaseViewModel.cs @@ -1,4 +1,4 @@ -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2023 RHEA System S.A. // @@ -23,10 +23,8 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.ViewModels.Components +namespace COMET.Web.Common.ViewModels.Components.Applications { - using System.Reactive.Linq; - using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; @@ -35,91 +33,33 @@ namespace COMET.Web.Common.ViewModels.Components using COMET.Web.Common.Extensions; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.Utilities.HaveObjectChangedTracking; - - using DynamicData.Binding; - - using ReactiveUI; /// /// Base view model for any application that will need only one /// - public abstract class SingleIterationApplicationBaseViewModel : HaveObjectChangedTracking, ISingleIterationApplicationBaseViewModel + public abstract class SingleIterationApplicationBaseViewModel : SingleThingApplicationBaseViewModel, ISingleIterationApplicationBaseViewModel { - /// - /// Backing field for - /// - private Iteration currentIteration; - - /// - /// Backing field for - /// - private bool isLoading; - /// /// Initializes a new instance of the class. /// /// The - protected SingleIterationApplicationBaseViewModel(ISessionService sessionService) + protected SingleIterationApplicationBaseViewModel(ISessionService sessionService) : base(sessionService) { - this.Disposables.Add(this.WhenAnyPropertyChanged(nameof(this.CurrentIteration)) - .SubscribeAsync(_ => this.OnIterationChanged())); - this.Disposables.Add(CDPMessageBus.Current.Listen().SubscribeAsync(_ => this.OnDomainChanged())); - - this.Disposables.Add(CDPMessageBus.Current.Listen() - .Where(x => x.Status == SessionStatus.EndUpdate) - .Subscribe(_ => this.OnSessionRefreshed())); - - this.SessionService = sessionService; } - /// - /// The - /// - protected ISessionService SessionService { get; private set; } - /// /// Gets the current /// public DomainOfExpertise CurrentDomain { get; protected set; } - /// - /// Value asserting that the current is loading - /// - public bool IsLoading - { - get => this.isLoading; - set => this.RaiseAndSetIfChanged(ref this.isLoading, value); - } - - /// - /// The current to work with - /// - public Iteration CurrentIteration - { - get => this.currentIteration; - set => this.RaiseAndSetIfChanged(ref this.currentIteration, value); - } - - /// - /// Value asserting that the view model has set initial values at least once - /// - public bool HasSetInitialValuesOnce { get; set; } - - /// - /// Handles the refresh of the current - /// - /// A - protected abstract Task OnSessionRefreshed(); - /// /// Handles the change of /// /// A protected virtual Task OnDomainChanged() { - this.CurrentDomain = this.CurrentIteration == null ? null : this.SessionService.GetDomainOfExpertise(this.CurrentIteration); + this.CurrentDomain = this.CurrentThing == null ? null : this.SessionService.GetDomainOfExpertise(this.CurrentThing); return Task.CompletedTask; } @@ -127,26 +67,21 @@ protected virtual Task OnDomainChanged() /// Update this view model properties when the has changed ///
/// A - protected virtual async Task OnIterationChanged() + protected override async Task OnThingChanged() { this.IsLoading = true; - this.CurrentDomain = this.CurrentIteration == null ? null : this.SessionService.GetDomainOfExpertise(this.CurrentIteration); + this.CurrentDomain = this.CurrentThing == null ? null : this.SessionService.GetDomainOfExpertise(this.CurrentThing); await Task.CompletedTask; } /// - /// The logic used to check if a change should be recorded an + /// The logic used to check if a change should be recorded an /// - /// The + /// The /// true if the change should be recorded, false otherwise protected override bool ShouldRecordChange(ObjectChangedEvent objectChangedEvent) { - if (this.CurrentIteration == null || objectChangedEvent.ChangedThing.GetContainerOfType()?.Iid != this.CurrentIteration.Iid) - { - return false; - } - - return true; + return this.CurrentThing != null && objectChangedEvent.ChangedThing.GetContainerOfType()?.Iid == this.CurrentThing.Iid; } } } diff --git a/COMET.Web.Common/ViewModels/Components/SingleIterationApplicationTemplateViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/SingleIterationApplicationTemplateViewModel.cs similarity index 53% rename from COMET.Web.Common/ViewModels/Components/SingleIterationApplicationTemplateViewModel.cs rename to COMET.Web.Common/ViewModels/Components/Applications/SingleIterationApplicationTemplateViewModel.cs index e8376552..9ed70210 100644 --- a/COMET.Web.Common/ViewModels/Components/SingleIterationApplicationTemplateViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Applications/SingleIterationApplicationTemplateViewModel.cs @@ -22,98 +22,55 @@ //
// -------------------------------------------------------------------------------------------------------------------- -namespace COMET.Web.Common.ViewModels.Components +namespace COMET.Web.Common.ViewModels.Components.Applications { using CDP4Common.EngineeringModelData; - using COMET.Web.Common.Model; - using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.Utilities.DisposableObject; + using COMET.Web.Common.Model; + using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.ViewModels.Components.Selectors; - using Microsoft.AspNetCore.Components; - - using ReactiveUI; - /// /// ViewModel that will englobe all applications where only one needs to be selected /// - public class SingleIterationApplicationTemplateViewModel : DisposableObject, ISingleIterationApplicationTemplateViewModel + public class SingleIterationApplicationTemplateViewModel : SingleThingApplicationTemplateViewModel, ISingleIterationApplicationTemplateViewModel { - /// - /// Backing field for - /// - private bool isOnIterationSelectionMode; - - /// - /// Backing field for - /// - private Iteration selectedIteration; - - /// - /// The that will be used - /// - public IterationData SelectedIterationData { get; set; } - /// /// Initializes a new instance of the class. /// /// The /// The - public SingleIterationApplicationTemplateViewModel(ISessionService sessionService, IIterationSelectorViewModel iterationSelectorViewModel) + public SingleIterationApplicationTemplateViewModel(ISessionService sessionService, IIterationSelectorViewModel iterationSelectorViewModel) : base(sessionService, iterationSelectorViewModel) { - this.SessionService = sessionService; - this.IterationSelectorViewModel = iterationSelectorViewModel; - this.IterationSelectorViewModel.OnSubmit = new EventCallbackFactory().Create(this, this.SelectIteration); this.Disposables.Add(this.SessionService.OpenIterations.CountChanged.Subscribe(_ => this.OnOpenIterationCountChanged())); } /// - /// Selects an + /// Gets the /// - /// The selected - public void SelectIteration(Iteration iteration) - { - this.SelectedIteration = iteration; - this.IsOnIterationSelectionMode = false; - this.SelectedIterationData = new IterationData(iteration.IterationSetup, true); - } + public IIterationSelectorViewModel IterationSelectorViewModel => this.SelectorViewModel as IIterationSelectorViewModel; /// - /// The that will be used + /// The that will be used /// - public Iteration SelectedIteration - { - get => this.selectedIteration; - set => this.RaiseAndSetIfChanged(ref this.selectedIteration, value); - } + public IterationData SelectedIterationData { get; set; } /// - /// Asks the user to selects the that he wants to works with + /// Selects a /// - public void AskToSelectIteration() + /// The newly selected + public override void OnThingSelect(Iteration thing) { - this.IterationSelectorViewModel.UpdateProperties(this.SessionService.OpenIterations.Items); - this.IsOnIterationSelectionMode = true; + base.OnThingSelect(thing); + this.SelectedIterationData = new IterationData(thing.IterationSetup, true); } /// - /// Gets the - /// - public ISessionService SessionService { get; } - - /// - /// Gets the - /// - public IIterationSelectorViewModel IterationSelectorViewModel { get; } - - /// - /// Value asserting that the user should select an + /// Updates this view model properties /// - public bool IsOnIterationSelectionMode + protected override void UpdateProperties() { - get => this.isOnIterationSelectionMode; - set => this.RaiseAndSetIfChanged(ref this.isOnIterationSelectionMode, value); + this.SelectorViewModel.UpdateProperties(this.SessionService.OpenIterations.Items); } /// @@ -123,7 +80,7 @@ private void OnOpenIterationCountChanged() { if (this.SessionService.OpenIterations.Count is 0 or 1) { - this.SelectedIteration = this.SessionService.OpenIterations.Items.FirstOrDefault(); + this.SelectedThing = this.SessionService.OpenIterations.Items.FirstOrDefault(); } } } diff --git a/COMET.Web.Common/ViewModels/Components/Applications/SingleThingApplicationBaseViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/SingleThingApplicationBaseViewModel.cs new file mode 100644 index 00000000..52863721 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/SingleThingApplicationBaseViewModel.cs @@ -0,0 +1,73 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using CDP4Common.CommonData; + + using COMET.Web.Common.Extensions; + using COMET.Web.Common.Services.SessionManagement; + + using DynamicData.Binding; + + using ReactiveUI; + + /// + /// Base view model for any application that will need only one + /// + /// Any + public abstract class SingleThingApplicationBaseViewModel : ApplicationBaseViewModel, ISingleThingApplicationBaseViewModel where TThing : Thing + { + /// + /// Backing field for + /// + private TThing currentThing; + + /// + /// Initializes a new + /// + /// The + protected SingleThingApplicationBaseViewModel(ISessionService sessionService) : base(sessionService) + { + this.Disposables.Add(this.WhenAnyPropertyChanged(nameof(this.CurrentThing)) + .SubscribeAsync(_ => this.OnThingChanged())); + } + + /// + /// The current to work with + /// + public TThing CurrentThing + { + get => this.currentThing; + set => this.RaiseAndSetIfChanged(ref this.currentThing, value); + } + + /// + /// Update this view model properties when the has changed + /// + /// A + protected abstract Task OnThingChanged(); + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Applications/SingleThingApplicationTemplateViewModel.cs b/COMET.Web.Common/ViewModels/Components/Applications/SingleThingApplicationTemplateViewModel.cs new file mode 100644 index 00000000..7d144ea3 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Applications/SingleThingApplicationTemplateViewModel.cs @@ -0,0 +1,111 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Applications +{ + using CDP4Common.CommonData; + + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.ViewModels.Components.Selectors; + + using Microsoft.AspNetCore.Components; + + using ReactiveUI; + + /// + /// Base ViewModel that will englobe all applications where only one needs to be selected + /// + /// Any + public abstract class SingleThingApplicationTemplateViewModel : ApplicationTemplateViewModel, ISingleThingApplicationTemplateViewModel where TThing : Thing + { + /// + /// Backing field for + /// + private bool isOnSelectionMode; + + /// + /// Backing field + /// + private TThing selectedThing; + + /// + /// Initializes a new + /// + /// The + /// The + protected SingleThingApplicationTemplateViewModel(ISessionService sessionService, IThingSelectorViewModel selectorViewModel) : base(sessionService) + { + this.SelectorViewModel = selectorViewModel; + this.SelectorViewModel.OnSubmit = new EventCallbackFactory().Create(this, this.OnThingSelect); + } + + /// + /// Gets the + /// + public IThingSelectorViewModel SelectorViewModel { get; } + + /// + /// Value asserting that the user should select an + /// + public bool IsOnSelectionMode + { + get => this.isOnSelectionMode; + set => this.RaiseAndSetIfChanged(ref this.isOnSelectionMode, value); + } + + /// + /// Gets or sets the selected + /// + public TThing SelectedThing + { + get => this.selectedThing; + set => this.RaiseAndSetIfChanged(ref this.selectedThing, value); + } + + /// + /// Asks the user to selects the that he wants to works with + /// + public void AskToSelectThing() + { + this.UpdateProperties(); + this.IsOnSelectionMode = true; + } + + /// + /// Selects a + /// + /// The newly selected + public virtual void OnThingSelect(TThing thing) + { + this.SelectedThing = thing; + this.IsOnSelectionMode = false; + } + + /// + /// Updates this view model properties + /// + protected abstract void UpdateProperties(); + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/EngineeringModelSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/EngineeringModelSelectorViewModel.cs new file mode 100644 index 00000000..64ad535b --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Selectors/EngineeringModelSelectorViewModel.cs @@ -0,0 +1,78 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Selectors +{ + using CDP4Common.EngineeringModelData; + using CDP4Common.SiteDirectoryData; + + using Microsoft.AspNetCore.Components; + + /// + /// View model that enable the user to select one selected + /// + public class EngineeringModelSelectorViewModel : IEngineeringModelSelectorViewModel + { + /// + /// A collection of available + /// + private IEnumerable engineeringModels; + + /// + /// The selected + /// + public EngineeringModelSetup SelectedEngineeringModelSetup { get; set; } + + /// + /// A collection of available + /// + public IEnumerable AvailableEngineeringModelSetups { get; set; } + + /// + /// to call when the has been selected + /// + public EventCallback OnSubmit { get; set; } + + /// + /// Updates this view model properties + /// + /// A collection of available + public void UpdateProperties(IEnumerable availableEngineeringModels) + { + this.engineeringModels = availableEngineeringModels; + this.AvailableEngineeringModelSetups = this.engineeringModels.Select(x => x.EngineeringModelSetup); + this.SelectedEngineeringModelSetup = null; + } + + /// + /// Submit the selection of the + /// + /// A + public Task Submit() + { + return this.OnSubmit.InvokeAsync(this.engineeringModels.First(x => x.Iid == this.SelectedEngineeringModelSetup.EngineeringModelIid)); + } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/IEngineeringModelSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/IEngineeringModelSelectorViewModel.cs new file mode 100644 index 00000000..b37b3dcc --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Selectors/IEngineeringModelSelectorViewModel.cs @@ -0,0 +1,52 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Selectors +{ + using CDP4Common.EngineeringModelData; + using CDP4Common.SiteDirectoryData; + + /// + /// View model that enable the user to select one selected + /// + public interface IEngineeringModelSelectorViewModel : IThingSelectorViewModel + { + /// + /// The selected + /// + EngineeringModelSetup SelectedEngineeringModelSetup { get; set; } + + /// + /// A collection of available + /// + IEnumerable AvailableEngineeringModelSetups { get; set; } + + /// + /// Submit the selection of the + /// + /// A + Task Submit(); + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/IIterationSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/IIterationSelectorViewModel.cs index 9e15148d..3b82ced0 100644 --- a/COMET.Web.Common/ViewModels/Components/Selectors/IIterationSelectorViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Selectors/IIterationSelectorViewModel.cs @@ -34,7 +34,7 @@ namespace COMET.Web.Common.ViewModels.Components.Selectors /// /// View model that enable the user to select one selected /// - public interface IIterationSelectorViewModel + public interface IIterationSelectorViewModel: IThingSelectorViewModel { /// /// The selected @@ -46,17 +46,6 @@ public interface IIterationSelectorViewModel /// IEnumerable AvailableIterations { get; set; } - /// - /// to call when the has been selected - /// - EventCallback OnSubmit { get; set; } - - /// - /// Updates this view model properties - /// - /// A collection of available - void UpdateProperties(IEnumerable availableIterations); - /// /// Submit the selection of the /// diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/IThingSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/IThingSelectorViewModel.cs new file mode 100644 index 00000000..d3531ff1 --- /dev/null +++ b/COMET.Web.Common/ViewModels/Components/Selectors/IThingSelectorViewModel.cs @@ -0,0 +1,49 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.ViewModels.Components.Selectors +{ + using CDP4Common.CommonData; + + using Microsoft.AspNetCore.Components; + + /// + /// View model that provide selection capabilities for a + /// + /// Any + public interface IThingSelectorViewModel where TThing: Thing + { + /// + /// Updates this view model properties + /// + /// A collection of available + void UpdateProperties(IEnumerable availableThings); + + /// + /// to call when the has been selected + /// + EventCallback OnSubmit { get; set; } + } +} diff --git a/COMET.Web.Common/ViewModels/Components/Selectors/IterationSelectorViewModel.cs b/COMET.Web.Common/ViewModels/Components/Selectors/IterationSelectorViewModel.cs index 70444dc5..bef57597 100644 --- a/COMET.Web.Common/ViewModels/Components/Selectors/IterationSelectorViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/Selectors/IterationSelectorViewModel.cs @@ -59,10 +59,10 @@ public class IterationSelectorViewModel : IIterationSelectorViewModel /// /// Updates this view model properties /// - /// A collection of available - public void UpdateProperties(IEnumerable availableIterations) + /// A collection of available + public void UpdateProperties(IEnumerable availableThings) { - this.iterations = availableIterations; + this.iterations = availableThings; this.AvailableIterations = this.iterations.Select(x => new IterationData(x.IterationSetup, true)); this.SelectedIteration = null; } diff --git a/COMET.Web.Common/_Imports.razor b/COMET.Web.Common/_Imports.razor index e65fc98f..72e1ea7a 100644 --- a/COMET.Web.Common/_Imports.razor +++ b/COMET.Web.Common/_Imports.razor @@ -1,4 +1,5 @@ @using COMET.Web.Common.Components +@using COMET.Web.Common.Components.Applications @using COMET.Web.Common.Components.Selectors @using COMET.Web.Common.Components.ParameterTypeEditors @using COMET.Web.Common.Shared diff --git a/COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs b/COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs index 6a5a756d..d1eea09b 100644 --- a/COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs +++ b/COMETwebapp.Tests/Components/BookEditor/BookEditorBodyTestFixture.cs @@ -27,7 +27,6 @@ namespace COMETwebapp.Tests.Components.BookEditor using Bunit; using CDP4Common.CommonData; - using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; using CDP4Common.SiteDirectoryData; @@ -87,7 +86,6 @@ public void Setup() availableBooks.Add(this.selectedBook); this.viewModel = new Mock(); - this.viewModel.Setup(x => x.CurrentIteration).Returns(new Iteration()); this.viewModel.Setup(x => x.CurrentDomain).Returns(new DomainOfExpertise()); this.viewModel.Setup(x => x.AvailableBooks).Returns(availableBooks); this.viewModel.Setup(x => x.SelectedBook).Returns(this.selectedBook); diff --git a/COMETwebapp.Tests/Components/ModelDashboard/ModelDashboardBodyTestFixture.cs b/COMETwebapp.Tests/Components/ModelDashboard/ModelDashboardBodyTestFixture.cs index 5e27b464..7fec8aa5 100644 --- a/COMETwebapp.Tests/Components/ModelDashboard/ModelDashboardBodyTestFixture.cs +++ b/COMETwebapp.Tests/Components/ModelDashboard/ModelDashboardBodyTestFixture.cs @@ -39,6 +39,8 @@ namespace COMETwebapp.Tests.Components.ModelDashboard using CDP4Dal.Events; using COMET.Web.Common.Extensions; + using COMET.Web.Common.Model.Configuration; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.Utilities; @@ -78,6 +80,9 @@ public void Setup() this.context.Services.AddSingleton(); this.context.Services.AddSingleton(); this.context.Services.AddSingleton(this.sessionService.Object); + var configuration = new Mock(); + configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + this.context.Services.AddSingleton(configuration.Object); this.viewModel = this.context.Services.GetService() as ModelDashboardBodyViewModel; } @@ -92,7 +97,7 @@ public void Teardown() public async Task VerifyModelDashboardComponent() { var renderer = this.context.RenderComponent(); - Assert.That(this.viewModel.CurrentIteration, Is.Null); + Assert.That(this.viewModel.CurrentThing, Is.Null); CDPMessageBus.Current.SendMessage(new DomainChangedEvent(null, null)); Assert.That(this.viewModel.CurrentDomain, Is.Null); @@ -256,7 +261,7 @@ public async Task VerifyModelDashboardComponent() parameter3.ValueSet.Add(new ParameterValueSet() { - ActualState = actualFiniteStateList.ActualState.First(), + ActualState = actualFiniteStateList.ActualState[0], Published = new ValueArray(compoundValues), Formula = new ValueArray(noValues), Manual = new ValueArray(compoundValues), @@ -265,7 +270,7 @@ public async Task VerifyModelDashboardComponent() parameter3.ValueSet.Add(new ParameterValueSet() { - ActualState = actualFiniteStateList.ActualState.Last(), + ActualState = actualFiniteStateList.ActualState[^1], Published = new ValueArray(compoundValues), Formula = new ValueArray(noValues), Manual = new ValueArray(compoundValues), @@ -284,7 +289,7 @@ public async Task VerifyModelDashboardComponent() iteration.Element.AddRange(new List{element1, element2, element3}); iteration.TopElement = element1; - this.viewModel.CurrentIteration = iteration; + this.viewModel.CurrentThing = iteration; await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading); Assert.Multiple(() => diff --git a/COMETwebapp.Tests/Components/ModelEditor/ElementDefinitionTableTestFixture.cs b/COMETwebapp.Tests/Components/ModelEditor/ElementDefinitionTableTestFixture.cs index e596f956..67848c43 100644 --- a/COMETwebapp.Tests/Components/ModelEditor/ElementDefinitionTableTestFixture.cs +++ b/COMETwebapp.Tests/Components/ModelEditor/ElementDefinitionTableTestFixture.cs @@ -28,17 +28,22 @@ namespace COMETwebapp.Tests.Components.ModelEditor using Bunit; + using COMET.Web.Common.Model.Configuration; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using COMETwebapp.Components.ModelEditor; using COMETwebapp.Services.Interoperability; using COMETwebapp.ViewModels.Components.ModelEditor; - using COMETwebapp.ViewModels.Components.SystemRepresentation; - using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; - using DevExpress.Blazor; - using Microsoft.Extensions.DependencyInjection; - using Moq; + using COMETwebapp.ViewModels.Components.SystemRepresentation; + using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; + + using DevExpress.Blazor; + + using Microsoft.Extensions.DependencyInjection; + + using Moq; using NUnit.Framework; @@ -59,12 +64,15 @@ public void SetUp() this.context.ConfigureDevExpressBlazor(); this.context.Services.AddSingleton(); this.context.Services.AddSingleton(); + var configuration = new Mock(); + configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + this.context.Services.AddSingleton(configuration.Object); this.elementDefinitionDetailsViewModel = new ElementDefinitionDetailsViewModel(); var elementDefinitionTableViewModel = new Mock(); - elementDefinitionTableViewModel.Setup(x => x.RowsTarget).Returns(new ObservableCollection() { new ElementDefinitionRowViewModel() { ElementDefinitionName = "Test" } }); - elementDefinitionTableViewModel.Setup(x => x.RowsSource).Returns(new ObservableCollection() { new ElementDefinitionRowViewModel() { ElementDefinitionName = "Test1" } }); + elementDefinitionTableViewModel.Setup(x => x.RowsTarget).Returns(new ObservableCollection { new() { ElementDefinitionName = "Test" } }); + elementDefinitionTableViewModel.Setup(x => x.RowsSource).Returns(new ObservableCollection { new() { ElementDefinitionName = "Test1" } }); elementDefinitionTableViewModel.Setup(x => x.ElementDefinitionDetailsViewModel).Returns(this.elementDefinitionDetailsViewModel); this.context.Services.AddSingleton(elementDefinitionTableViewModel.Object); @@ -80,6 +88,16 @@ public void TearDown() this.context.CleanContext(); } + [Test] + public async Task VerifyAddingElementDefinition() + { + var addButton = this.renderedComponent.FindComponents().First(x => x.Instance.Id == "addElementDefinition"); + + Assert.That(addButton.Instance, Is.Not.Null); + + await this.renderedComponent.InvokeAsync(addButton.Instance.Click.InvokeAsync); + } + [Test] public void VerifyComponent() { @@ -96,15 +114,5 @@ public void VerifyMoveGridRow() { Assert.That(() => this.table.MoveGridRow(1, 1, It.IsAny()), Throws.Nothing); } - - [Test] - public async Task VerifyAddingElementDefinition() - { - var addButton = this.renderedComponent.FindComponents().First(x => x.Instance.Id == "addElementDefinition"); - - Assert.That(addButton.Instance, Is.Not.Null); - - await this.renderedComponent.InvokeAsync(addButton.Instance.Click.InvokeAsync); - } - } + } } diff --git a/COMETwebapp.Tests/Components/ParameterEditor/ParameterEditorBodyTestFixture.cs b/COMETwebapp.Tests/Components/ParameterEditor/ParameterEditorBodyTestFixture.cs index 46415d53..3a4d1cc4 100644 --- a/COMETwebapp.Tests/Components/ParameterEditor/ParameterEditorBodyTestFixture.cs +++ b/COMETwebapp.Tests/Components/ParameterEditor/ParameterEditorBodyTestFixture.cs @@ -38,6 +38,8 @@ namespace COMETwebapp.Tests.Components.ParameterEditor using CDP4Dal.Permission; using COMET.Web.Common.Components.Selectors; + using COMET.Web.Common.Model.Configuration; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components.Selectors; @@ -89,6 +91,9 @@ public void SetUp() parameterEditorViewModel.Setup(x => x.ParameterTypeSelector).Returns(new ParameterTypeSelectorViewModel()); parameterEditorViewModel.Setup(x => x.ParameterTableViewModel).Returns(new ParameterTableViewModel(sessionService.Object)); + var configuration = new Mock(); + configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + this.context.Services.AddSingleton(configuration.Object); this.context.Services.AddSingleton(parameterEditorViewModel.Object); var parameterTableViewModelMock = new Mock(); diff --git a/COMETwebapp.Tests/Components/SubscriptionDashboard/SubscriptionDashboardBodyTestFixture.cs b/COMETwebapp.Tests/Components/SubscriptionDashboard/SubscriptionDashboardBodyTestFixture.cs index 3dd8a8e5..aba941fc 100644 --- a/COMETwebapp.Tests/Components/SubscriptionDashboard/SubscriptionDashboardBodyTestFixture.cs +++ b/COMETwebapp.Tests/Components/SubscriptionDashboard/SubscriptionDashboardBodyTestFixture.cs @@ -28,6 +28,8 @@ namespace COMETwebapp.Tests.Components.SubscriptionDashboard using CDP4Common.SiteDirectoryData; using COMET.Web.Common.Extensions; + using COMET.Web.Common.Model.Configuration; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.Utilities; @@ -66,6 +68,9 @@ public void Setup() this.viewModel = new SubscriptionDashboardBodyViewModel(this.sessionService.Object, this.subscribedTableViewModel); this.context.ConfigureDevExpressBlazor(); + var configuration = new Mock(); + configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + this.context.Services.AddSingleton(configuration.Object); this.context.Services.AddSingleton(this.viewModel); } @@ -82,7 +87,7 @@ public void VerifyWithoutInitializationValueComponent() _ = this.context.RenderComponent(parameters => { - parameters.Add(p => p.CurrentIteration, new Iteration()); + parameters.Add(p => p.CurrentThing, new Iteration()); }); Assert.Multiple(() => @@ -150,7 +155,7 @@ public void VerifyWithValidInitialValuesComponent() _ = this.context.RenderComponent(parameters => { - parameters.Add(p => p.CurrentIteration, iteration); + parameters.Add(p => p.CurrentThing, iteration); }); Assert.Multiple(() => diff --git a/COMETwebapp.Tests/Components/SystemRepresentation/SystemRepresentationBodyTestFixture.cs b/COMETwebapp.Tests/Components/SystemRepresentation/SystemRepresentationBodyTestFixture.cs index b73122f2..b5ea94c6 100644 --- a/COMETwebapp.Tests/Components/SystemRepresentation/SystemRepresentationBodyTestFixture.cs +++ b/COMETwebapp.Tests/Components/SystemRepresentation/SystemRepresentationBodyTestFixture.cs @@ -36,11 +36,12 @@ namespace COMETwebapp.Tests.Components.SystemRepresentation using CDP4Dal.DAL; using COMET.Web.Common.Components.Selectors; + using COMET.Web.Common.Model.Configuration; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; using COMETwebapp.Components.SystemRepresentation; - using COMETwebapp.Model; using COMETwebapp.Utilities; using COMETwebapp.ViewModels.Components.SystemRepresentation; @@ -82,6 +83,9 @@ public void SetUp() this.context.ConfigureDevExpressBlazor(); this.context.Services.AddAntDesign(); this.context.Services.AddSingleton(); + var configuration = new Mock(); + configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + this.context.Services.AddSingleton(configuration.Object); this.assembler = new Assembler(this.uri); this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri); @@ -264,7 +268,7 @@ public void VerifyOnInitialized() { var renderer = this.context.RenderComponent(parameters => { - parameters.Add(p => p.CurrentIteration, this.iteration); + parameters.Add(p => p.CurrentThing, this.iteration); }); var option1 = new Option(Guid.NewGuid(), this.assembler.Cache, this.uri) @@ -283,25 +287,25 @@ public void VerifyOnInitialized() [Test] public async Task VerifySelectNode() { - var renderer = this.context.RenderComponent(parameters => + this.context.RenderComponent(parameters => { - parameters.Add(p => p.CurrentIteration, this.iteration); + parameters.Add(p => p.CurrentThing, this.iteration); }); await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading); this.viewModel.Elements.Clear(); - this.viewModel.Elements.Add(this.iteration.Element.First()); + this.viewModel.Elements.Add(this.iteration.Element[0]); - this.viewModel.SelectElement(new SystemNodeViewModel(this.viewModel.Elements.FirstOrDefault().Name)); + this.viewModel.SelectElement(new SystemNodeViewModel(this.viewModel.Elements.FirstOrDefault()!.Name)); Assert.Multiple(() => { Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.SelectedSystemNode, Is.Not.Null); Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.Count, Is.EqualTo(1)); - Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().ParameterTypeName, Is.EqualTo(this.iteration.Element.First().Parameter.First().ParameterType.Name)); - Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().ShortName, Is.EqualTo(this.iteration.Element.First().Parameter.First().ParameterType.ShortName)); - Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().Owner, Is.EqualTo(this.iteration.Element.First().Parameter.First().Owner.ShortName)); + Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().ParameterTypeName, Is.EqualTo(this.iteration.Element[0].Parameter[0].ParameterType.Name)); + Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().ShortName, Is.EqualTo(this.iteration.Element[0].Parameter[0].ParameterType.ShortName)); + Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().Owner, Is.EqualTo(this.iteration.Element[0].Parameter[0].Owner.ShortName)); Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().PublishedValue, Is.Not.Null); Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().ActualValue, Is.Not.Null); Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().SwitchValue, Is.Not.Null); diff --git a/COMETwebapp.Tests/Components/UserManagement/UserManagementTableTestFixture.cs b/COMETwebapp.Tests/Components/UserManagement/UserManagementTableTestFixture.cs index 4a224ea6..0fda6c18 100644 --- a/COMETwebapp.Tests/Components/UserManagement/UserManagementTableTestFixture.cs +++ b/COMETwebapp.Tests/Components/UserManagement/UserManagementTableTestFixture.cs @@ -38,6 +38,8 @@ namespace COMETwebapp.Tests.Components.UserManagement using CDP4Dal.Events; using CDP4Dal.Permission; + using COMET.Web.Common.Model.Configuration; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Test.Helpers; @@ -97,6 +99,9 @@ public void SetUp() this.context.Services.AddSingleton(this.sessionService); this.context.ConfigureDevExpressBlazor(); + var configuration = new Mock(); + configuration.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + this.context.Services.AddSingleton(configuration.Object); this.assembler = new Assembler(this.uri); this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri); diff --git a/COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs b/COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs index 8399d5a0..86f3a218 100644 --- a/COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs +++ b/COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs @@ -40,6 +40,7 @@ namespace COMETwebapp.Tests.Pages.ModelDashboard using COMET.Web.Common.Services.StringTableService; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMETwebapp.Pages.ModelDashboard; using COMETwebapp.ViewModels.Components.ModelDashboard; @@ -159,7 +160,7 @@ public async Task VerifyIterationSelection() Assert.Multiple(() => { - Assert.That(this.viewModel.SelectedIteration, Is.Not.Null); + Assert.That(this.viewModel.SelectedThing, Is.Not.Null); Assert.That(navigation.Uri.Contains("server"), Is.True); Assert.That(navigation.Uri.Contains(this.secondIteration.Iid.ToShortGuid()), Is.True); }); @@ -179,19 +180,19 @@ public void VerifyIterationPreselection() Assert.Multiple(() => { - Assert.That(this.viewModel.SelectedIteration, Is.EqualTo(this.firstIteration)); + Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); Assert.That(navigation.Uri.Contains("server"), Is.True); Assert.That(navigation.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); }); - this.viewModel.SelectedIteration = null; + this.viewModel.SelectedThing = null; this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.secondIteration.Iid.ToShortGuid()); }); - Assert.That(this.viewModel.SelectedIteration, Is.Null); + Assert.That(this.viewModel.SelectedThing, Is.Null); } } } diff --git a/COMETwebapp.Tests/Pages/ParameterEditor/ParameterEditorTestFixture.cs b/COMETwebapp.Tests/Pages/ParameterEditor/ParameterEditorTestFixture.cs index 3a5edbd5..3e8a81fa 100644 --- a/COMETwebapp.Tests/Pages/ParameterEditor/ParameterEditorTestFixture.cs +++ b/COMETwebapp.Tests/Pages/ParameterEditor/ParameterEditorTestFixture.cs @@ -41,6 +41,7 @@ namespace COMETwebapp.Tests.Pages.ParameterEditor using COMET.Web.Common.Services.StringTableService; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMETwebapp.Pages.ParameterEditor; using COMETwebapp.Services.SubscriptionService; @@ -168,7 +169,7 @@ public async Task VerifyIterationSelection() Assert.Multiple(() => { - Assert.That(this.viewModel.SelectedIteration, Is.Not.Null); + Assert.That(this.viewModel.SelectedThing, Is.Not.Null); Assert.That(navigation.Uri.Contains("server"), Is.True); Assert.That(navigation.Uri.Contains(this.secondIteration.Iid.ToShortGuid()), Is.True); }); @@ -188,19 +189,19 @@ public void VerifyIterationPreselection() Assert.Multiple(() => { - Assert.That(this.viewModel.SelectedIteration, Is.EqualTo(this.firstIteration)); + Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); Assert.That(navigation.Uri.Contains("server"), Is.True); Assert.That(navigation.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); }); - this.viewModel.SelectedIteration = null; + this.viewModel.SelectedThing = null; this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.secondIteration.Iid.ToShortGuid()); }); - Assert.That(this.viewModel.SelectedIteration, Is.Null); + Assert.That(this.viewModel.SelectedThing, Is.Null); } } } diff --git a/COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs b/COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs index 8f6cbc53..bea12ed9 100644 --- a/COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs +++ b/COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs @@ -40,7 +40,9 @@ namespace COMETwebapp.Tests.Pages.Viewer using COMET.Web.Common.Services.StringTableService; using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; + using COMETwebapp.Pages.Viewer; using COMETwebapp.Services.Interoperability; using COMETwebapp.Services.SubscriptionService; @@ -83,16 +85,16 @@ public void Setup() this.session = new Mock(); this.session.Setup(x => x.DataSourceUri).Returns("http://localhost:5000"); this.sessionService.Setup(x => x.Session).Returns(this.session.Object); - this.sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny())).Returns(new DomainOfExpertise() { Iid = Guid.NewGuid() }); + this.sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny())).Returns(new DomainOfExpertise { Iid = Guid.NewGuid() }); - this.firstIteration = new Iteration() + this.firstIteration = new Iteration { Iid = Guid.NewGuid(), - IterationSetup = new IterationSetup() + IterationSetup = new IterationSetup { Iid = Guid.NewGuid(), IterationNumber = 1, - Container = new EngineeringModelSetup() + Container = new EngineeringModelSetup { Iid = Guid.NewGuid(), Name = "EnVision" @@ -100,21 +102,21 @@ public void Setup() } }; - this.secondIteration = new Iteration() + this.secondIteration = new Iteration { Iid = Guid.NewGuid(), - IterationSetup = new IterationSetup() + IterationSetup = new IterationSetup { Iid = Guid.NewGuid(), IterationNumber = 4, - Container = new EngineeringModelSetup() + Container = new EngineeringModelSetup { Iid = Guid.NewGuid(), Name = "Loft" } } }; - + var mockConfigurationService = new Mock(); mockConfigurationService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); @@ -141,10 +143,26 @@ public void Teardown() } [Test] - public void VerifyOpenModelPresent() + public void VerifyIterationPreselection() { - var renderer = this.context.RenderComponent(); - Assert.That(() => renderer.FindComponent(), Throws.Nothing); + this.openedIterations.AddRange(new List { this.firstIteration }); + + this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.firstIteration.Iid.ToShortGuid()); }); + + var navigation = this.context.Services.GetService(); + + Assert.Multiple(() => + { + Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); + Assert.That(navigation.Uri.Contains("server"), Is.True); + Assert.That(navigation.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); + }); + + this.viewModel.SelectedThing = null; + + this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.secondIteration.Iid.ToShortGuid()); }); + + Assert.That(this.viewModel.SelectedThing, Is.Null); } [Test] @@ -163,39 +181,17 @@ public async Task VerifyIterationSelection() Assert.Multiple(() => { - Assert.That(this.viewModel.SelectedIteration, Is.Not.Null); + Assert.That(this.viewModel.SelectedThing, Is.Not.Null); Assert.That(navigation.Uri.Contains("server"), Is.True); Assert.That(navigation.Uri.Contains(this.secondIteration.Iid.ToShortGuid()), Is.True); }); } [Test] - public void VerifyIterationPreselection() + public void VerifyOpenModelPresent() { - this.openedIterations.AddRange(new List { this.firstIteration }); - - this.context.RenderComponent(parameters => - { - parameters.Add(p => p.IterationId, this.firstIteration.Iid.ToShortGuid()); - }); - - var navigation = this.context.Services.GetService(); - - Assert.Multiple(() => - { - Assert.That(this.viewModel.SelectedIteration, Is.EqualTo(this.firstIteration)); - Assert.That(navigation.Uri.Contains("server"), Is.True); - Assert.That(navigation.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); - }); - - this.viewModel.SelectedIteration = null; - - this.context.RenderComponent(parameters => - { - parameters.Add(p => p.IterationId, this.secondIteration.Iid.ToShortGuid()); - }); - - Assert.That(this.viewModel.SelectedIteration, Is.Null); + var renderer = this.context.RenderComponent(); + Assert.That(() => renderer.FindComponent(), Throws.Nothing); } } } diff --git a/COMETwebapp.Tests/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModelTestFixture.cs b/COMETwebapp.Tests/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModelTestFixture.cs index feb06030..760d51f0 100644 --- a/COMETwebapp.Tests/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModelTestFixture.cs +++ b/COMETwebapp.Tests/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModelTestFixture.cs @@ -22,11 +22,12 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace COMETwebapp.Tests.ViewModels.Components.ModelEdior +namespace COMETwebapp.Tests.ViewModels.Components.ModelEditor { using CDP4Common.EngineeringModelData; - using CDP4Common.SiteDirectoryData; - using CDP4Dal; + using CDP4Common.SiteDirectoryData; + + using CDP4Dal; using CDP4Dal.Events; using COMET.Web.Common.Services.SessionManagement; @@ -94,13 +95,14 @@ public void Setup() this.sessionService.Setup(x => x.OpenIterations).Returns(iterations); this.viewModel = new ElementDefinitionTableViewModel(this.sessionService.Object); - this.viewModel.CurrentIteration = this.iteration; + this.viewModel.CurrentThing = this.iteration; } [TearDown] public void TearDown() { this.viewModel.Dispose(); + CDPMessageBus.Current.ClearSubscriptions(); } [Test] @@ -160,7 +162,7 @@ public async Task VerifyAddingElementDefinition() Owner = this.domain }; - this.viewModel.ElementDefinitionCreationViewModel.SelectedCategories = new List { new Category { Name = "C" } }; + this.viewModel.ElementDefinitionCreationViewModel.SelectedCategories = new List { new() { Name = "C" } }; this.viewModel.ElementDefinitionCreationViewModel.IsTopElement = true; this.viewModel.ElementDefinitionCreationViewModel.ElementDefinition.Category = this.viewModel.ElementDefinitionCreationViewModel.SelectedCategories.ToList(); diff --git a/COMETwebapp.Tests/ViewModels/Components/ParameterEditor/ParameterEditorBodyViewModelTestFixture.cs b/COMETwebapp.Tests/ViewModels/Components/ParameterEditor/ParameterEditorBodyViewModelTestFixture.cs index 81d0aa89..ce7c4d2a 100644 --- a/COMETwebapp.Tests/ViewModels/Components/ParameterEditor/ParameterEditorBodyViewModelTestFixture.cs +++ b/COMETwebapp.Tests/ViewModels/Components/ParameterEditor/ParameterEditorBodyViewModelTestFixture.cs @@ -220,7 +220,7 @@ public void SetUp() this.tableViewModel = new Mock(); this.viewModel = new ParameterEditorBodyViewModel(sessionService.Object, subscriptionService.Object, this.tableViewModel.Object); - this.viewModel.CurrentIteration = this.iteration; + this.viewModel.CurrentThing = this.iteration; } [TearDown] @@ -265,7 +265,7 @@ public async Task VerifyApplyFilters() this.viewModel.ParameterTypeSelector.SelectedParameterType = null; await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading); - this.viewModel.OptionSelector.SelectedOption = this.viewModel.CurrentIteration.Option.Last(); + this.viewModel.OptionSelector.SelectedOption = this.viewModel.CurrentThing.Option.Last(); await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading); this.tableViewModel.Verify(x => x.ApplyFilters(this.iteration.Option.Last(), diff --git a/COMETwebapp.Tests/ViewModels/Components/SubscriptionDashboard/SubscriptionDashboardBodyViewModelTestFixture.cs b/COMETwebapp.Tests/ViewModels/Components/SubscriptionDashboard/SubscriptionDashboardBodyViewModelTestFixture.cs index 6e85c58b..2674a7dd 100644 --- a/COMETwebapp.Tests/ViewModels/Components/SubscriptionDashboard/SubscriptionDashboardBodyViewModelTestFixture.cs +++ b/COMETwebapp.Tests/ViewModels/Components/SubscriptionDashboard/SubscriptionDashboardBodyViewModelTestFixture.cs @@ -58,13 +58,13 @@ public void Setup() [Test] public void VerifyOnIterationChanged() { - Assert.That(() => this.viewModel.CurrentIteration = null,Throws.Nothing); + Assert.That(() => this.viewModel.CurrentThing = null,Throws.Nothing); var domain = new DomainOfExpertise(); this.sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny())).Returns(domain); - this.viewModel.CurrentIteration = new Iteration(); + this.viewModel.CurrentThing = new Iteration(); this.subscribedTableViewModel.Verify(x => x.UpdateProperties(It.IsAny>(), - this.viewModel.CurrentIteration.Option, this.viewModel.CurrentIteration), Times.Once); + this.viewModel.CurrentThing.Option, this.viewModel.CurrentThing), Times.Once); } [Test] diff --git a/COMETwebapp.Tests/ViewModels/Pages/Viewer/ViewerBodyViewModelTestFixture.cs b/COMETwebapp.Tests/ViewModels/Pages/Viewer/ViewerBodyViewModelTestFixture.cs index 147b673e..d614153f 100644 --- a/COMETwebapp.Tests/ViewModels/Pages/Viewer/ViewerBodyViewModelTestFixture.cs +++ b/COMETwebapp.Tests/ViewModels/Pages/Viewer/ViewerBodyViewModelTestFixture.cs @@ -170,7 +170,7 @@ public void SetUp() var babylonInterop = new Mock(); this.viewModel = new ViewerBodyViewModel(sessionServiceMock.Object, selectionMediatorMock.Object, babylonInterop.Object); - this.viewModel.CurrentIteration = iteration; + this.viewModel.CurrentThing = iteration; } [TearDown] diff --git a/COMETwebapp.sln.DotSettings b/COMETwebapp.sln.DotSettings index fad6fc78..10dc2de5 100644 --- a/COMETwebapp.sln.DotSettings +++ b/COMETwebapp.sln.DotSettings @@ -130,6 +130,7 @@ <HasAttribute Name="NUnit.Framework.TestFixtureAttribute" Inherited="True" /> </And> </TypePattern.Match> + <Entry DisplayName="All other members" /> <Entry DisplayName="Setup/Teardown Methods"> <Entry.Match> <And> @@ -143,7 +144,6 @@ </And> </Entry.Match> </Entry> - <Entry DisplayName="All other members" /> <Entry DisplayName="Test Methods" Priority="100"> <Entry.Match> <And> diff --git a/COMETwebapp/COMETwebapp.csproj b/COMETwebapp/COMETwebapp.csproj index 5c09b3c2..bddc29e2 100644 --- a/COMETwebapp/COMETwebapp.csproj +++ b/COMETwebapp/COMETwebapp.csproj @@ -1,4 +1,4 @@ - + net7.0 diff --git a/COMETwebapp/Components/BookEditor/BookEditorBody.razor b/COMETwebapp/Components/BookEditor/BookEditorBody.razor index fe8404a3..f6efed4f 100644 --- a/COMETwebapp/Components/BookEditor/BookEditorBody.razor +++ b/COMETwebapp/Components/BookEditor/BookEditorBody.razor @@ -23,7 +23,7 @@ @using COMETwebapp.Extensions @using COMET.Web.Common.Components.BookEditor @using CDP4Common.ReportingData -@inherits SingleIterationApplicationBase +@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase diff --git a/COMETwebapp/Components/ModelDashboard/ModelDashboardBody.razor b/COMETwebapp/Components/ModelDashboard/ModelDashboardBody.razor index 108ec813..df2b6ed3 100644 --- a/COMETwebapp/Components/ModelDashboard/ModelDashboardBody.razor +++ b/COMETwebapp/Components/ModelDashboard/ModelDashboardBody.razor @@ -21,7 +21,7 @@ -------------------------------------------------------------------------------> @using COMETwebapp.Utilities @using COMETwebapp.Extensions -@inherits SingleIterationApplicationBase +@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase
diff --git a/COMETwebapp/Components/ModelEditor/ElementDefinitionTable.razor b/COMETwebapp/Components/ModelEditor/ElementDefinitionTable.razor index 640bb9bb..b35597f5 100644 --- a/COMETwebapp/Components/ModelEditor/ElementDefinitionTable.razor +++ b/COMETwebapp/Components/ModelEditor/ElementDefinitionTable.razor @@ -23,7 +23,7 @@ @using CDP4Common.SiteDirectoryData @using COMETwebapp.ViewModels.Components.ParameterEditor @using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; -@inherits SingleIterationApplicationBase; +@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase; diff --git a/COMETwebapp/Components/ParameterEditor/ParameterEditorBody.razor b/COMETwebapp/Components/ParameterEditor/ParameterEditorBody.razor index 4361fdbf..be7ee247 100644 --- a/COMETwebapp/Components/ParameterEditor/ParameterEditorBody.razor +++ b/COMETwebapp/Components/ParameterEditor/ParameterEditorBody.razor @@ -21,7 +21,7 @@ -------------------------------------------------------------------------------> @using COMETwebapp.Utilities @using COMETwebapp.Extensions -@inherits SingleIterationApplicationBase +@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase
diff --git a/COMETwebapp/Components/SubscriptionDashboard/SubscriptionDashboardBody.razor b/COMETwebapp/Components/SubscriptionDashboard/SubscriptionDashboardBody.razor index 94427ef7..e435df2d 100644 --- a/COMETwebapp/Components/SubscriptionDashboard/SubscriptionDashboardBody.razor +++ b/COMETwebapp/Components/SubscriptionDashboard/SubscriptionDashboardBody.razor @@ -21,7 +21,7 @@ -------------------------------------------------------------------------------> @using COMETwebapp.Utilities @using COMETwebapp.Extensions -@inherits SingleIterationApplicationBase +@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase
diff --git a/COMETwebapp/Components/SystemRepresentation/SystemRepresentationBody.razor b/COMETwebapp/Components/SystemRepresentation/SystemRepresentationBody.razor index 11b32899..bffd811d 100644 --- a/COMETwebapp/Components/SystemRepresentation/SystemRepresentationBody.razor +++ b/COMETwebapp/Components/SystemRepresentation/SystemRepresentationBody.razor @@ -19,7 +19,7 @@ // 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 SingleIterationApplicationBase +@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase
diff --git a/COMETwebapp/Components/UserManagement/UserManagementTable.razor b/COMETwebapp/Components/UserManagement/UserManagementTable.razor index 9a44dce9..7c21d770 100644 --- a/COMETwebapp/Components/UserManagement/UserManagementTable.razor +++ b/COMETwebapp/Components/UserManagement/UserManagementTable.razor @@ -22,7 +22,7 @@ @using COMETwebapp.ViewModels.Components.UserManagement.Rows @using CDP4Common.SiteDirectoryData @using COMETwebapp.ViewModels.Components.UserManagement; -@inherits SingleIterationApplicationBase; +@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase; @using COMETwebapp.Utilities @using COMETwebapp.Extensions -@inherits SingleIterationApplicationBase +@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase
diff --git a/COMETwebapp/ViewModels/Components/BookEditor/BookEditorBodyViewModel.cs b/COMETwebapp/ViewModels/Components/BookEditor/BookEditorBodyViewModel.cs index 54fb0ddc..421fd7bd 100644 --- a/COMETwebapp/ViewModels/Components/BookEditor/BookEditorBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/BookEditor/BookEditorBodyViewModel.cs @@ -33,6 +33,7 @@ namespace COMETwebapp.ViewModels.Components.BookEditor using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.BookEditor; using DynamicData; @@ -198,19 +199,19 @@ private void OnSelectedPageChanged() /// A protected override Task OnSessionRefreshed() { - return this.OnIterationChanged(); + return this.OnThingChanged(); } /// /// Update this view model properties when the has changed /// /// A - protected override async Task OnIterationChanged() + protected override async Task OnThingChanged() { this.IsLoading = true; - await base.OnIterationChanged(); + await base.OnThingChanged(); - if (this.CurrentIteration.Container is EngineeringModel engineeringModel) + if (this.CurrentThing.Container is EngineeringModel engineeringModel) { this.AvailableBooks.Edit(inner => { @@ -297,7 +298,7 @@ public async Task OnCreateThing() switch (this.ThingToCreate) { case Book: - thingContainer = this.CurrentIteration.Container; + thingContainer = this.CurrentThing.Container; break; case Section: thingContainer = this.SelectedBook; diff --git a/COMETwebapp/ViewModels/Components/BookEditor/IBookEditorBodyViewModel.cs b/COMETwebapp/ViewModels/Components/BookEditor/IBookEditorBodyViewModel.cs index 3cca665e..c5ae7836 100644 --- a/COMETwebapp/ViewModels/Components/BookEditor/IBookEditorBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/BookEditor/IBookEditorBodyViewModel.cs @@ -28,8 +28,9 @@ namespace COMETwebapp.ViewModels.Components.BookEditor using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; using CDP4Common.SiteDirectoryData; - + using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.BookEditor; using DynamicData; diff --git a/COMETwebapp/ViewModels/Components/ModelDashboard/IModelDashboardBodyViewModel.cs b/COMETwebapp/ViewModels/Components/ModelDashboard/IModelDashboardBodyViewModel.cs index 01293b17..370d58ad 100644 --- a/COMETwebapp/ViewModels/Components/ModelDashboard/IModelDashboardBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ModelDashboard/IModelDashboardBodyViewModel.cs @@ -24,7 +24,7 @@ namespace COMETwebapp.ViewModels.Components.ModelDashboard { - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMETwebapp.ViewModels.Components.ModelDashboard.Elements; diff --git a/COMETwebapp/ViewModels/Components/ModelDashboard/ModelDashboardBodyViewModel.cs b/COMETwebapp/ViewModels/Components/ModelDashboard/ModelDashboardBodyViewModel.cs index 0a812061..9ad9f07d 100644 --- a/COMETwebapp/ViewModels/Components/ModelDashboard/ModelDashboardBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ModelDashboard/ModelDashboardBodyViewModel.cs @@ -30,7 +30,7 @@ namespace COMETwebapp.ViewModels.Components.ModelDashboard using COMET.Web.Common.Extensions; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMETwebapp.ViewModels.Components.ModelDashboard.Elements; @@ -94,7 +94,7 @@ public ModelDashboardBodyViewModel(ISessionService sessionService, IParameterDas /// A protected override Task OnSessionRefreshed() { - return this.OnIterationChanged(); + return this.OnThingChanged(); } /// @@ -111,18 +111,18 @@ protected override async Task OnDomainChanged() /// Update this view model properties /// /// A - protected override async Task OnIterationChanged() + protected override async Task OnThingChanged() { - await base.OnIterationChanged(); - this.OptionSelector.CurrentIteration = this.CurrentIteration; - this.FiniteStateSelector.CurrentIteration = this.CurrentIteration; - this.ParameterTypeSelector.CurrentIteration = this.CurrentIteration; + await base.OnThingChanged(); + this.OptionSelector.CurrentIteration = this.CurrentThing; + this.FiniteStateSelector.CurrentIteration = this.CurrentThing; + this.ParameterTypeSelector.CurrentIteration = this.CurrentThing; - this.AvailableDomains = this.CurrentIteration == null + this.AvailableDomains = this.CurrentThing == null ? Enumerable.Empty() - : this.SessionService.GetModelDomains((EngineeringModelSetup)this.CurrentIteration.IterationSetup.Container); + : this.SessionService.GetModelDomains((EngineeringModelSetup)this.CurrentThing.IterationSetup.Container); - this.CurrentDomain = this.CurrentIteration == null ? null : this.SessionService.GetDomainOfExpertise(this.CurrentIteration); + this.CurrentDomain = this.CurrentThing == null ? null : this.SessionService.GetDomainOfExpertise(this.CurrentThing); await this.UpdateDashboards(); } @@ -135,11 +135,11 @@ private async Task UpdateDashboards() this.IsLoading = true; await Task.Delay(1); - this.ParameterDashboard.UpdateProperties(this.CurrentIteration, this.OptionSelector.SelectedOption, + this.ParameterDashboard.UpdateProperties(this.CurrentThing, this.OptionSelector.SelectedOption, this.FiniteStateSelector.SelectedActualFiniteState, this.ParameterTypeSelector.SelectedParameterType, this.CurrentDomain, this.AvailableDomains); - this.ElementDashboard.UpdateProperties(this.CurrentIteration, this.CurrentDomain); + this.ElementDashboard.UpdateProperties(this.CurrentThing, this.CurrentDomain); this.IsLoading = false; } } diff --git a/COMETwebapp/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModel.cs b/COMETwebapp/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModel.cs index 3559bb6d..a999f546 100644 --- a/COMETwebapp/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ModelEditor/ElementDefinitionTableViewModel.cs @@ -25,76 +25,81 @@ namespace COMETwebapp.ViewModels.Components.ModelEditor { using System.Collections.ObjectModel; - using System.Reactive.Linq; - using CDP4Common.CommonData; - using CDP4Common.EngineeringModelData; - using CDP4Common.SiteDirectoryData; - using CDP4Dal; + + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.SiteDirectoryData; + + using CDP4Dal; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMETwebapp.Components.ModelEditor; - using COMETwebapp.ViewModels.Components.SystemRepresentation; - using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; - using DevExpress.Blazor; - using DynamicData; - using Microsoft.AspNetCore.Components; - using ReactiveUI; - - /// - /// ViewModel for the - /// + using COMETwebapp.ViewModels.Components.SystemRepresentation; + using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; + + using DevExpress.Blazor; + + using DynamicData; + + using Microsoft.AspNetCore.Components; + + using ReactiveUI; + + /// + /// ViewModel for the + /// public class ElementDefinitionTableViewModel : SingleIterationApplicationBaseViewModel, IElementDefinitionTableViewModel { /// - /// All of the iteration + /// The current /// - public List Elements { get; set; } = new(); + private readonly Iteration iteration; /// - /// The current + /// The /// - private readonly Iteration iteration; + private readonly ISessionService sessionService; - /// - /// The - /// - private readonly ISessionService sessionService; - - /// - /// Backing field for - /// - private bool isOnCreationMode; - - /// - /// The - /// - public IElementDefinitionDetailsViewModel ElementDefinitionDetailsViewModel { get; } = new ElementDefinitionDetailsViewModel(); - - /// - /// Gets the - /// - public IElementDefinitionCreationViewModel ElementDefinitionCreationViewModel { get; set; } - - /// - /// Creates a new instance of - /// - /// the - public ElementDefinitionTableViewModel(ISessionService sessionService) : base(sessionService) + /// + /// Backing field for + /// + private bool isOnCreationMode; + + /// + /// Creates a new instance of + /// + /// the + public ElementDefinitionTableViewModel(ISessionService sessionService) : base(sessionService) { this.iteration = sessionService?.OpenIterations.Items.FirstOrDefault(); - this.sessionService = sessionService; + this.sessionService = sessionService; this.InitializeElements(); - this.ElementDefinitionCreationViewModel = new ElementDefinitionCreationViewModel(sessionService) - { - OnValidSubmit = new EventCallbackFactory().Create(this, this.AddingElementDefinition) - }; + this.ElementDefinitionCreationViewModel = new ElementDefinitionCreationViewModel(sessionService) + { + OnValidSubmit = new EventCallbackFactory().Create(this, this.AddingElementDefinition) + }; - this.InitializeSubscriptions(new List { typeof(ElementBase) }); + this.InitializeSubscriptions(new List { typeof(ElementBase) }); } + /// + /// All of the iteration + /// + public List Elements { get; set; } = new(); + + /// + /// The + /// + public IElementDefinitionDetailsViewModel ElementDefinitionDetailsViewModel { get; } = new ElementDefinitionDetailsViewModel(); + + /// + /// Gets the + /// + public IElementDefinitionCreationViewModel ElementDefinitionCreationViewModel { get; set; } + /// /// Gets the collection of the for target model /// @@ -105,74 +110,67 @@ public ElementDefinitionTableViewModel(ISessionService sessionService) : base(se ///
public ObservableCollection RowsSource { get; } = new(); - /// - /// Value indicating the user is currently creating a new - /// - public bool IsOnCreationMode - { - get => this.isOnCreationMode; - set => this.RaiseAndSetIfChanged(ref this.isOnCreationMode, value); - } - - /// - /// Represents the selected ElementDefinitionRowViewModel - /// - public object SelectedElementDefinition { get; set; } - - /// - /// Initialize list - /// - private void InitializeElements() + /// + /// Value indicating the user is currently creating a new + /// + public bool IsOnCreationMode { - if (this.iteration != null) - { - this.iteration.Element.ForEach(e => - { - this.Elements.Add(e); - this.Elements.AddRange(e.ContainedElement); - }); - this.Elements.ForEach(e => this.RowsTarget.Add(new ElementDefinitionRowViewModel(e))); - this.Elements.ForEach(e => this.RowsSource.Add(new ElementDefinitionRowViewModel(e))); - } + get => this.isOnCreationMode; + set => this.RaiseAndSetIfChanged(ref this.isOnCreationMode, value); } /// - /// Handles the refresh of the current + /// Represents the selected ElementDefinitionRowViewModel /// + public object SelectedElementDefinition { get; set; } + + /// + /// set the selected + /// + /// The selected /// A - protected override async Task OnSessionRefreshed() + public void SelectElement(GridRowClickEventArgs args) { - if (!this.AddedThings.Any() && !this.DeletedThings.Any() && !this.UpdatedThings.Any()) - { - return; - } + var selectedNode = (ElementDefinitionRowViewModel)args.Grid.GetDataItem(args.VisibleIndex); - this.IsLoading = true; - await Task.Delay(1); + // It is preferable to have a selection based on the Iid of the Thing + this.ElementDefinitionDetailsViewModel.SelectedSystemNode = selectedNode.ElementBase; - this.RemoveRows(this.DeletedThings.OfType()); - this.RowsSource.AddRange(this.AddedThings.OfType().Select(e => new ElementDefinitionRowViewModel(e))); - this.RowsTarget.AddRange(this.AddedThings.OfType().Select(e => new ElementDefinitionRowViewModel(e))); - this.UpdateRows(this.UpdatedThings.OfType()); + this.ElementDefinitionDetailsViewModel.Rows = this.ElementDefinitionDetailsViewModel.SelectedSystemNode switch + { + ElementDefinition elementDefinition => elementDefinition.Parameter.Select(x => new ElementDefinitionDetailsRowViewModel(x)).ToList(), + ElementUsage elementUsage => elementUsage.ElementDefinition.Parameter.Select(x => new ElementDefinitionDetailsRowViewModel(x)).ToList(), + _ => null + }; + } - this.ClearRecordedChanges(); - this.IsLoading = false; + /// + /// Opens the popup + /// + public void OpenCreateElementDefinitionCreationPopup() + { + this.ElementDefinitionCreationViewModel.ElementDefinition = new ElementDefinition(); + this.ElementDefinitionCreationViewModel.SelectedCategories = new List(); + this.IsOnCreationMode = true; } - /// + /// /// Updates rows related to that have been updated /// /// A collection of updated public void UpdateRows(IEnumerable updatedThings) { - foreach (ElementBase element in updatedThings) + foreach (var element in updatedThings) { var row = this.RowsSource.FirstOrDefault(x => x.ElementBase.Iid == element.Iid); + if (row != null) { row.UpdateProperties(new ElementDefinitionRowViewModel(element)); } + row = this.RowsTarget.FirstOrDefault(x => x.ElementBase.Iid == element.Iid); + if (row != null) { row.UpdateProperties(new ElementDefinitionRowViewModel(element)); @@ -186,14 +184,17 @@ public void UpdateRows(IEnumerable updatedThings) /// A collection of deleted public void RemoveRows(IEnumerable deletedThings) { - foreach (ElementBase element in deletedThings) + foreach (var element in deletedThings) { var row = this.RowsSource.FirstOrDefault(x => x.ElementBase.Iid == element.Iid); + if (row != null) { this.RowsSource.Remove(row); } + row = this.RowsTarget.FirstOrDefault(x => x.ElementBase.Iid == element.Iid); + if (row != null) { this.RowsTarget.Remove(row); @@ -201,78 +202,91 @@ public void RemoveRows(IEnumerable deletedThings) } } - /// - /// set the selected - /// - /// The selected - /// A - public void SelectElement(GridRowClickEventArgs args) - { - var selectedNode = (ElementDefinitionRowViewModel) args.Grid.GetDataItem(args.VisibleIndex); - // It is preferable to have a selection based on the Iid of the Thing - this.ElementDefinitionDetailsViewModel.SelectedSystemNode = selectedNode.ElementBase; + /// + /// Tries to create a new + /// + /// A + public async Task AddingElementDefinition() + { + var thingsToCreate = new List(); + + if (this.ElementDefinitionCreationViewModel.SelectedCategories.Any()) + { + this.ElementDefinitionCreationViewModel.ElementDefinition.Category = this.ElementDefinitionCreationViewModel.SelectedCategories.ToList(); + } + + this.ElementDefinitionCreationViewModel.ElementDefinition.Container = this.iteration; + thingsToCreate.Add(this.ElementDefinitionCreationViewModel.ElementDefinition); + var clonedIteration = this.iteration.Clone(false); + + if (this.ElementDefinitionCreationViewModel.IsTopElement) + { + clonedIteration.TopElement = this.ElementDefinitionCreationViewModel.ElementDefinition; + } + + clonedIteration.Element.Add(this.ElementDefinitionCreationViewModel.ElementDefinition); - this.ElementDefinitionDetailsViewModel.Rows = this.ElementDefinitionDetailsViewModel.SelectedSystemNode switch - { - ElementDefinition elementDefinition => elementDefinition.Parameter.Select(x => new ElementDefinitionDetailsRowViewModel(x)).ToList(), - ElementUsage elementUsage => elementUsage.ElementDefinition.Parameter.Select(x => new ElementDefinitionDetailsRowViewModel(x)).ToList(), - _ => null - }; - } - - /// - /// Opens the popup - /// - public void OpenCreateElementDefinitionCreationPopup() - { - this.ElementDefinitionCreationViewModel.ElementDefinition = new ElementDefinition(); - this.ElementDefinitionCreationViewModel.SelectedCategories = new List(); - this.IsOnCreationMode = true; - } - - /// - /// Tries to create a new - /// - /// A - public async Task AddingElementDefinition() - { - var thingsToCreate = new List(); - - if (this.ElementDefinitionCreationViewModel.SelectedCategories.Any()) - { - this.ElementDefinitionCreationViewModel.ElementDefinition.Category = this.ElementDefinitionCreationViewModel.SelectedCategories.ToList(); - } - - this.ElementDefinitionCreationViewModel.ElementDefinition.Container = this.iteration; - thingsToCreate.Add(this.ElementDefinitionCreationViewModel.ElementDefinition); - var clonedIteration = this.iteration.Clone(false); - - if (this.ElementDefinitionCreationViewModel.IsTopElement) - { - clonedIteration.TopElement = this.ElementDefinitionCreationViewModel.ElementDefinition; - } - - clonedIteration.Element.Add(this.ElementDefinitionCreationViewModel.ElementDefinition); - try - { - await this.sessionService.CreateThings(clonedIteration, thingsToCreate); - this.IsOnCreationMode = false; - } - catch (Exception exception) - { - Console.WriteLine(exception.Message); - throw; - } - } - - /// - /// Update this view model properties - /// - /// A - protected override async Task OnIterationChanged() + try + { + await this.sessionService.CreateThings(clonedIteration, thingsToCreate); + this.IsOnCreationMode = false; + } + catch (Exception exception) + { + Console.WriteLine(exception.Message); + throw; + } + } + + /// + /// Handles the refresh of the current + /// + /// A + protected override async Task OnSessionRefreshed() { - await base.OnIterationChanged(); + if (!this.AddedThings.Any() && !this.DeletedThings.Any() && !this.UpdatedThings.Any()) + { + return; + } + + this.IsLoading = true; + await Task.Delay(1); + + this.RemoveRows(this.DeletedThings.OfType()); + this.RowsSource.AddRange(this.AddedThings.OfType().Select(e => new ElementDefinitionRowViewModel(e))); + this.RowsTarget.AddRange(this.AddedThings.OfType().Select(e => new ElementDefinitionRowViewModel(e))); + this.UpdateRows(this.UpdatedThings.OfType()); + + this.ClearRecordedChanges(); + this.IsLoading = false; + } + + /// + /// Update this view model properties + /// + /// A + protected override async Task OnThingChanged() + { + await base.OnThingChanged(); this.IsLoading = false; } + + /// + /// Initialize list + /// + private void InitializeElements() + { + if (this.iteration != null) + { + this.iteration.Element.ForEach(e => + { + this.Elements.Add(e); + this.Elements.AddRange(e.ContainedElement); + }); + + this.Elements.ForEach(e => this.RowsTarget.Add(new ElementDefinitionRowViewModel(e))); + this.Elements.ForEach(e => this.RowsSource.Add(new ElementDefinitionRowViewModel(e))); + } + } } } diff --git a/COMETwebapp/ViewModels/Components/ModelEditor/IElementDefinitionTableViewModel.cs b/COMETwebapp/ViewModels/Components/ModelEditor/IElementDefinitionTableViewModel.cs index df217be3..928244c0 100644 --- a/COMETwebapp/ViewModels/Components/ModelEditor/IElementDefinitionTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ModelEditor/IElementDefinitionTableViewModel.cs @@ -24,15 +24,15 @@ namespace COMETwebapp.ViewModels.Components.ModelEditor { - using COMET.Web.Common.ViewModels.Components; - using COMETwebapp.ViewModels.Components.SystemRepresentation; - using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; - using DevExpress.Blazor; - using System.Collections.ObjectModel; + using COMET.Web.Common.ViewModels.Components.Applications; + using COMETwebapp.ViewModels.Components.SystemRepresentation; + using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; + using DevExpress.Blazor; + using System.Collections.ObjectModel; - /// - /// Interface for the - /// + /// + /// Interface for the + /// public interface IElementDefinitionTableViewModel : ISingleIterationApplicationBaseViewModel { /// diff --git a/COMETwebapp/ViewModels/Components/ParameterEditor/IParameterEditorBodyViewModel.cs b/COMETwebapp/ViewModels/Components/ParameterEditor/IParameterEditorBodyViewModel.cs index 8434e7a1..3f8f1104 100644 --- a/COMETwebapp/ViewModels/Components/ParameterEditor/IParameterEditorBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ParameterEditor/IParameterEditorBodyViewModel.cs @@ -24,7 +24,7 @@ namespace COMETwebapp.ViewModels.Components.ParameterEditor { - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMETwebapp.Services.SubscriptionService; diff --git a/COMETwebapp/ViewModels/Components/ParameterEditor/ParameterEditorBodyViewModel.cs b/COMETwebapp/ViewModels/Components/ParameterEditor/ParameterEditorBodyViewModel.cs index ee2fe423..b7b1c7fc 100644 --- a/COMETwebapp/ViewModels/Components/ParameterEditor/ParameterEditorBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ParameterEditor/ParameterEditorBodyViewModel.cs @@ -1,4 +1,4 @@ -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2023 RHEA System S.A. // @@ -32,7 +32,7 @@ namespace COMETwebapp.ViewModels.Components.ParameterEditor using COMET.Web.Common.Extensions; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMETwebapp.Services.SubscriptionService; @@ -160,13 +160,13 @@ protected override async Task OnDomainChanged() /// Update this view model properties /// /// A - protected override async Task OnIterationChanged() + protected override async Task OnThingChanged() { - await base.OnIterationChanged(); + await base.OnThingChanged(); this.IsOwnedParameters = true; - this.ElementSelector.CurrentIteration = this.CurrentIteration; - this.OptionSelector.CurrentIteration = this.CurrentIteration; - this.ParameterTypeSelector.CurrentIteration = this.CurrentIteration; + this.ElementSelector.CurrentIteration = this.CurrentThing; + this.OptionSelector.CurrentIteration = this.CurrentThing; + this.ParameterTypeSelector.CurrentIteration = this.CurrentThing; await this.InitializeTable(); } @@ -178,7 +178,7 @@ private async Task InitializeTable() { this.IsLoading = true; await Task.Delay(1); - this.ParameterTableViewModel.InitializeViewModel(this.CurrentIteration, this.CurrentDomain, this.OptionSelector.SelectedOption); + this.ParameterTableViewModel.InitializeViewModel(this.CurrentThing, this.CurrentDomain, this.OptionSelector.SelectedOption); this.IsLoading = false; } @@ -188,7 +188,7 @@ private async Task InitializeTable() /// A private async Task ApplyFilters() { - if (this.CurrentIteration != null) + if (this.CurrentThing != null) { this.IsLoading = true; await Task.Delay(1); diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/CategoriesTableViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/CategoriesTableViewModel.cs index dfc83b1b..bd094c7e 100644 --- a/COMETwebapp/ViewModels/Components/ReferenceData/CategoriesTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ReferenceData/CategoriesTableViewModel.cs @@ -34,14 +34,12 @@ namespace COMETwebapp.ViewModels.Components.ReferenceData using CDP4Dal.Permission; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; - + using COMET.Web.Common.ViewModels.Components.Applications; + using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.ReferenceData.Rows; - using COMETwebapp.ViewModels.Components.SystemRepresentation; - using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; using COMETwebapp.Wrappers; - using DevExpress.Blazor; + using DynamicData; using ReactiveUI; @@ -171,18 +169,6 @@ public bool IsOnDeprecationMode /// public ReferenceDataLibrary SelectedReferenceDataLibrary { get; set; } - /// - /// Handles the refresh of the current - /// - /// A - protected override async Task OnSessionRefreshed() - { - this.IsLoading = true; - await Task.Delay(1); - this.IsLoading = false; - } - - /// /// Method invoked when canceling the deprecation/un-deprecation of a /// @@ -273,6 +259,20 @@ public async Task OnInitializedAsync() await this.RefreshAccessRight(); } + /// + /// set the selected + /// + /// The selected + public void SelectCategory(CategoryRowViewModel selectedCategory) + { + this.CategoryHierarchyDiagramViewModel.SelectedCategory = selectedCategory.Category; + + this.CategoryHierarchyDiagramViewModel.Rows = this.CategoryHierarchyDiagramViewModel.SelectedCategory.SuperCategory; + this.CategoryHierarchyDiagramViewModel.SubCategories = this.CategoryHierarchyDiagramViewModel.SelectedCategory.AllDerivedCategories(); + + this.CategoryHierarchyDiagramViewModel.SetupDiagram(); + } + /// /// Adds a new /// @@ -361,6 +361,17 @@ public async Task DeprecatingCategory() this.IsOnDeprecationMode = false; } + /// + /// Handles the refresh of the current + /// + /// A + protected override async Task OnSessionRefreshed() + { + this.IsLoading = true; + await Task.Delay(1); + this.IsLoading = false; + } + /// /// Refresh the displayed container name for the category rows /// @@ -371,6 +382,7 @@ private async Task RefreshContainerName(ReferenceDataLibrary rdl) { this.IsLoading = true; await Task.Delay(1); + foreach (var category in this.Rows.Items) { if (category.ContainerName != rdl.ShortName) @@ -378,6 +390,7 @@ private async Task RefreshContainerName(ReferenceDataLibrary rdl) category.ContainerName = rdl.ShortName; } } + this.IsLoading = false; } @@ -388,10 +401,12 @@ private async Task RefreshAccessRight() { this.IsLoading = true; await Task.Delay(1); + foreach (var row in this.Rows.Items) { row.IsAllowedToWrite = this.permissionService.CanWrite(ClassKind.Category, row.Category.Container); } + this.IsLoading = false; } @@ -416,19 +431,5 @@ private void UpdateRows(IEnumerable rowsToDisplay) this.Rows.Items.First(x => x.Category.Iid == existingRow.Category.Iid).UpdateProperties(existingRow); } } - - /// - /// set the selected - /// - /// The selected - public void SelectCategory(CategoryRowViewModel selectedCategory) - { - this.CategoryHierarchyDiagramViewModel.SelectedCategory = selectedCategory.Category; - - this.CategoryHierarchyDiagramViewModel.Rows = this.CategoryHierarchyDiagramViewModel.SelectedCategory.SuperCategory; - this.CategoryHierarchyDiagramViewModel.SubCategories = this.CategoryHierarchyDiagramViewModel.SelectedCategory.AllDerivedCategories(); - - this.CategoryHierarchyDiagramViewModel.SetupDiagram(); - } } } diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/ICategoriesTableViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/ICategoriesTableViewModel.cs index 7660452d..3e824f25 100644 --- a/COMETwebapp/ViewModels/Components/ReferenceData/ICategoriesTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ReferenceData/ICategoriesTableViewModel.cs @@ -26,9 +26,8 @@ namespace COMETwebapp.ViewModels.Components.ReferenceData { using CDP4Common.CommonData; using CDP4Common.SiteDirectoryData; - - using COMET.Web.Common.ViewModels.Components; - + using COMET.Web.Common.ViewModels.Components.Applications; + using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.ReferenceData.Rows; using COMETwebapp.Wrappers; diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/IParameterTypeTableViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/IParameterTypeTableViewModel.cs index 52819dc7..17ca861d 100644 --- a/COMETwebapp/ViewModels/Components/ReferenceData/IParameterTypeTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ReferenceData/IParameterTypeTableViewModel.cs @@ -21,24 +21,25 @@ // along with this program. If not, see . // // -------------------------------------------------------------------------------------------------------------------- + namespace COMETwebapp.ViewModels.Components.ReferenceData { using CDP4Common.SiteDirectoryData; - - using COMET.Web.Common.ViewModels.Components; - + + using COMET.Web.Common.ViewModels.Components.Applications; + using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.ReferenceData.Rows; - + using DynamicData; /// /// View model used to manage /// - public interface IParameterTypeTableViewModel: ISingleIterationApplicationBaseViewModel + public interface IParameterTypeTableViewModel : ISingleIterationApplicationBaseViewModel { /// - /// Gets or sets the data source for the grid control. + /// Gets or sets the data source for the grid control. /// SourceList DataSource { get; } @@ -53,10 +54,10 @@ public interface IParameterTypeTableViewModel: ISingleIterationApplicationBaseVi IShowHideDeprecatedThingsService ShowHideDeprecatedThingsService { get; } /// - /// Method invoked when the component is ready to start, having received its - /// initial parameters from its parent in the render tree. - /// Override this method if you will perform an asynchronous operation and - /// want the component to refresh when that operation is completed. + /// Method invoked when the component is ready to start, having received its + /// initial parameters from its parent in the render tree. + /// Override this method if you will perform an asynchronous operation and + /// want the component to refresh when that operation is completed. /// /// A representing any asynchronous operation. Task OnInitializedAsync(); diff --git a/COMETwebapp/ViewModels/Components/ReferenceData/ParameterTypeTableViewModel.cs b/COMETwebapp/ViewModels/Components/ReferenceData/ParameterTypeTableViewModel.cs index 52b02a6c..68107ea7 100644 --- a/COMETwebapp/ViewModels/Components/ReferenceData/ParameterTypeTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ReferenceData/ParameterTypeTableViewModel.cs @@ -33,12 +33,12 @@ namespace COMETwebapp.ViewModels.Components.ReferenceData using CDP4Dal.Events; using CDP4Dal.Permission; + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.ViewModels.Components.Applications; + using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.ReferenceData.Rows; - using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; - using DynamicData; /// @@ -56,11 +56,6 @@ public class ParameterTypeTableViewModel : SingleIterationApplicationBaseViewMod /// private readonly ISessionService sessionService; - /// - /// Injected property to get access to - /// - public IShowHideDeprecatedThingsService ShowHideDeprecatedThingsService { get; } - /// /// A collection of all /// @@ -110,6 +105,11 @@ public ParameterTypeTableViewModel(ISessionService sessionService, IShowHideDepr /// public IEnumerable ReferenceDataLibraries { get; set; } + /// + /// Injected property to get access to + /// + public IShowHideDeprecatedThingsService ShowHideDeprecatedThingsService { get; } + /// /// A reactive collection of /// @@ -120,17 +120,6 @@ public ParameterTypeTableViewModel(ISessionService sessionService, IShowHideDepr /// public SourceList DataSource { get; } = new(); - /// - /// Handles the refresh of the current - /// - /// A - protected override async Task OnSessionRefreshed() - { - this.IsLoading = true; - await Task.Delay(1); - this.IsLoading = false; - } - /// /// Method invoked when the component is ready to start, having received its /// initial parameters from its parent in the render tree. @@ -189,6 +178,17 @@ public async Task UpdateProperties(IEnumerable parameterTypes) this.IsLoading = false; } + /// + /// Handles the refresh of the current + /// + /// A + protected override async Task OnSessionRefreshed() + { + this.IsLoading = true; + await Task.Delay(1); + this.IsLoading = false; + } + /// /// Refresh the displayed container name for the category rows /// @@ -199,6 +199,7 @@ private async Task RefreshContainerName(ReferenceDataLibrary rdl) { this.IsLoading = true; await Task.Delay(1); + foreach (var parameter in this.Rows.Items) { if (parameter.ContainerName != rdl.ShortName) @@ -206,6 +207,7 @@ private async Task RefreshContainerName(ReferenceDataLibrary rdl) parameter.ContainerName = rdl.ShortName; } } + this.IsLoading = false; } @@ -216,10 +218,12 @@ private async Task RefreshAccessRight() { this.IsLoading = true; await Task.Delay(1); + foreach (var row in this.Rows.Items) { row.IsAllowedToWrite = this.permissionService.CanWrite(ClassKind.Category, row.ParameterType.Container); } + this.IsLoading = false; } diff --git a/COMETwebapp/ViewModels/Components/SubscriptionDashboard/ISubscriptionDashboardBodyViewModel.cs b/COMETwebapp/ViewModels/Components/SubscriptionDashboard/ISubscriptionDashboardBodyViewModel.cs index e9e39225..27829938 100644 --- a/COMETwebapp/ViewModels/Components/SubscriptionDashboard/ISubscriptionDashboardBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/SubscriptionDashboard/ISubscriptionDashboardBodyViewModel.cs @@ -24,7 +24,7 @@ namespace COMETwebapp.ViewModels.Components.SubscriptionDashboard { - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; /// diff --git a/COMETwebapp/ViewModels/Components/SubscriptionDashboard/SubscriptionDashboardBodyViewModel.cs b/COMETwebapp/ViewModels/Components/SubscriptionDashboard/SubscriptionDashboardBodyViewModel.cs index 34bfaa2e..bbee94d8 100644 --- a/COMETwebapp/ViewModels/Components/SubscriptionDashboard/SubscriptionDashboardBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/SubscriptionDashboard/SubscriptionDashboardBodyViewModel.cs @@ -31,11 +31,9 @@ namespace COMETwebapp.ViewModels.Components.SubscriptionDashboard using COMET.Web.Common.Extensions; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; - using COMETwebapp.Extensions; - using ReactiveUI; /// @@ -81,26 +79,26 @@ public SubscriptionDashboardBodyViewModel(ISessionService sessionService, ISubsc /// Update this view model properties when the has changed /// /// A - protected override async Task OnIterationChanged() + protected override async Task OnThingChanged() { - await base.OnIterationChanged(); + await base.OnThingChanged(); - this.OptionSelector.CurrentIteration = this.CurrentIteration; - this.ParameterTypeSelector.CurrentIteration = this.CurrentIteration; + this.OptionSelector.CurrentIteration = this.CurrentThing; + this.ParameterTypeSelector.CurrentIteration = this.CurrentThing; - var ownedSubscriptions = this.CurrentIteration?.QueryOwnedParameterSubscriptions(this.CurrentDomain).ToList() + var ownedSubscriptions = this.CurrentThing?.QueryOwnedParameterSubscriptions(this.CurrentDomain).ToList() ?? new List(); - var availableOptions = this.CurrentIteration?.Option.ToList(); + var availableOptions = this.CurrentThing?.Option.ToList(); - var subscribedParameters = this.CurrentIteration?.QuerySubscribedParameterByOthers(this.CurrentDomain).ToList() + var subscribedParameters = this.CurrentThing?.QuerySubscribedParameterByOthers(this.CurrentDomain).ToList() ?? new List(); var availableParameterTypes = ownedSubscriptions.Select(x => x.ParameterType).ToList(); availableParameterTypes.AddRange(subscribedParameters.Select(x => x.ParameterType)); this.ParameterTypeSelector.FilterAvailableParameterTypes(availableParameterTypes.Select(x => x.Iid).Distinct()); - this.SubscribedTable.UpdateProperties(ownedSubscriptions, availableOptions, this.CurrentIteration); + this.SubscribedTable.UpdateProperties(ownedSubscriptions, availableOptions, this.CurrentThing); this.DomainOfExpertiseSubscriptionTable.UpdateProperties(subscribedParameters); await Task.Delay(1); this.IsLoading = false; @@ -112,7 +110,7 @@ protected override async Task OnIterationChanged() /// A protected override async Task OnSessionRefreshed() { - await this.OnIterationChanged(); + await this.OnThingChanged(); await this.UpdateTables(); } @@ -123,7 +121,7 @@ protected override async Task OnSessionRefreshed() protected override Task OnDomainChanged() { base.OnDomainChanged(); - return this.OnIterationChanged(); + return this.OnThingChanged(); } /// diff --git a/COMETwebapp/ViewModels/Components/SystemRepresentation/ISystemRepresentationBodyViewModel.cs b/COMETwebapp/ViewModels/Components/SystemRepresentation/ISystemRepresentationBodyViewModel.cs index b46bf2ce..06ea52ce 100644 --- a/COMETwebapp/ViewModels/Components/SystemRepresentation/ISystemRepresentationBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/SystemRepresentation/ISystemRepresentationBodyViewModel.cs @@ -26,7 +26,7 @@ namespace COMETwebapp.ViewModels.Components.SystemRepresentation { using CDP4Common.EngineeringModelData; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; /// diff --git a/COMETwebapp/ViewModels/Components/SystemRepresentation/SystemRepresentationBodyViewModel.cs b/COMETwebapp/ViewModels/Components/SystemRepresentation/SystemRepresentationBodyViewModel.cs index a2112d7e..bde47dfb 100644 --- a/COMETwebapp/ViewModels/Components/SystemRepresentation/SystemRepresentationBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/SystemRepresentation/SystemRepresentationBodyViewModel.cs @@ -1,207 +1,207 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2023 RHEA System S.A. -// -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar -// -// This file is part of COMET WEB Community Edition -// The COMET WEB Community Edition is the RHEA 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 COMETwebapp.ViewModels.Components.SystemRepresentation -{ - using CDP4Common.SiteDirectoryData; - using CDP4Common.EngineeringModelData; - - using CDP4Dal; - - using COMET.Web.Common.Extensions; - using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; - using COMET.Web.Common.ViewModels.Components.Selectors; - - using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; - - using Microsoft.AspNetCore.Components; - - using ReactiveUI; - - /// - /// View Model that handle the logic for the System Representation application - /// - public class SystemRepresentationBodyViewModel : SingleIterationApplicationBaseViewModel, ISystemRepresentationBodyViewModel - { - /// - /// Initializes a new instance of the class. - /// - /// The - public SystemRepresentationBodyViewModel(ISessionService sessionService) : base(sessionService) - { - this.ProductTreeViewModel = new SystemRepresentationTreeViewModel() - { - OnClick = new EventCallbackFactory().Create(this, this.SelectElement) - }; - - this.Disposables.Add(this.WhenAnyValue(x => x.OptionSelector.SelectedOption).SubscribeAsync(_ => this.ApplyFilters())); - } - - /// - /// Gets the - /// - public IOptionSelectorViewModel OptionSelector { get; private set; } = new OptionSelectorViewModel(false); - - /// - /// Represents the RootNode of the tree - /// - public SystemNodeViewModel RootNode { get; set; } - - /// - /// The - /// - public SystemRepresentationTreeViewModel ProductTreeViewModel { get; } - - /// - /// The - /// - public IElementDefinitionDetailsViewModel ElementDefinitionDetailsViewModel { get; } = new ElementDefinitionDetailsViewModel(); - - /// - /// All of the iteration - /// - public List Elements { get; set; } = new(); - - /// - /// Updates Elements list when a filter for option is selected - /// - /// the selected - public void OnOptionFilterChange(Option selectedOption) - { - this.Elements.Clear(); - - var nestedElements = this.CurrentIteration.QueryNestedElements(selectedOption).ToList(); - - var associatedElements = new List(); - associatedElements.AddRange(nestedElements.SelectMany(x => x.ElementUsage)); - associatedElements = associatedElements.Distinct().ToList(); - - var elementsToRemove = new List(); - - this.Elements.ForEach(e => - { - if (e.GetType() == typeof(ElementUsage) && !associatedElements.Contains(e)) - { - elementsToRemove.Add(e); - } - }); - - this.Elements.RemoveAll(e => elementsToRemove.Contains(e)); - - this.InitializeElements(); - this.ProductTreeViewModel.CreateTree(this.Elements, this.OptionSelector.SelectedOption, new List()); - } - - /// - /// Update this view model properties - /// - /// A - protected override async Task OnIterationChanged() - { - this.Elements.Clear(); - await base.OnIterationChanged(); - this.OptionSelector.CurrentIteration = this.CurrentIteration; - this.InitializeElements(); - await this.ApplyFilters(); - this.IsLoading = false; - } - - /// - /// Handles the change of - /// - /// A - protected override async Task OnDomainChanged() - { - await base.OnDomainChanged(); - - if (this.CurrentDomain != null) - { - this.IsLoading = true; - await Task.Delay(1); - - await this.ApplyFilters(); - - this.IsLoading = false; - } - } - - /// - /// Handles the refresh of the current - /// - /// A - protected override Task OnSessionRefreshed() - { - return this.OnIterationChanged(); - } - - /// - /// Initialize list - /// - private void InitializeElements() - { - if (this.CurrentIteration.TopElement != null) - { - this.Elements.Add(this.CurrentIteration.TopElement); - } - - this.CurrentIteration.Element.ForEach(e => this.Elements.AddRange(e.ContainedElement)); - } - - /// - /// set the selected - /// - /// The selected - /// A - public void SelectElement(SystemNodeViewModel selectedNode) - { - // It is preferable to have a selection based on the Iid of the Thing - this.ElementDefinitionDetailsViewModel.SelectedSystemNode = this.Elements.FirstOrDefault(e => e.Name.Equals(selectedNode.Title)); - - this.ElementDefinitionDetailsViewModel.Rows = this.ElementDefinitionDetailsViewModel.SelectedSystemNode switch - { - ElementDefinition elementDefinition => elementDefinition.Parameter.Select(x => new ElementDefinitionDetailsRowViewModel(x)).ToList(), - ElementUsage elementUsage => elementUsage.ElementDefinition.Parameter.Select(x => new ElementDefinitionDetailsRowViewModel(x)).ToList(), - _ => null - }; - } - - /// - /// Apply all the filters on the - /// - /// A - public async Task ApplyFilters() - { - if (this.CurrentIteration != null) - { - this.IsLoading = true; - await Task.Delay(1); - - this.OnOptionFilterChange(this.OptionSelector.SelectedOption); - - this.IsLoading = false; - } - } - } -} +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 COMETwebapp.ViewModels.Components.SystemRepresentation +{ + using CDP4Common.EngineeringModelData; + using CDP4Common.SiteDirectoryData; + + using CDP4Dal; + + using COMET.Web.Common.Extensions; + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.ViewModels.Components.Applications; + using COMET.Web.Common.ViewModels.Components.Selectors; + + using COMETwebapp.ViewModels.Components.SystemRepresentation.Rows; + + using Microsoft.AspNetCore.Components; + + using ReactiveUI; + + /// + /// View Model that handle the logic for the System Representation application + /// + public class SystemRepresentationBodyViewModel : SingleIterationApplicationBaseViewModel, ISystemRepresentationBodyViewModel + { + /// + /// Initializes a new instance of the class. + /// + /// The + public SystemRepresentationBodyViewModel(ISessionService sessionService) : base(sessionService) + { + this.ProductTreeViewModel = new SystemRepresentationTreeViewModel + { + OnClick = new EventCallbackFactory().Create(this, this.SelectElement) + }; + + this.Disposables.Add(this.WhenAnyValue(x => x.OptionSelector.SelectedOption).SubscribeAsync(_ => this.ApplyFilters())); + } + + /// + /// Gets the + /// + public IOptionSelectorViewModel OptionSelector { get; private set; } = new OptionSelectorViewModel(false); + + /// + /// Represents the RootNode of the tree + /// + public SystemNodeViewModel RootNode { get; set; } + + /// + /// The + /// + public SystemRepresentationTreeViewModel ProductTreeViewModel { get; } + + /// + /// The + /// + public IElementDefinitionDetailsViewModel ElementDefinitionDetailsViewModel { get; } = new ElementDefinitionDetailsViewModel(); + + /// + /// All of the iteration + /// + public List Elements { get; set; } = new(); + + /// + /// set the selected + /// + /// The selected + /// A + public void SelectElement(SystemNodeViewModel selectedNode) + { + // It is preferable to have a selection based on the Iid of the Thing + this.ElementDefinitionDetailsViewModel.SelectedSystemNode = this.Elements.FirstOrDefault(e => e.Name.Equals(selectedNode.Title)); + + this.ElementDefinitionDetailsViewModel.Rows = this.ElementDefinitionDetailsViewModel.SelectedSystemNode switch + { + ElementDefinition elementDefinition => elementDefinition.Parameter.Select(x => new ElementDefinitionDetailsRowViewModel(x)).ToList(), + ElementUsage elementUsage => elementUsage.ElementDefinition.Parameter.Select(x => new ElementDefinitionDetailsRowViewModel(x)).ToList(), + _ => null + }; + } + + /// + /// Apply all the filters on the + /// + /// A + public async Task ApplyFilters() + { + if (this.CurrentThing != null) + { + this.IsLoading = true; + await Task.Delay(1); + + this.OnOptionFilterChange(this.OptionSelector.SelectedOption); + + this.IsLoading = false; + } + } + + /// + /// Updates Elements list when a filter for option is selected + /// + /// the selected + public void OnOptionFilterChange(Option selectedOption) + { + this.Elements.Clear(); + + var nestedElements = this.CurrentThing.QueryNestedElements(selectedOption).ToList(); + + var associatedElements = new List(); + associatedElements.AddRange(nestedElements.SelectMany(x => x.ElementUsage)); + associatedElements = associatedElements.Distinct().ToList(); + + var elementsToRemove = new List(); + + this.Elements.ForEach(e => + { + if (e.GetType() == typeof(ElementUsage) && !associatedElements.Contains(e)) + { + elementsToRemove.Add(e); + } + }); + + this.Elements.RemoveAll(e => elementsToRemove.Contains(e)); + + this.InitializeElements(); + this.ProductTreeViewModel.CreateTree(this.Elements, this.OptionSelector.SelectedOption, new List()); + } + + /// + /// Update this view model properties + /// + /// A + protected override async Task OnThingChanged() + { + this.Elements.Clear(); + await base.OnThingChanged(); + this.OptionSelector.CurrentIteration = this.CurrentThing; + this.InitializeElements(); + await this.ApplyFilters(); + this.IsLoading = false; + } + + /// + /// Handles the change of + /// + /// A + protected override async Task OnDomainChanged() + { + await base.OnDomainChanged(); + + if (this.CurrentDomain != null) + { + this.IsLoading = true; + await Task.Delay(1); + + await this.ApplyFilters(); + + this.IsLoading = false; + } + } + + /// + /// Handles the refresh of the current + /// + /// A + protected override Task OnSessionRefreshed() + { + return this.OnThingChanged(); + } + + /// + /// Initialize list + /// + private void InitializeElements() + { + if (this.CurrentThing.TopElement != null) + { + this.Elements.Add(this.CurrentThing.TopElement); + } + + this.CurrentThing.Element.ForEach(e => this.Elements.AddRange(e.ContainedElement)); + } + } +} diff --git a/COMETwebapp/ViewModels/Components/UserManagement/IUserManagementTableViewModel.cs b/COMETwebapp/ViewModels/Components/UserManagement/IUserManagementTableViewModel.cs index d9e35e64..8c970ba4 100644 --- a/COMETwebapp/ViewModels/Components/UserManagement/IUserManagementTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/UserManagement/IUserManagementTableViewModel.cs @@ -26,7 +26,7 @@ namespace COMETwebapp.ViewModels.Components.UserManagement { using CDP4Common.SiteDirectoryData; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.UserManagement.Rows; diff --git a/COMETwebapp/ViewModels/Components/UserManagement/UserManagementTableViewModel.cs b/COMETwebapp/ViewModels/Components/UserManagement/UserManagementTableViewModel.cs index f85b6250..944635ba 100644 --- a/COMETwebapp/ViewModels/Components/UserManagement/UserManagementTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/UserManagement/UserManagementTableViewModel.cs @@ -24,8 +24,6 @@ namespace COMETwebapp.ViewModels.Components.UserManagement { - using System.Reactive.Linq; - using AntDesign; using CDP4Common.CommonData; @@ -37,7 +35,7 @@ namespace COMETwebapp.ViewModels.Components.UserManagement using CDP4Dal.Permission; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.UserManagement.Rows; @@ -63,11 +61,6 @@ public class UserManagementTableViewModel : SingleIterationApplicationBaseViewMo /// private readonly ISessionService sessionService; - /// - /// Injected property to get access to - /// - public IShowHideDeprecatedThingsService ShowHideDeprecatedThingsService { get; } - /// /// Backing field for /// @@ -88,69 +81,9 @@ public UserManagementTableViewModel(ISessionService sessionService, IShowHideDep } /// - /// Handles the refresh of the current - /// - /// A - protected override async Task OnSessionRefreshed() - { - if (!this.AddedThings.Any() && !this.DeletedThings.Any() && !this.UpdatedThings.Any()) - { - return; - } - - this.IsLoading = true; - await Task.Delay(1); - - this.RemoveRows(this.DeletedThings.OfType()); - this.UpdateRows(this.UpdatedThings.OfType()); - this.Rows.AddRange(this.AddedThings.OfType().Select(x => new PersonRowViewModel(x))); - - this.ClearRecordedChanges(); - this.RefreshAccessRight(); - this.IsLoading = false; - } - - /// - /// The logic used to check if a change should be recorded an - /// - /// The - /// true if the change should be recorded, false otherwise - protected override bool ShouldRecordChange(ObjectChangedEvent objectChangedEvent) - { - return true; - } - - /// - /// Remove rows related to a that has been deleted - /// - /// A collection of deleted - public void RemoveRows(IEnumerable deletedThings) - { - foreach (Person person in deletedThings) - { - var row = this.Rows.Items.FirstOrDefault(x => x.Person.Iid == person.Iid); - if (row != null) - { - this.Rows.Remove(row); - } - } - } - - /// - /// Updates rows related to that have been updated + /// Injected property to get access to /// - /// A collection of updated - public void UpdateRows(IEnumerable updatedThings) - { - foreach (Person person in updatedThings) - { - var row = this.Rows.Items.FirstOrDefault(x => x.Person.Iid == person.Iid); - if (row != null) - { - row.UpdateProperties(new PersonRowViewModel(person)); - } - } - } + public IShowHideDeprecatedThingsService ShowHideDeprecatedThingsService { get; } /// /// The to create or edit @@ -319,6 +252,40 @@ public void OnInitialized() this.RefreshAccessRight(); } + /// + /// Remove rows related to a that has been deleted + /// + /// A collection of deleted + public void RemoveRows(IEnumerable deletedThings) + { + foreach (var person in deletedThings) + { + var row = this.Rows.Items.FirstOrDefault(x => x.Person.Iid == person.Iid); + + if (row != null) + { + this.Rows.Remove(row); + } + } + } + + /// + /// Updates rows related to that have been updated + /// + /// A collection of updated + public void UpdateRows(IEnumerable updatedThings) + { + foreach (var person in updatedThings) + { + var row = this.Rows.Items.FirstOrDefault(x => x.Person.Iid == person.Iid); + + if (row != null) + { + row.UpdateProperties(new PersonRowViewModel(person)); + } + } + } + /// /// Tries to undeprecate a /// @@ -348,25 +315,58 @@ public async Task DeprecatingPerson() } /// - /// Updates the active user access rights + /// Handles the refresh of the current /// - private void RefreshAccessRight() + /// A + protected override async Task OnSessionRefreshed() { - foreach (var row in this.Rows.Items) + if (!this.AddedThings.Any() && !this.DeletedThings.Any() && !this.UpdatedThings.Any()) { - row.IsAllowedToWrite = row.Person.Iid != this.sessionService.Session.ActivePerson.Iid - && this.permissionService.CanWrite(ClassKind.Person, this.sessionService.GetSiteDirectory()); + return; } + + this.IsLoading = true; + await Task.Delay(1); + + this.RemoveRows(this.DeletedThings.OfType()); + this.UpdateRows(this.UpdatedThings.OfType()); + this.Rows.AddRange(this.AddedThings.OfType().Select(x => new PersonRowViewModel(x))); + + this.ClearRecordedChanges(); + this.RefreshAccessRight(); + this.IsLoading = false; + } + + /// + /// The logic used to check if a change should be recorded an + /// + /// The + /// true if the change should be recorded, false otherwise + protected override bool ShouldRecordChange(ObjectChangedEvent objectChangedEvent) + { + return true; } /// /// Update this view model properties /// /// A - protected override async Task OnIterationChanged() + protected override async Task OnThingChanged() { - await base.OnIterationChanged(); + await base.OnThingChanged(); this.IsLoading = false; } + + /// + /// Updates the active user access rights + /// + private void RefreshAccessRight() + { + foreach (var row in this.Rows.Items) + { + row.IsAllowedToWrite = row.Person.Iid != this.sessionService.Session.ActivePerson.Iid + && this.permissionService.CanWrite(ClassKind.Person, this.sessionService.GetSiteDirectory()); + } + } } } diff --git a/COMETwebapp/ViewModels/Components/Viewer/IViewerBodyViewModel.cs b/COMETwebapp/ViewModels/Components/Viewer/IViewerBodyViewModel.cs index 1e1bea24..3830fcbd 100644 --- a/COMETwebapp/ViewModels/Components/Viewer/IViewerBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/Viewer/IViewerBodyViewModel.cs @@ -26,7 +26,7 @@ namespace COMETwebapp.ViewModels.Components.Viewer { using CDP4Common.EngineeringModelData; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMETwebapp.Utilities; diff --git a/COMETwebapp/ViewModels/Components/Viewer/ViewerBodyViewModel.cs b/COMETwebapp/ViewModels/Components/Viewer/ViewerBodyViewModel.cs index 2b67501b..e5d3e7be 100644 --- a/COMETwebapp/ViewModels/Components/Viewer/ViewerBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/Viewer/ViewerBodyViewModel.cs @@ -28,9 +28,8 @@ namespace COMETwebapp.ViewModels.Components.Viewer using CDP4Dal; - using COMET.Web.Common.Extensions; using COMET.Web.Common.Services.SessionManagement; - using COMET.Web.Common.ViewModels.Components; + using COMET.Web.Common.ViewModels.Components.Applications; using COMET.Web.Common.ViewModels.Components.Selectors; using COMETwebapp.Services.Interoperability; @@ -116,7 +115,7 @@ public async Task InitializeViewModel() /// public IEnumerable InitializeElements() { - return this.CurrentIteration?.QueryElementsBase().ToList() ?? new List(); + return this.CurrentThing?.QueryElementsBase().ToList() ?? new List(); } /// @@ -139,18 +138,18 @@ public void InitializeElementsAndCreateTree() /// A protected override Task OnSessionRefreshed() { - return this.OnIterationChanged(); + return this.OnThingChanged(); } /// /// Update this view model properties /// /// A - protected override async Task OnIterationChanged() + protected override async Task OnThingChanged() { - await base.OnIterationChanged(); - this.OptionSelector.CurrentIteration = this.CurrentIteration; - this.MultipleFiniteStateSelector.CurrentIteration = this.CurrentIteration; + await base.OnThingChanged(); + this.OptionSelector.CurrentIteration = this.CurrentThing; + this.MultipleFiniteStateSelector.CurrentIteration = this.CurrentThing; await this.InitializeViewModel(); } diff --git a/COMETwebapp/_Imports.razor b/COMETwebapp/_Imports.razor index b15ba495..9af0a01d 100644 --- a/COMETwebapp/_Imports.razor +++ b/COMETwebapp/_Imports.razor @@ -31,6 +31,7 @@ @using BlazorStrap @using DevExpress.Blazor @using COMET.Web.Common.Components +@using COMET.Web.Common.Components.Applications @using COMET.Web.Common.Components.ParameterTypeEditors @using COMET.Web.Common.Components.Selectors @using COMET.Web.Common.Components.ValueSetRenderers