Skip to content

Commit

Permalink
finished implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Apr 29, 2024
1 parent 9d8a231 commit a6098a9
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace COMET.Web.Common.Components.ParameterTypeEditors
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Extensions;
using COMET.Web.Common.ViewModels.Components.ParameterEditors;

using DevExpress.Blazor;
Expand Down Expand Up @@ -70,7 +71,7 @@ protected override void OnParametersSet()

this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsReadOnly,
x => x.ViewModel.ValueArray)
.Subscribe(_ => this.StateHasChanged()));
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IParameterTypeEditorSelectorViewModel.cs" company="RHEA System S.A.">
// Copyright (c) 2023-2024 RHEA System S.A.
// <copyright file="IParameterTypeEditorSelectorViewModel.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, Nabil Abbar
// 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 RHEA 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.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 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.
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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>
// --------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -47,10 +46,15 @@ public interface IParameterTypeEditorSelectorViewModel
EventCallback<(IValueSet, int)> ParameterValueChanged { get; set; }

/// <summary>
/// Gets the <see cref="MeasurementScale"/> to use
/// Gets the <see cref="MeasurementScale" /> to use
/// </summary>
MeasurementScale Scale { get; set; }

/// <summary>
/// Gets the value set of this <see cref="ParameterType" />
/// </summary>
IValueSet ValueSet { get; }

/// <summary>
/// Creates a view model for the corresponding editor
/// </summary>
Expand All @@ -65,7 +69,7 @@ public interface IParameterTypeEditorSelectorViewModel
void UpdateSwitchKind(ParameterSwitchKind switchValue);

/// <summary>
/// Updates the associated <see cref="IParameterEditorBaseViewModel{T}"/> properties
/// Updates the associated <see cref="IParameterEditorBaseViewModel{T}" /> properties
/// </summary>
/// <param name="readOnly">The readonly state</param>
void UpdateProperties(bool readOnly);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterTypeEditorSelectorViewModel.cs" company="RHEA System S.A.">
// Copyright (c) 2023-2024 RHEA System S.A.
// <copyright file="ParameterTypeEditorSelectorViewModel.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, Nabil Abbar
// 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 RHEA 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.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 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.
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 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>
// --------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -92,7 +91,7 @@ public ParameterTypeEditorSelectorViewModel(ParameterType parameterType, IValueS
/// <summary>
/// Gets the index of the value changed in the value sets
/// </summary>
public int ValueArrayIndex { get; }
public int ValueArrayIndex { get; private set; }

/// <summary>
/// Gets or sets the value set of this <see cref="ParameterType" />
Expand Down Expand Up @@ -136,7 +135,7 @@ public IParameterEditorBaseViewModel<T> CreateParameterEditorViewModel<T>() wher
};

var parameterViewModel = (this.haveValueSetViewModel as IParameterEditorBaseViewModel<T>)!;
parameterViewModel.ParameterValueChanged = this.ParameterValueChanged;
parameterViewModel.ParameterValueChanged = new EventCallbackFactory().Create<(IValueSet, int)>(this, this.OnParameterValueChange);

if (this.preSetSwitchKind.HasValue)
{
Expand Down Expand Up @@ -175,5 +174,18 @@ private void InitializesProperties(bool readOnly)
{
this.isReadOnly = readOnly;
}

/// <summary>
/// Method executed when the parameter value has changed
/// </summary>
/// <param name="callbackValues">The callback event values</param>
/// <returns>A <see cref="Task" /></returns>
private async Task OnParameterValueChange((IValueSet, int) callbackValues)
{
this.ValueSet = callbackValues.Item1;
this.ValueArrayIndex = callbackValues.Item2;

await this.ParameterValueChanged.InvokeAsync(callbackValues);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,75 @@ Copyright (c) 2024 Starion Group S.A.
@inherits DisposableComponent

<DxButton Id="openBatchParameterEditorButton"
Click="(() => this.ViewModel.IsVisible = true)"
Click="(this.ViewModel.OpenPopup)"
Text="Batch Update"
SizeMode="SizeMode.Medium"/>

<DxPopup @bind-Visible="@(this.ViewModel.IsVisible)"
HeaderText="Batch Update"
Width="70vw">
Width="60vw">
<div class="px-3">
<ParameterTypeSelector ViewModel="this.ViewModel.ParameterTypeSelectorViewModel"
DisplayText="Select a parameter type:"/>

<ParameterTypeSelector ViewModel="this.ViewModel.ParameterTypeSelectorViewModel"
DisplayText="Select a parameter type:"/>

<OptionSelector ViewModel="this.ViewModel.OptionSelectorViewModel"/>
@if (this.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType != null)
{
<div class="row pt-2">
<div class="col">
<OptionSelector ViewModel="this.ViewModel.OptionSelectorViewModel"/>
</div>
<div class="col">
<FiniteStateSelector ViewModel="this.ViewModel.FiniteStateSelectorViewModel"/>
</div>
</div>

@if (this.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType != null)
{
<div class="pt-3"></div>
<h6>Select a value:</h6>
<ParameterTypeEditorSelector BindValueMode="BindValueMode.OnDelayedInput"
IsOnEditMode="false"
ViewModel="@(this.ViewModel.ParameterTypeEditorSelectorViewModel)"/>
}

<DxGrid Data="@this.ViewModel.Rows.Items"
ShowAllRows="true">
<Columns>
<DxGridSelectionColumn Width="100px" />
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ElementName)" GroupIndex="0" GroupInterval="GridColumnGroupInterval.Value" Caption="@("Element Name")" AllowSort="true"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ParameterName)" Caption="@("Parameter")" AllowGroup="false" AllowSort="true"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.OptionName)" Caption="@("Option")" AllowGroup="false" AllowSort="true"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ActualFiniteStateName)" Caption="@("State")" AllowGroup="false" AllowSort="true" />
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.PublishedValue)" Caption="@("Published Value")" AllowGroup="false"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ActualValue)" Caption="@("Value")" AllowGroup="false"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ModelCode)" Caption="@("Model Code")" AllowGroup="false" AllowSort="true" />
<div class="row pt-3">
<h6>Select a value:</h6>
<ParameterTypeEditorSelector BindValueMode="BindValueMode.OnDelayedInput"
IsOnEditMode="false"
ViewModel="@(this.ViewModel.ParameterTypeEditorSelectorViewModel)"/>
</div>

</Columns>
</DxGrid>
<DxGrid @ref="this.Grid"
Data="@this.ViewModel.Rows.Items"
ShowAllRows="true"
SelectAllCheckboxMode="GridSelectAllCheckboxMode.AllPages"
@bind-SelectedDataItems="@(this.ViewModel.SelectedValueSetsRowsToUpdate)"
CssClass="mt-3">
<Columns>
<DxGridSelectionColumn Width="100px" AllowSelectAll="true" />
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ElementName)" GroupIndex="0" GroupInterval="GridColumnGroupInterval.Value" Caption="@("Element Name")" AllowSort="true" />
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ParameterName)" Caption="@("Parameter")" AllowGroup="false" AllowSort="true"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.OptionName)" Caption="@("Option")" AllowGroup="false" AllowSort="true"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ActualFiniteStateName)" Caption="@("State")" AllowGroup="false" AllowSort="true" />
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.PublishedValue)" Caption="@("Published Value")" AllowGroup="false"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ActualValue)" Caption="@("Value")" AllowGroup="false"/>
<DxGridDataColumn FieldName="@nameof(ParameterValueSetBaseRowViewModel.ModelCode)" Caption="@("Model Code")" AllowGroup="false" AllowSort="true" />
</Columns>

<DataColumnGroupRowTemplate Context="context">
<DxCheckBox style="margin-left: 7px; margin-right: 4px;"
AllowIndeterminateStateByClick="false"
Checked="this.GetGroupCheckBoxChecked(context)"
CheckedChanged="(bool? value) => this.GroupCheckBox_CheckedChanged(value, context)">
@context.DisplayText
</DxCheckBox>
</DataColumnGroupRowTemplate>
</DxGrid>
}

<div class="pt-3"></div>
<div class="dxbl-grid-edit-form-buttons">
<DxButton Id="okButton"
Text="Apply Changes"
Click="(() => this.ViewModel.ConfirmCancelPopupViewModel.IsVisible = true)"
Enabled="@this.IsApplyButtonEnabled"/>
<div class="pt-3"></div>
<div class="dxbl-grid-edit-form-buttons">
<DxButton Id="okButton"
Text="Apply Changes"
Click="(() => this.ViewModel.ConfirmCancelPopupViewModel.IsVisible = true)"
Enabled="@this.IsApplyButtonEnabled"/>

<DxButton Id="closeButton"
Text="Close"
Click="(() => this.ViewModel.IsVisible = false)"
RenderStyle="ButtonRenderStyle.Secondary"/>
<DxButton Id="closeButton"
Text="Close"
Click="(() => this.ViewModel.IsVisible = false)"
RenderStyle="ButtonRenderStyle.Secondary"/>
</div>
</div>

<ConfirmCancelPopup ViewModel="@(this.ViewModel.ConfirmCancelPopupViewModel)"></ConfirmCancelPopup>
</DxPopup>
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ namespace COMETwebapp.Components.ParameterEditor.BatchParameterEditor
{
using COMET.Web.Common.Extensions;

using COMETwebapp.ViewModels.Components.ModelDashboard.ParameterValues;
using COMETwebapp.ViewModels.Components.ParameterEditor.BatchParameterEditor;

using DevExpress.Blazor;

using Microsoft.AspNetCore.Components;

using ReactiveUI;
Expand All @@ -43,10 +46,15 @@ public partial class BatchParameterEditor
[Parameter]
public IBatchParameterEditorViewModel ViewModel { get; set; }

/// <summary>
/// Gets or sets the grid control that is being customized.
/// </summary>
protected IGrid Grid { get; set; }

/// <summary>
/// Gets the condition to check if the apply button should be enabled
/// </summary>
private bool IsApplyButtonEnabled => this.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType != null;
private bool IsApplyButtonEnabled => this.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType != null && this.ViewModel.SelectedValueSetsRowsToUpdate.Count > 0;

/// <summary>
/// Method invoked when the component is ready to start, having received its
Expand All @@ -55,7 +63,57 @@ public partial class BatchParameterEditor
protected override void OnInitialized()
{
base.OnInitialized();
this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType).SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));

this.Disposables.Add(this.WhenAnyValue(
x => x.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType,
x => x.ViewModel.OptionSelectorViewModel.SelectedOption,
x => x.ViewModel.FiniteStateSelectorViewModel.SelectedActualFiniteState)
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
}

/// <summary>
/// Gets the group check value based on the given <see cref="ViewModel"/>
/// </summary>
/// <param name="context">The column group context</param>
/// <returns>The check box value</returns>
private bool? GetGroupCheckBoxChecked(GridDataColumnGroupRowTemplateContext context)
{
var groupedRows = this.GetGroupDataItems(context).OfType<ParameterValueSetBaseRowViewModel>().ToList();
var numberOfSelectedGroupedRows = groupedRows.Count(this.Grid.IsDataItemSelected);

if (numberOfSelectedGroupedRows == groupedRows.Count)
{
return true;
}

if (numberOfSelectedGroupedRows == 0)
{
return false;
}

return null;
}

/// <summary>
/// Method executed when the checkbox value has changed for a given group
/// </summary>
/// <param name="value">The new checkbox value</param>
/// <param name="context">The group context</param>
private void GroupCheckBox_CheckedChanged(bool? value, GridDataColumnGroupRowTemplateContext context)
{
var items = this.GetGroupDataItems(context);
context.Grid.SelectDataItems(items, value != null && value.Value);
}

/// <summary>
/// Gets the <see cref="ParameterValueSetBaseRowViewModel"/>s from the selected element name group
/// </summary>
/// <param name="context">The <see cref="GridDataColumnGroupRowTemplateContext"/></param>
/// <returns>A collection of data items contained in the given group</returns>
private IEnumerable<object> GetGroupDataItems(GridDataColumnGroupRowTemplateContext context)
{
var groupElementName = (string)this.Grid.GetRowValue(context.VisibleIndex, nameof(ParameterValueSetBaseRowViewModel.ElementName));
return this.ViewModel.Rows.Items.Where(x => x.ElementName == groupElementName);
}
}
}
Loading

0 comments on commit a6098a9

Please sign in to comment.