From ce3541b9b63fb69d945719a47369ee9e14cb9eff Mon Sep 17 00:00:00 2001 From: nabilatrhea <112706228+nabilatrhea@users.noreply.github.com> Date: Fri, 8 Sep 2023 13:07:53 +0200 Subject: [PATCH] Add configurationService for navigation menu : Fix #446 (#447) * add configurationService for navigation menu * fix unit tests * fix indentation --- .../Shared/TopMenuTestFixture.cs | 12 ++++++++---- .../Enumerations/TextConfigurationKind.cs | 17 ++++++++++++++++- .../Shared/TopMenuEntry/ApplicationMenu.razor | 3 ++- .../TopMenuEntry/ApplicationMenu.razor.cs | 7 +++++++ .../Shared/TopMenuEntry/ModelMenu.razor | 5 +++-- .../Shared/TopMenuEntry/ModelMenu.razor.cs | 7 +++++++ .../wwwroot/DefaultTextConfiguration.json | 5 ++++- 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/COMET.Web.Common.Tests/Shared/TopMenuTestFixture.cs b/COMET.Web.Common.Tests/Shared/TopMenuTestFixture.cs index 0d905012..75cbb266 100644 --- a/COMET.Web.Common.Tests/Shared/TopMenuTestFixture.cs +++ b/COMET.Web.Common.Tests/Shared/TopMenuTestFixture.cs @@ -38,6 +38,7 @@ namespace COMET.Web.Common.Tests.Shared using COMET.Web.Common.Components; using COMET.Web.Common.Model; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.NotificationService; using COMET.Web.Common.Services.RegistrationService; using COMET.Web.Common.Services.SessionManagement; @@ -71,6 +72,7 @@ public class TopMenuTestFixture private Mock authenticationService; private Mock registrationService; private Mock versionService; + private Mock configurationService; private SourceList sourceList; private List registeredMenuEntries; private List registeredApplications; @@ -103,6 +105,8 @@ public void Setup() this.context.Services.AddSingleton(); this.context.Services.AddSingleton(); this.context.Services.AddSingleton(); + this.configurationService = new Mock(); + this.context.Services.AddSingleton(this.configurationService.Object); this.context.ConfigureDevExpressBlazor(); } @@ -271,8 +275,8 @@ public void VerifyReturnToHomeWithTitle() navigationManager.NavigateTo("/AnUrl"); var renderer = this.context.RenderComponent(); var topMenuTitle = renderer.FindComponent(); - var link =(ElementWrapper) topMenuTitle.Find("a"); - var htmlAnchor = (IHtmlAnchorElement) link.WrappedElement; + var link = (ElementWrapper)topMenuTitle.Find("a"); + var htmlAnchor = (IHtmlAnchorElement)link.WrappedElement; Assert.That(navigationManager.Uri, Does.EndWith("AnUrl")); navigationManager.NavigateTo(htmlAnchor.Href); Assert.That(navigationManager.Uri, Does.Not.EndWith("AnUrl")); @@ -283,7 +287,7 @@ public void VerifyCustomTitleHeader() { this.registrationService.Setup(x => x.CustomHeader).Returns(typeof(CustomHeader)); var renderer = this.context.RenderComponent(); - + Assert.Multiple(() => { Assert.That(() => renderer.FindComponent(), Throws.Exception); @@ -295,7 +299,7 @@ private class TestAuthorizedMenuEntry : AuthorizedMenuEntry { } - private class CustomHeader: MenuEntryBase + private class CustomHeader : MenuEntryBase { } } diff --git a/COMET.Web.Common/Enumerations/TextConfigurationKind.cs b/COMET.Web.Common/Enumerations/TextConfigurationKind.cs index 761fca2e..c33fd1dc 100644 --- a/COMET.Web.Common/Enumerations/TextConfigurationKind.cs +++ b/COMET.Web.Common/Enumerations/TextConfigurationKind.cs @@ -63,6 +63,21 @@ public enum TextConfigurationKind /// /// The title to use in the landing page /// - LandingPageTitle = 6 + LandingPageTitle = 6, + + /// + /// The caption to use as navigation application selector title + /// + NavigationApplicationSelectorTitle = 7, + + /// + /// The caption to use as navigation model selector title + /// + NavigationModelSelectorTitle = 8, + + /// + /// The caption to use as title for the open button + /// + ModelOpenButtonCaption = 9, } } diff --git a/COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor b/COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor index 2461a9e1..61af3c6f 100644 --- a/COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor +++ b/COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor @@ -21,9 +21,10 @@ -------------------------------------------------------------------------------> @namespace COMET.Web.Common.Shared.TopMenuEntry +@using COMET.Web.Common.Enumerations @inherits AuthorizedMenuEntry - + @foreach (var applicationEntry in this.RegistrationService.RegisteredApplications) { diff --git a/COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor.cs b/COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor.cs index 25e42c43..6d7d00b6 100644 --- a/COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor.cs +++ b/COMET.Web.Common/Shared/TopMenuEntry/ApplicationMenu.razor.cs @@ -26,6 +26,7 @@ namespace COMET.Web.Common.Shared.TopMenuEntry { using COMET.Web.Common.Model; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.RegistrationService; using Microsoft.AspNetCore.Components; @@ -40,5 +41,11 @@ public partial class ApplicationMenu /// [Inject] internal IRegistrationService RegistrationService { get; set; } + + /// + /// The + /// + [Inject] + public IConfigurationService ConfigurationService { get; set; } } } diff --git a/COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor b/COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor index 76a650b0..204e98bc 100644 --- a/COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor +++ b/COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor @@ -20,6 +20,7 @@ // limitations under the License. -------------------------------------------------------------------------------> @namespace COMET.Web.Common.Shared.TopMenuEntry +@using COMET.Web.Common.Enumerations @inherits AuthorizedMenuEntry @@ -32,14 +33,14 @@ - + @context.Text - + @contextSwitch.Text diff --git a/COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor.cs b/COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor.cs index afb83274..9fb9d332 100644 --- a/COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor.cs +++ b/COMET.Web.Common/Shared/TopMenuEntry/ModelMenu.razor.cs @@ -27,6 +27,7 @@ namespace COMET.Web.Common.Shared.TopMenuEntry { using CDP4Common.EngineeringModelData; + using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.ViewModels.Shared.TopMenuEntry; using Microsoft.AspNetCore.Components; @@ -44,6 +45,12 @@ public partial class ModelMenu [Inject] public IModelMenuViewModel ViewModel { get; set; } + /// + /// The + /// + [Inject] + public IConfigurationService ConfigurationService { get; set; } + /// /// Method invoked when the component is ready to start, having received its /// initial parameters from its parent in the render tree. diff --git a/COMET.Web.Common/wwwroot/DefaultTextConfiguration.json b/COMET.Web.Common/wwwroot/DefaultTextConfiguration.json index 1fd073a8..618c17a3 100644 --- a/COMET.Web.Common/wwwroot/DefaultTextConfiguration.json +++ b/COMET.Web.Common/wwwroot/DefaultTextConfiguration.json @@ -5,5 +5,8 @@ "ModelTitleCaption": "Model", "IterationTitleCaption": "Iteration", "DomainTitleCaption": "Domain", - "LandingPageTitle" : "" + "LandingPageTitle": "", + "NavigationApplicationSelectorTitle": "Application", + "NavigationModelSelectorTitle": "Models", + "ModelOpenButtonCaption": "Open Model" }