Skip to content

Commit

Permalink
reference data page is now tabbed
Browse files Browse the repository at this point in the history
TODO
- Make server admin page tabbed
- Unit tests
  • Loading branch information
joao4all committed Jul 19, 2024
1 parent 982d482 commit 3704a4b
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 43 deletions.
42 changes: 42 additions & 0 deletions COMETwebapp/Components/ReferenceData/ReferenceDataBody.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!------------------------------------------------------------------------------
// Copyright (c) 2023-2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, João Rua
//
// This file is part of CDP4-COMET WEB Community Edition
// The CDP4-COMET WEB Community Edition is the Starion Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The CDP4-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 CDP4-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 http://www.gnu.org/licenses/.
------------------------------------------------------------------------------->
@inherits ApplicationBase<COMETwebapp.ViewModels.Components.ReferenceData.IReferenceDataBodyViewModel>

<LoadingComponent IsVisible="@(this.ViewModel.IsLoading)">
<DxToolbar ItemClick="@(this.OnItemClick)">
<Items>
@foreach (var mappedValue in this.mapOfComponentsAndNames)
{
<DxToolbarItem @key="@(mappedValue.Value)"
Name="@(mappedValue.Value)"
Text="@(mappedValue.Value)"
Tooltip="@(mappedValue.Value)"
RenderStyle="@(mappedValue.Key == this.SelectedComponent ? ButtonRenderStyle.Primary : ButtonRenderStyle.Secondary)"/>
}
</Items>
</DxToolbar>

@if (this.SelectedComponent != null)
{
<DynamicComponent Type="@(this.SelectedComponent)"/>
}
</LoadingComponent>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ReferenceDataPage.razor.cs" company="Starion Group S.A.">
// <copyright file="ReferenceDataBody.razor.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
Expand All @@ -22,7 +22,7 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Pages.ReferenceData
namespace COMETwebapp.Components.ReferenceData
{
using COMETwebapp.Components.ReferenceData.Categories;
using COMETwebapp.Components.ReferenceData.MeasurementScales;
Expand All @@ -32,9 +32,9 @@ namespace COMETwebapp.Pages.ReferenceData
using DevExpress.Blazor;

/// <summary>
/// Support class for the <see cref="ReferenceDataPage" />
/// Core component for the Reference Data body application
/// </summary>
public partial class ReferenceDataPage
public partial class ReferenceDataBody
{
/// <summary>
/// A map with all the available components and their names
Expand Down Expand Up @@ -70,5 +70,13 @@ private void OnItemClick(ToolbarItemClickEventArgs e)
{
this.SelectedComponent = this.mapOfComponentsAndNames.First(x => x.Value == e.ItemName).Key;
}

/// <summary>
/// Initializes values of the component and of the ViewModel based on parameters provided from the url
/// </summary>
/// <param name="parameters">A <see cref="Dictionary{TKey,TValue}" /> for parameters</param>
protected override void InitializeValues(Dictionary<string, string> parameters)
{
}
}
}
4 changes: 2 additions & 2 deletions COMETwebapp/Components/Tabs/TabsPanelComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
<div class="d-flex gap-2">
@foreach (var tab in this.Tabs)
{
<TabComponent Text="@(GetTabText(tab.ObjectOfInterest))"
<TabComponent Text="@(GetTabText(tab))"
Caption="@(this.GetCaptionText(tab.ObjectOfInterest))"
Icon="typeof(FeatherX)"
CustomOptionIcon="typeof(FeatherCopy)"
CustomOptionIcon="@(typeof(FeatherCopy))"
OnClick="@(() => this.OnTabClick.InvokeAsync((tab, this.Handler)))"
OnIconClick="@(() => this.OnRemoveTabClick.InvokeAsync(tab))"
OnCustomOptionIconClick="@(() => this.OnCreateTabForModel.InvokeAsync(tab))"
Expand Down
13 changes: 9 additions & 4 deletions COMETwebapp/Components/Tabs/TabsPanelComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public partial class TabsPanelComponent : DisposableComponent
/// <summary>
/// Gets the tab text for the given object of interest
/// </summary>
/// <param name="objectOfInterest">The object of interest to get its tab text</param>
/// <param name="tab">Thetab to get its text</param>
/// <returns>The tab text</returns>
private static string GetTabText(object objectOfInterest)
private static string GetTabText(TabbedApplicationInformation tab)
{
return objectOfInterest switch
return tab.ObjectOfInterest switch
{
Iteration iteration => iteration.QueryName(),
EngineeringModel engineeringModel => engineeringModel.EngineeringModelSetup.Name,
_ => string.Empty
_ => Applications.ExistingApplications.OfType<TabbedApplication>().First(x => x.ComponentType == tab.ComponentType).Name
};
}

Expand Down Expand Up @@ -142,6 +142,11 @@ private string GetCaptionText(object objectOfInterest)

modelName.Append(" - ");

if (iterationOfInterest == null)
{
return modelName.ToString();
}

var domainOfExpertiseShortName = this.SessionService.GetDomainOfExpertise(iterationOfInterest).ShortName;
modelName.Append(domainOfExpertiseShortName);

Expand Down
2 changes: 2 additions & 0 deletions COMETwebapp/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace COMETwebapp.Extensions
using COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FileRevisionHandler;
using COMETwebapp.ViewModels.Components.EngineeringModel.FileStore.FolderHandler;
using COMETwebapp.ViewModels.Components.ParameterEditor.BatchParameterEditor;
using COMETwebapp.ViewModels.Components.ReferenceData;
using COMETwebapp.ViewModels.Pages;

/// <summary>
Expand Down Expand Up @@ -124,6 +125,7 @@ public static void RegisterViewModels(this IServiceCollection serviceCollection)
serviceCollection.AddTransient<IBatchParameterEditorViewModel, BatchParameterEditorViewModel>();
serviceCollection.AddScoped<ITabsViewModel, TabsViewModel>();
serviceCollection.AddTransient<IOpenTabViewModel, OpenTabViewModel>();
serviceCollection.AddTransient<IReferenceDataBodyViewModel, ReferenceDataBodyViewModel>();
}
}
}
6 changes: 4 additions & 2 deletions COMETwebapp/Model/Applications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace COMETwebapp.Model
using COMETwebapp.Components.ModelDashboard;
using COMETwebapp.Components.ModelEditor;
using COMETwebapp.Components.ParameterEditor;
using COMETwebapp.Components.ReferenceData;
using COMETwebapp.Components.SubscriptionDashboard;
using COMETwebapp.Components.SystemRepresentation;
using COMETwebapp.Components.Viewer;
Expand Down Expand Up @@ -131,13 +132,14 @@ private static List<Application> InitializesApplications()
ComponentType = typeof(ViewerBody)
},

new Application
new TabbedApplication
{
Name = "Reference Data",
Color = "#fc3a1aad",
IconType = typeof(FeatherFile),
Description = "Visualize reference data",
Url = WebAppConstantValues.ReferenceDataPage
Url = WebAppConstantValues.ReferenceDataPage,
ComponentType = typeof(ReferenceDataBody)
},

new Application
Expand Down
18 changes: 1 addition & 17 deletions COMETwebapp/Pages/ReferenceData/ReferenceDataPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ Copyright (c) 2023-2024 Starion Group S.A.

<ApplicationTemplate>
<Body>
<DxToolbar ItemClick="@(this.OnItemClick)">
<Items>
@foreach (var mappedValue in this.mapOfComponentsAndNames)
{
<DxToolbarItem @key="@(mappedValue.Value)"
Name="@(mappedValue.Value)"
Text="@(mappedValue.Value)"
Tooltip="@(mappedValue.Value)"
RenderStyle="@(mappedValue.Key == this.SelectedComponent ? ButtonRenderStyle.Primary : ButtonRenderStyle.Secondary)"/>
}
</Items>
</DxToolbar>

@if (this.SelectedComponent != null)
{
<DynamicComponent Type="@(this.SelectedComponent)"/>
}
<ReferenceDataBody/>
</Body>
</ApplicationTemplate>
8 changes: 4 additions & 4 deletions COMETwebapp/Shared/SideBarEntry/ApplicationsSideBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
Model
</div>

@foreach (var applicationEntry in this.RegistrationService.RegisteredApplications.OfType<TabbedApplication>().Where(x => !x.IsDisabled))
@foreach (var applicationEntry in this.GetModelApplications())
{
<SideBarItem Text="@applicationEntry.Name"
OnClick="@(() => this.NavigateToTabbedApplication(applicationEntry))"
OnClick="@(() => this.NavigateToApplication(applicationEntry))"
CssClass="@(this.IsCurrentApplication(applicationEntry) ? "selected-application-item" : "")"
Icon="@(applicationEntry.IconType)"
Enabled="@(this.IsApplicationEnabled(applicationEntry))"/>
Expand All @@ -40,10 +40,10 @@
General
</div>

@foreach (var applicationEntry in this.RegistrationService.RegisteredApplications.Where(x => x is not TabbedApplication && !x.IsDisabled && x.Url != WebAppConstantValues.TabsPage))
@foreach (var applicationEntry in this.GetGeneralApplications())
{
<SideBarItem Text="@applicationEntry.Name"
OnClick="@(() => this.NavigationManager.NavigateTo(applicationEntry.Url))"
OnClick="@(() => this.NavigateToApplication(applicationEntry))"
CssClass="@(this.IsCurrentApplication(applicationEntry) ? "selected-application-item" : "")"
Icon="@(applicationEntry.IconType)"
Enabled="@(this.IsApplicationEnabled(applicationEntry))" />
Expand Down
48 changes: 44 additions & 4 deletions COMETwebapp/Shared/SideBarEntry/ApplicationsSideBar.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,18 @@ private void OnLocationChanged(object sender, LocationChangedEventArgs e)
/// <summary>
/// Navigates to the selected tabbed application
/// </summary>
/// <param name="application">The <see cref="TabbedApplication" /> to navigate to</param>
private void NavigateToTabbedApplication(TabbedApplication application)
/// <param name="application">The <see cref="Application" /> to navigate to</param>
private void NavigateToApplication(Application application)
{
this.TabsViewModel.SelectedApplication = application;
this.NavigationManager.NavigateTo(WebAppConstantValues.TabsPage);
if (application is TabbedApplication tabbedApplication)
{
this.TabsViewModel.SelectedApplication = tabbedApplication;
this.NavigationManager.NavigateTo(WebAppConstantValues.TabsPage);
}
else
{
this.NavigationManager.NavigateTo(application.Url);
}
}

/// <summary>
Expand Down Expand Up @@ -154,5 +161,38 @@ private bool IsApplicationEnabled(Application application)

return this.CurrentApplication != application;
}

/// <summary>
/// Gets the model <see cref="TabbedApplication" />s
/// </summary>
/// <returns>A collection of applications</returns>
private IEnumerable<TabbedApplication> GetModelApplications()
{
return this.RegistrationService.RegisteredApplications.OfType<TabbedApplication>().Where(x => !x.IsDisabled && x.ThingTypeOfInterest != null);
}

/// <summary>
/// Gets the general <see cref="Application" />s
/// </summary>
/// <returns>A collection of applications</returns>
private IEnumerable<Application> GetGeneralApplications()
{
return this.RegistrationService.RegisteredApplications.Where(x => !x.IsDisabled && x.Url != WebAppConstantValues.TabsPage && !ApplicationHasThingTypeOfInterest(x));
}

/// <summary>
/// Checks if an application has a thing type of interest
/// </summary>
/// <param name="application">The application to check</param>
/// <returns>The value to check if the application has a thing type of interest</returns>
private static bool ApplicationHasThingTypeOfInterest(Application application)
{
if (application is not TabbedApplication tabbedApplication)
{
return false;
}

return tabbedApplication.ThingTypeOfInterest != null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public async Task OpenTab(TabPanelInformation panel)
var result = new Result<Iteration>();
var isIteration = this.SelectedApplication?.ThingTypeOfInterest == typeof(Iteration);

if (this.SelectedApplication?.ThingTypeOfInterest is null)
{
this.tabsViewModel.CreateNewTab(this.SelectedApplication, Guid.Empty, panel);
return;
}

if (!this.IsCurrentModelOpened)
{
result = await base.OpenSession();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IReferenceDataBodyViewModel.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group 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 <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.ViewModels.Components.ReferenceData
{
using COMET.Web.Common.ViewModels.Components.Applications;

/// <summary>
/// View Model that handle the logic for the Reference data body application
/// </summary>
public interface IReferenceDataBodyViewModel : IApplicationBaseViewModel
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ReferenceDataBodyViewModel.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group 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 <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.ViewModels.Components.ReferenceData
{
using CDP4Dal;

using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.ViewModels.Components.Applications;

/// <summary>
/// View Model that handle the logic for the Reference data body application
/// </summary>
public class ReferenceDataBodyViewModel : ApplicationBaseViewModel, IReferenceDataBodyViewModel
{
/// <summary>
/// Initializes a new instance of the <see cref="ReferenceDataBodyViewModel" /> class.
/// </summary>
/// <param name="sessionService">The <see cref="ISessionService" /></param>
/// <param name="messageBus">The <see cref="ICDPMessageBus" /></param>
public ReferenceDataBodyViewModel(ISessionService sessionService, ICDPMessageBus messageBus) : base(sessionService, messageBus)
{
}

/// <summary>
/// Handles the refresh of the current <see cref="ISession" />
/// </summary>
/// <returns>A <see cref="Task" /></returns>
protected override Task OnSessionRefreshed()
{
return Task.CompletedTask;
}
}
}
Loading

0 comments on commit 3704a4b

Please sign in to comment.