Skip to content

Commit

Permalink
caption updated and icon added
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Jul 18, 2024
1 parent e771c1d commit 52e0356
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
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

0 comments on commit 52e0356

Please sign in to comment.