Skip to content

Commit

Permalink
list of available parameters implemented
Browse files Browse the repository at this point in the history
TODO
- finish implementation of value sets selection and update
  • Loading branch information
joao4all committed Apr 26, 2024
1 parent 31dd18e commit 9d8a231
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Copyright (c) 2024 Starion Group S.A.
along with this program. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------->

@using COMETwebapp.ViewModels.Components.ParameterEditor
@using COMETwebapp.ViewModels.Components.ModelDashboard.ParameterValues
@inherits DisposableComponent

<DxButton Id="openBatchParameterEditorButton"
Expand All @@ -28,20 +30,38 @@ Copyright (c) 2024 Starion Group S.A.
SizeMode="SizeMode.Medium"/>

<DxPopup @bind-Visible="@(this.ViewModel.IsVisible)"
HeaderText="Batch Update">
HeaderText="Batch Update"
Width="70vw">

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

<OptionSelector ViewModel="this.ViewModel.OptionSelectorViewModel"/>

@if (this.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType != null)
{
<div class="pt-3"></div>
<h6>Select a value</h6>
<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" />

</Columns>
</DxGrid>

<div class="pt-3"></div>
<div class="dxbl-grid-edit-form-buttons">
<DxButton Id="okButton"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ParameterValueSetBaseRowViewModel
/// <param name="valueSet">The <see cref="ParameterValueSetBase" /></param>
public ParameterValueSetBaseRowViewModel(ParameterValueSetBase valueSet)
{
this.ParameterValueSetBase = valueSet;
this.ElementName = ((ElementBase)valueSet.Container.Container).Name;
var parameter = (ParameterOrOverrideBase)valueSet.Container;
this.ParameterName = parameter.ParameterType.Name;
Expand All @@ -58,6 +59,11 @@ public ParameterValueSetBaseRowViewModel(ParameterValueSetBase valueSet)
this.Scale = parameter.Scale;
}

/// <summary>
/// The <see cref="ParameterValueSetBase" />
/// </summary>
public ParameterValueSetBase ParameterValueSetBase { get; }

/// <summary>
/// The <see cref="MeasurementScale" />
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ namespace COMETwebapp.ViewModels.Components.ParameterEditor.BatchParameterEditor
using COMET.Web.Common.ViewModels.Components.ParameterEditors;
using COMET.Web.Common.ViewModels.Components.Selectors;

using COMETwebapp.ViewModels.Components.ModelDashboard.ParameterValues;

using DynamicData;

using Microsoft.AspNetCore.Components;

using ReactiveUI;

//TODO
// Need to make the user select the value sets available to update for each parameter/element definition, because it depends on the actual state and the option
// Use a grid to display the selection => filters with options and
// Exclude the parameter types SFPT, Array and Compound

/// <summary>
/// ViewModel used to apply batch operations for a parameter
/// </summary>
Expand All @@ -66,6 +75,11 @@ public class BatchParameterEditorViewModel : BelongsToIterationSelectorViewModel
/// </summary>
private readonly ICDPMessageBus messageBus;

/// <summary>
/// Gets the excluded <see cref="ParameterType"/>s for applying the batch updates
/// </summary>
private IEnumerable<ClassKind> excludedParameterTypes = [ClassKind.SampledFunctionParameterType, ClassKind.ArrayParameterType, ClassKind.CompoundParameterType];

/// <summary>
/// Creates a new instance of type <see cref="BatchParameterEditorViewModel" />
/// </summary>
Expand Down Expand Up @@ -119,11 +133,21 @@ public bool IsLoading
/// </summary>
public IParameterTypeSelectorViewModel ParameterTypeSelectorViewModel { get; private set; } = new ParameterTypeSelectorViewModel();

/// <summary>
/// Gets the <see cref="IOptionSelectorViewModel" />
/// </summary>
public IOptionSelectorViewModel OptionSelectorViewModel { get; private set; } = new OptionSelectorViewModel();

/// <summary>
/// Gets the <see cref="IConfirmCancelPopupViewModel" />
/// </summary>
public IConfirmCancelPopupViewModel ConfirmCancelPopupViewModel { get; private set; }

/// <summary>
/// Gets the list of <see cref="ParameterValueSetBaseRowViewModel"/>s
/// </summary>
public SourceList<ParameterValueSetBaseRowViewModel> Rows { get; private set; } = new();

/// <summary>
/// Updates this view model properties
/// </summary>
Expand All @@ -150,17 +174,11 @@ private async Task OnConfirmPopup()
this.IsVisible = false;

this.logger.LogInformation("Applying manual value {value} to all parameters types with iid {iid}", this.SelectedValueSet.Manual, this.ParameterTypeSelectorViewModel.SelectedParameterType.Iid);

var parameters = this.CurrentIteration
.QueryParameterAndOverrideBases()
.Where(x => x.ParameterType.Iid == this.ParameterTypeSelectorViewModel.SelectedParameterType.Iid);

var thingsToUpdate = new List<Thing>();

foreach (var parameter in parameters)
foreach (var parameterValueSet in this.Rows.Items.Select(x => x.ParameterValueSetBase))
{
var valueSet = (ParameterValueSetBase)parameter.ValueSets.First();
var valueSetClone = valueSet.Clone(true);
var valueSetClone = parameterValueSet.Clone(true);
valueSetClone.Manual = this.SelectedValueSet.Manual;
thingsToUpdate.Add(valueSetClone);
}
Expand All @@ -184,6 +202,18 @@ private void OnSelectedParameterTypeChange(ParameterType selectedParameterType)

this.SelectedValueSet = defaultParameterValueSet;

var parameterValueSets = this.CurrentIteration?
.QueryParameterAndOverrideBases()
.Where(x => x.ParameterType.Iid == selectedParameterType.Iid)
.Cast<Parameter>()
.SelectMany(x => x.ValueSet);

this.Rows.Edit(action =>
{
action.Clear();
action.AddRange(parameterValueSets?.Select(x => new ParameterValueSetBaseRowViewModel(x)) ?? Array.Empty<ParameterValueSetBaseRowViewModel>());
});

this.ParameterTypeEditorSelectorViewModel = new ParameterTypeEditorSelectorViewModel(selectedParameterType, defaultParameterValueSet, false, this.messageBus)
{
ParameterValueChanged = new EventCallbackFactory().Create<(IValueSet, int)>(this, callbackValueSet => { this.SelectedValueSet = callbackValueSet.Item1; })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace COMETwebapp.ViewModels.Components.ParameterEditor.BatchParameterEditor
using COMET.Web.Common.ViewModels.Components.ParameterEditors;
using COMET.Web.Common.ViewModels.Components.Selectors;

using COMETwebapp.ViewModels.Components.ModelDashboard.ParameterValues;

using DynamicData;

/// <summary>
/// ViewModel used to apply batch operations for a parameter
/// </summary>
Expand Down Expand Up @@ -57,5 +61,15 @@ public interface IBatchParameterEditorViewModel : IBelongsToIterationSelectorVie
/// Gets or sets the loading value
/// </summary>
bool IsLoading { get; set; }

/// <summary>
/// Gets the <see cref="IOptionSelectorViewModel" />
/// </summary>
IOptionSelectorViewModel OptionSelectorViewModel { get; }

/// <summary>
/// Gets the list of <see cref="ParameterValueSetBaseRowViewModel"/>s
/// </summary>
SourceList<ParameterValueSetBaseRowViewModel> Rows { get; }
}
}

0 comments on commit 9d8a231

Please sign in to comment.