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 5 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 @@ -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.ViewModel.Rows.Items.Order(this.comparer)"
SelectionMode="GridSelectionMode.Single"
AllowSelectRowByClick="false"
ShowFilterRow="true"
Expand Down
39 changes: 12 additions & 27 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 @@ -24,18 +24,13 @@

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;

using DevExpress.Blazor;

using DynamicData;

using Microsoft.AspNetCore.Components;

using ReactiveUI;
Expand All @@ -53,12 +48,7 @@ public partial class ParameterTable
/// <summary>
/// The <see cref="ParameterBaseRowViewModelComparer" />
/// </summary>
private ParameterBaseRowViewModelComparer comparer = new();

/// <summary>
/// The sorted collection of <see cref="ParameterBaseRowViewModel" />
/// </summary>
private ReadOnlyObservableCollection<ParameterBaseRowViewModel> sortedCollection;
joao4all marked this conversation as resolved.
Show resolved Hide resolved
private readonly ParameterBaseRowViewModelComparer comparer = new();

/// <summary>
/// Gets or sets the <see cref="IParameterTableViewModel" />
Expand All @@ -80,20 +70,15 @@ protected override void OnInitialized()
base.OnInitialized();

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

this.Disposables.Add(this.ViewModel.Rows.Connect()
.Sort(this.comparer)
.Bind(out this.sortedCollection)
.Subscribe(_ => this.InvokeAsync(this.StateHasChanged)));
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));

this.closeEditor = new EventCallbackFactory().Create(this, () => { this.ViewModel.IsOnEditMode = false; });
}

/// <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 All @@ -109,7 +94,7 @@ private void OnCustomizeElement(GridCustomizeElementEventArgs e)
if (e.ElementType == GridElementType.GroupCell)
{
var elementBaseName = (string)e.Grid.GetRowValue(e.VisibleIndex, nameof(ParameterBaseRowViewModel.ElementBaseName));
var isPublishableParameterInGroup = this.sortedCollection.Any(x => x.IsPublishable && x.ElementBaseName == elementBaseName);
var isPublishableParameterInGroup = this.ViewModel.Rows.Items.Any(x => x.IsPublishable && x.ElementBaseName == elementBaseName);

if (isPublishableParameterInGroup)
{
Expand Down
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