Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat #698 Update tab caption #706

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,11 +78,17 @@ public void SetUp()
this.engineeringModelBodyViewModel = new Mock<IEngineeringModelBodyViewModel>();
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
}
};

Expand All @@ -96,6 +103,10 @@ public void SetUp()
this.viewModel.Setup(x => x.SelectedApplication).Returns(engineeringModelBodyApplication);
this.viewModel.Setup(x => x.SidePanels).Returns(new SourceList<TabPanelInformation>());

var sessionService = new Mock<ISessionService>();
sessionService.Setup(x => x.GetDomainOfExpertise(It.IsAny<Iteration>())).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);
Expand Down
9 changes: 7 additions & 2 deletions COMETwebapp.Tests/Pages/TabsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ public void Setup()
this.engineeringModelBodyViewModel = new Mock<IEngineeringModelBodyViewModel>();
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<IConfigurationService>();
Expand Down
16 changes: 13 additions & 3 deletions COMETwebapp/Components/Tabs/TabComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@
@inherits DisposableComponent

<div class="@($"tab-component {(this.OnClick != null ? "cursor-pointer" : "")} {(this.IsCurrent ? "current-tab" : "")}")"
@onclick="@(() => this.OnClick?.Invoke())">
@onclick="@(() => this.OnClick?.Invoke())"
title="@(this.Caption)">

@if (this.ApplicationIcon is not null)
{
<DxButton RenderStyle="ButtonRenderStyle.None"
CssClass="px-1">
<DynamicComponent Type="@(this.ApplicationIcon)"
Parameters="IconConfiguration"/>
</DxButton>
}

<span>@(this.Text)</span>

@if (this.CustomOptionIcon is not null)
{
<DxButton RenderStyle="ButtonRenderStyle.None"
Click="@(() => this.OnCustomOptionIconClick?.Invoke())"
CssClass="ps-1 pe-0"
CssClass="ps-2 pe-0"
Id="tab-custom-option-button">
<DynamicComponent Type="@(this.CustomOptionIcon)"
Parameters="IconConfiguration"/>
Expand Down
12 changes: 12 additions & 0 deletions COMETwebapp/Components/Tabs/TabComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public partial class TabComponent : DisposableComponent
[Parameter]
public string Text { get; set; }

/// <summary>
/// Gets or sets the caption text to be displayed when tab hover
/// </summary>
[Parameter]
public string Caption { get; set; }

/// <summary>
/// Gets or sets the icon to be displayed on the right side of a tab
/// </summary>
Expand All @@ -51,6 +57,12 @@ public partial class TabComponent : DisposableComponent
[Parameter]
public Type CustomOptionIcon { get; set; }

/// <summary>
/// Gets or sets the icon to be displayed in the left, distinguishing different applications
/// </summary>
[Parameter]
public Type ApplicationIcon { get; set; }

/// <summary>
/// Gets or sets the action to be executed when the tab is clicked
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions COMETwebapp/Components/Tabs/TabsPanelComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -30,12 +31,14 @@
@foreach (var tab in this.Tabs)
{
<TabComponent Text="@(GetTabText(tab.ObjectOfInterest))"
Caption="@(this.GetCaptionText(tab.ObjectOfInterest))"
Icon="typeof(FeatherX)"
CustomOptionIcon="typeof(FeatherCopy)"
OnClick="@(() => this.OnTabClick.InvokeAsync((tab, this.Handler)))"
OnIconClick="@(() => this.OnRemoveTabClick.InvokeAsync(tab))"
OnCustomOptionIconClick="@(() => this.OnCreateTabForModel.InvokeAsync(tab))"
IsCurrent="@(tab == this.Handler.CurrentTab)"
ApplicationIcon="@(Applications.ExistingApplications.OfType<TabbedApplication>().First(x => x.ComponentType == tab.ComponentType).IconType)"
@key="tab"/>
}

Expand Down
39 changes: 39 additions & 0 deletions COMETwebapp/Components/Tabs/TabsPanelComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,6 +97,12 @@ public partial class TabsPanelComponent : DisposableComponent
[Parameter]
public bool IsSidePanelAvailable { get; set; }

/// <summary>
/// Gets or sets the <see cref="ISessionService" />
/// </summary>
[Inject]
public ISessionService SessionService { get; set; }

/// <summary>
/// Gets the tab text for the given object of interest
/// </summary>
Expand All @@ -109,6 +118,36 @@ private static string GetTabText(object objectOfInterest)
};
}

/// <summary>
/// Gets the tab caption text for the given object of interest
/// </summary>
/// <param name="objectOfInterest">The object of interest to get its tab caption text</param>
/// <returns>The tab caption</returns>
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();
}

/// <summary>
/// Adds a new side panel to the tabs page
/// </summary>
Expand Down
Loading