From 52e0356490703cfd01229cd405b2617bac0d02f5 Mon Sep 17 00:00:00 2001 From: Joao Rua Date: Thu, 18 Jul 2024 12:28:09 +0100 Subject: [PATCH 1/2] caption updated and icon added --- .../Components/Tabs/TabComponent.razor | 16 ++++++-- .../Components/Tabs/TabComponent.razor.cs | 12 ++++++ .../Components/Tabs/TabsPanelComponent.razor | 3 ++ .../Tabs/TabsPanelComponent.razor.cs | 39 +++++++++++++++++++ 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/COMETwebapp/Components/Tabs/TabComponent.razor b/COMETwebapp/Components/Tabs/TabComponent.razor index c0b230b3..09d92ff1 100644 --- a/COMETwebapp/Components/Tabs/TabComponent.razor +++ b/COMETwebapp/Components/Tabs/TabComponent.razor @@ -22,15 +22,25 @@ @inherits DisposableComponent
+ @onclick="@(() => this.OnClick?.Invoke())" + title="@(this.Caption)"> + + @if (this.ApplicationIcon is not null) + { + + + + } @(this.Text) - + @if (this.CustomOptionIcon is not null) { diff --git a/COMETwebapp/Components/Tabs/TabComponent.razor.cs b/COMETwebapp/Components/Tabs/TabComponent.razor.cs index a3790502..ed372ae0 100644 --- a/COMETwebapp/Components/Tabs/TabComponent.razor.cs +++ b/COMETwebapp/Components/Tabs/TabComponent.razor.cs @@ -39,6 +39,12 @@ public partial class TabComponent : DisposableComponent [Parameter] public string Text { get; set; } + /// + /// Gets or sets the caption text to be displayed when tab hover + /// + [Parameter] + public string Caption { get; set; } + /// /// Gets or sets the icon to be displayed on the right side of a tab /// @@ -51,6 +57,12 @@ public partial class TabComponent : DisposableComponent [Parameter] public Type CustomOptionIcon { get; set; } + /// + /// Gets or sets the icon to be displayed in the left, distinguishing different applications + /// + [Parameter] + public Type ApplicationIcon { get; set; } + /// /// Gets or sets the action to be executed when the tab is clicked /// diff --git a/COMETwebapp/Components/Tabs/TabsPanelComponent.razor b/COMETwebapp/Components/Tabs/TabsPanelComponent.razor index d07fe76e..ffc055a9 100644 --- a/COMETwebapp/Components/Tabs/TabsPanelComponent.razor +++ b/COMETwebapp/Components/Tabs/TabsPanelComponent.razor @@ -19,6 +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/. -------------------------------------------------------------------------------> +@using COMETwebapp.Model @using CDP4Common.CommonData @inherits DisposableComponent @@ -30,12 +31,14 @@ @foreach (var tab in this.Tabs) { } diff --git a/COMETwebapp/Components/Tabs/TabsPanelComponent.razor.cs b/COMETwebapp/Components/Tabs/TabsPanelComponent.razor.cs index 3ae5831c..b81b4d0e 100644 --- a/COMETwebapp/Components/Tabs/TabsPanelComponent.razor.cs +++ b/COMETwebapp/Components/Tabs/TabsPanelComponent.razor.cs @@ -24,9 +24,12 @@ namespace COMETwebapp.Components.Tabs { + using System.Text; + using CDP4Common.EngineeringModelData; using COMET.Web.Common.Components; + using COMET.Web.Common.Services.SessionManagement; using COMETwebapp.Model; using COMETwebapp.ViewModels.Pages; @@ -94,6 +97,12 @@ public partial class TabsPanelComponent : DisposableComponent [Parameter] public bool IsSidePanelAvailable { get; set; } + /// + /// Gets or sets the + /// + [Inject] + public ISessionService SessionService { get; set; } + /// /// Gets the tab text for the given object of interest /// @@ -109,6 +118,36 @@ private static string GetTabText(object objectOfInterest) }; } + /// + /// Gets the tab caption text for the given object of interest + /// + /// The object of interest to get its tab caption text + /// The tab caption + private string GetCaptionText(object objectOfInterest) + { + var modelName = new StringBuilder(); + Iteration iterationOfInterest = null; + + switch (objectOfInterest) + { + case Iteration iteration: + modelName.Append(((EngineeringModel)iteration.Container).EngineeringModelSetup.Name + " - " + iteration.IterationSetup.IterationNumber); + iterationOfInterest = iteration; + break; + case EngineeringModel engineeringModel: + modelName.Append(engineeringModel.EngineeringModelSetup.Name); + iterationOfInterest = engineeringModel.Iteration.First(x => x.IterationSetup.FrozenOn == null); + break; + } + + modelName.Append(" - "); + + var domainOfExpertiseShortName = this.SessionService.GetDomainOfExpertise(iterationOfInterest).ShortName; + modelName.Append(domainOfExpertiseShortName); + + return modelName.ToString(); + } + /// /// Adds a new side panel to the tabs page /// From bd1628a70295ec79879627f9b76f2b810689e04c Mon Sep 17 00:00:00 2001 From: Joao Rua Date: Thu, 18 Jul 2024 12:33:19 +0100 Subject: [PATCH 2/2] unit tests --- .../Tabs/TabsPanelComponentTestFixture.cs | 13 ++++++++++++- COMETwebapp.Tests/Pages/TabsTestFixture.cs | 9 +++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/COMETwebapp.Tests/Components/Tabs/TabsPanelComponentTestFixture.cs b/COMETwebapp.Tests/Components/Tabs/TabsPanelComponentTestFixture.cs index aeb1511a..1e3b8680 100644 --- a/COMETwebapp.Tests/Components/Tabs/TabsPanelComponentTestFixture.cs +++ b/COMETwebapp.Tests/Components/Tabs/TabsPanelComponentTestFixture.cs @@ -31,6 +31,7 @@ namespace COMETwebapp.Tests.Components.Tabs 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.EngineeringModel; @@ -77,11 +78,17 @@ public void SetUp() this.engineeringModelBodyViewModel = new Mock(); this.engineeringModelBodyViewModel.Setup(x => x.OptionsTableViewModel).Returns(optionsTableViewModel.Object); + var engineeringModelSetup = new EngineeringModelSetup(); + this.iteration = new Iteration { IterationSetup = new IterationSetup { - Container = new EngineeringModelSetup() + Container = engineeringModelSetup + }, + Container = new EngineeringModel + { + EngineeringModelSetup = engineeringModelSetup } }; @@ -96,6 +103,10 @@ public void SetUp() this.viewModel.Setup(x => x.SelectedApplication).Returns(engineeringModelBodyApplication); this.viewModel.Setup(x => x.SidePanels).Returns(new SourceList()); + var sessionService = new Mock(); + sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny())).Returns(new DomainOfExpertise()); + + this.context.Services.AddSingleton(sessionService.Object); this.context.Services.AddSingleton(this.viewModel.Object); this.context.Services.AddSingleton(this.engineeringModelBodyViewModel.Object); this.context.Services.AddSingleton(configuration.Object); diff --git a/COMETwebapp.Tests/Pages/TabsTestFixture.cs b/COMETwebapp.Tests/Pages/TabsTestFixture.cs index 14db8dee..e459bcd9 100644 --- a/COMETwebapp.Tests/Pages/TabsTestFixture.cs +++ b/COMETwebapp.Tests/Pages/TabsTestFixture.cs @@ -88,13 +88,18 @@ public void Setup() this.engineeringModelBodyViewModel = new Mock(); this.engineeringModelBodyViewModel.Setup(x => x.OptionsTableViewModel).Returns(optionsTableViewModel.Object); + var engineeringSetupModel = new EngineeringModelSetup(); + this.iteration = new Iteration { IterationSetup = new IterationSetup { - Container = new EngineeringModelSetup() + Container = engineeringSetupModel }, - Container = new EngineeringModel() + Container = new EngineeringModel + { + EngineeringModelSetup = engineeringSetupModel + } }; var configuration = new Mock();