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

Fixes #689 2 tabs of same view: Filtering is identical #712

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -20,5 +20,5 @@
// limitations under the License.
------------------------------------------------------------------------------->
<CascadingValue Value="this.CurrentThing">
<DynamicComponent Type="this.ApplicationBaseType" Parameters="this.parameters"/>
<DynamicComponent Type="this.ApplicationBaseType" Parameters="this.parameters" @key="this.Id"/>
</CascadingValue>
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public partial class DynamicApplicationBase
[Parameter]
public Thing CurrentThing { get; set; }

/// <summary>
/// Gets or sets the component's id
/// </summary>
[Parameter]
public object Id { get; set; }

/// <summary>
/// Gets the <see cref="Dictionary{TKey,TValue}"/> of parameters that have to be passed to the <see cref="DynamicComponent"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ParameterEditorTestFixture
private Mock<ISession> session;
private Iteration firstIteration;
private Iteration secondIteration;
private ICDPMessageBus messageBus;
private CDPMessageBus messageBus;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -123,21 +123,31 @@ public void Setup()
mockConfigurationService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration());
this.messageBus = new CDPMessageBus();

var parameterTableViewModel = new Mock<IParameterTableViewModel>();
parameterTableViewModel.Setup(x => x.Rows).Returns(new SourceList<ParameterBaseRowViewModel>());

var parameterEditorBodyViewModel = new Mock<IParameterEditorBodyViewModel>();
parameterEditorBodyViewModel.Setup(x => x.OptionSelector).Returns(new Mock<IOptionSelectorViewModel>().Object);
parameterEditorBodyViewModel.Setup(x => x.BatchParameterEditorViewModel).Returns(new Mock<IBatchParameterEditorViewModel>().Object);
parameterEditorBodyViewModel.Setup(x => x.ParameterTypeSelector).Returns(new Mock<IParameterTypeSelectorViewModel>().Object);
parameterEditorBodyViewModel.Setup(x => x.ElementSelector).Returns(new Mock<IElementBaseSelectorViewModel>().Object);
parameterEditorBodyViewModel.Setup(x => x.ParameterTableViewModel).Returns(parameterTableViewModel.Object);

var configurationService = new Mock<IStringTableService>();
configurationService.Setup(x => x.GetText(It.IsAny<string>())).Returns("something");

this.context.ConfigureDevExpressBlazor();
this.context.Services.AddSingleton(this.viewModel);
this.context.Services.AddSingleton(this.sessionService.Object);
this.context.Services.AddSingleton(mockConfigurationService.Object);
this.context.Services.AddSingleton(parameterEditorBodyViewModel.Object);
this.context.Services.AddSingleton(parameterTableViewModel.Object);
this.context.Services.AddSingleton(configurationService.Object);
this.context.Services.AddSingleton<ICDPMessageBus>(this.messageBus);
this.context.Services.AddSingleton<IOpenModelViewModel, OpenModelViewModel>();
this.context.Services.AddSingleton<IParameterEditorBodyViewModel, ParameterEditorBodyViewModel>();
this.context.Services.AddSingleton<IBatchParameterEditorViewModel, BatchParameterEditorViewModel>();
this.context.Services.AddSingleton<ISubscriptionService, SubscriptionService>();
this.context.Services.AddSingleton<IParameterTableViewModel, ParameterTableViewModel>();
this.context.Services.AddSingleton<INotificationService, NotificationService>();
this.context.Services.AddSingleton(mockConfigurationService.Object);
this.context.Services.AddSingleton(this.messageBus);

var configurationService = new Mock<IStringTableService>();
configurationService.Setup(x => x.GetText(It.IsAny<string>())).Returns("something");
this.context.Services.AddSingleton(configurationService.Object);
}

[TearDown]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public async Task VerifyApplyFilters()
this.viewModel.ElementSelector.SelectedElementBase = this.viewModel.ElementSelector.AvailableElements.First();
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.tableViewModel.Verify(x => x.ApplyFilters(this.iteration.DefaultOption, this.viewModel.ElementSelector.SelectedElementBase, null, true), Times.Once);
this.tableViewModel.Verify(x => x.ApplyFilters(this.iteration.DefaultOption, this.viewModel.ElementSelector.SelectedElementBase, null, true), Times.AtLeastOnce);

this.viewModel.ElementSelector.SelectedElementBase = null;
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Copyright (c) 2024 Starion Group S.A.

@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase<COMETwebapp.ViewModels.Components.ParameterEditor.IParameterEditorBodyViewModel>

<LoadingComponent IsVisible="@(this.ViewModel.IsLoading || this.ViewModel.BatchParameterEditorViewModel.IsLoading)">
<LoadingComponent IsVisible="@(this.ViewModel.IsLoading)">
<div id="@WebAppConstantValues.ParameterEditorPage.QueryPageBodyName()" class="container-fluid">
<div class="row ">
<div class="col">
Expand Down Expand Up @@ -60,4 +60,4 @@ Copyright (c) 2024 Starion Group S.A.
<ParameterTable ViewModel="this.ViewModel.ParameterTableViewModel"/>
</div>
</div>
</LoadingComponent>
</LoadingComponent>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected override void OnViewModelAssigned()
{
base.OnViewModelAssigned();

this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.OptionSelector.SelectedOption,
this.Disposables.Add(this.WhenAnyValue(
x => x.ViewModel.OptionSelector.SelectedOption,
x => x.ViewModel.ParameterTypeSelector.SelectedParameterType,
x => x.ViewModel.ElementSelector.SelectedElementBase,
x => x.ViewModel.IsOwnedParameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<DxGrid @ref="this.Grid"
CssClass="default-grid"
ShowAllRows="true"
Data="@this.sortedCollection"
Data="@(this.sortedCollection)"
SelectionMode="GridSelectionMode.Single"
AllowSelectRowByClick="false"
ShowFilterRow="true"
Expand Down
30 changes: 15 additions & 15 deletions COMETwebapp/Components/ParameterEditor/ParameterTable.razor.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterTable.cs" company="Starion Group S.A.">
// Copyright (c) 2023-2024 Starion Group S.A.
// <copyright file="ParameterTable.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
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, 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.
// 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 CDP4-COMET WEB Community Edition is free software; you can redistribute it and/or
// 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 CDP4-COMET WEB Community Edition is distributed in the hope that it will be useful,
// 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.
Expand All @@ -26,8 +26,7 @@ namespace COMETwebapp.Components.ParameterEditor
{
using System.Collections.ObjectModel;

using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;
using COMET.Web.Common.Extensions;

using COMETwebapp.Comparer;
using COMETwebapp.ViewModels.Components.ParameterEditor;
Expand All @@ -46,14 +45,14 @@ namespace COMETwebapp.Components.ParameterEditor
public partial class ParameterTable
{
/// <summary>
/// <see cref="EventCallback" /> to close the popup editor
/// The <see cref="ParameterBaseRowViewModelComparer" />
/// </summary>
private EventCallback closeEditor;
private readonly ParameterBaseRowViewModelComparer comparer = new();

/// <summary>
/// The <see cref="ParameterBaseRowViewModelComparer" />
/// <see cref="EventCallback" /> to close the popup editor
/// </summary>
private ParameterBaseRowViewModelComparer comparer = new();
private EventCallback closeEditor;

/// <summary>
/// The sorted collection of <see cref="ParameterBaseRowViewModel" />
Expand All @@ -80,9 +79,10 @@ protected override void OnInitialized()
base.OnInitialized();

this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsOnEditMode)
.Subscribe(_ => this.InvokeAsync(this.StateHasChanged)));
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));

this.Disposables.Add(this.ViewModel.Rows.Connect()
.AutoRefresh()
.Sort(this.comparer)
.Bind(out this.sortedCollection)
.Subscribe(_ => this.InvokeAsync(this.StateHasChanged)));
Expand All @@ -93,7 +93,7 @@ protected override void OnInitialized()
/// <summary>
/// Customizes the table rows
/// </summary>
/// <param name="e">The <see cref="GridCustomizeElementEventArgs"/></param>
/// <param name="e">The <see cref="GridCustomizeElementEventArgs" /></param>
private void OnCustomizeElement(GridCustomizeElementEventArgs e)
{
if (e.ElementType == GridElementType.DataRow)
Expand Down
3 changes: 2 additions & 1 deletion COMETwebapp/Components/Tabs/TabsPanelComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
<div class="template-container" id="tabs-page-content">
<DynamicApplicationBase ViewModel="this.Panel.CurrentTab.ApplicationBaseViewModel"
ApplicationBaseType="this.Panel.CurrentTab.ComponentType"
CurrentThing="this.Panel.CurrentTab.ObjectOfInterest as Thing"/>
CurrentThing="this.Panel.CurrentTab.ObjectOfInterest as Thing"
Id="@(this.Panel.CurrentTab.Id)"/>
</div>
}
</div>
6 changes: 6 additions & 0 deletions COMETwebapp/Model/TabbedApplicationInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public TabbedApplicationInformation(IApplicationBaseViewModel applicationBaseVie
this.ApplicationBaseViewModel = applicationBaseViewModel;
this.ComponentType = componentType;
this.ObjectOfInterest = objectOfInterest;
this.Id = Guid.NewGuid();
}

/// <summary>
Expand All @@ -58,5 +59,10 @@ public TabbedApplicationInformation(IApplicationBaseViewModel applicationBaseVie
/// Gets the object of interest
/// </summary>
public object ObjectOfInterest { get; }

/// <summary>
/// Gets the tab's id
/// </summary>
public Guid Id { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ public ParameterEditorBodyViewModel(ISessionService sessionService, ISubscriptio
this.ParameterTableViewModel = parameterTableView;
this.BatchParameterEditorViewModel = batchParameterEditorViewModel;

this.Disposables.Add(this.WhenAnyValue(x => x.ElementSelector.SelectedElementBase,
this.Disposables.Add(this.WhenAnyValue(
x => x.ElementSelector.SelectedElementBase,
x => x.OptionSelector.SelectedOption,
x => x.ParameterTypeSelector.SelectedParameterType,
x => x.IsOwnedParameters).SubscribeAsync(_ => this.ApplyFilters()));
x => x.IsOwnedParameters)
.SubscribeAsync(_ => this.ApplyFilters()));

this.InitializeSubscriptions(ObjectChangedTypesOfInterest);
this.RegisterViewModelsWithReusableRows([this.ParameterTableViewModel]);
Expand Down Expand Up @@ -129,7 +131,7 @@ public bool IsOwnedParameters
/// <returns>A <see cref="Task" /></returns>
protected override async Task OnSessionRefreshed()
{
if (!this.AddedThings.Any() && !this.DeletedThings.Any() && !this.UpdatedThings.Any())
if (this.AddedThings.Count == 0 && this.DeletedThings.Count == 0 && this.UpdatedThings.Count == 0)
{
return;
}
Expand Down Expand Up @@ -172,23 +174,20 @@ protected override async Task OnDomainChanged()
protected override async Task OnThingChanged()
{
await base.OnThingChanged();
this.IsOwnedParameters = true;
this.ElementSelector.CurrentIteration = this.CurrentThing;
this.OptionSelector.CurrentIteration = this.CurrentThing;
this.ParameterTypeSelector.CurrentIteration = this.CurrentThing;
this.BatchParameterEditorViewModel.CurrentIteration = this.CurrentThing;
await this.InitializeTable();
}

/// <summary>
/// Initialize the <see cref="IParameterTableViewModel" />
/// </summary>
/// <returns>A <see cref="Task" /></returns>
private async Task InitializeTable()
{
this.IsLoading = true;
await Task.Delay(1);

if (!this.HasSetInitialValuesOnce)
{
this.IsOwnedParameters = true;
this.ElementSelector.CurrentIteration = this.CurrentThing;
this.OptionSelector.CurrentIteration = this.CurrentThing;
this.ParameterTypeSelector.CurrentIteration = this.CurrentThing;
this.BatchParameterEditorViewModel.CurrentIteration = this.CurrentThing;
}

this.ParameterTableViewModel.InitializeViewModel(this.CurrentThing, this.CurrentDomain, this.OptionSelector.SelectedOption);
await this.ApplyFilters();
this.IsLoading = false;
}

Expand Down
Loading