Skip to content

Commit

Permalink
filtering implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Jul 31, 2024
1 parent 41ec4d3 commit 236878c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<DxComboBox Data="@(this.ViewModel.AvailableDomainsOfExpertise)"
@bind-Value="@(this.ViewModel.SelectedDomainOfExpertise)"
FilteringMode="DataGridFilteringMode.Contains"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Never"
ClearButtonDisplayMode="@(this.ViewModel.AllowNullSelection ? DataEditorClearButtonDisplayMode.Auto : DataEditorClearButtonDisplayMode.Never)"
NullText="Select a Domain Of Expertise"
AllowUserInput="true"
CssClass="@(this.CssClass)">
Expand All @@ -48,6 +48,10 @@
@(domainOfExpertise.GetSelectorNameAndShortname())
</div>
}
else
{
<span class="text-secondary">@("Select a Domain Of Expertise")</span>
}
</EditBoxTemplate>
</DxComboBox>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class DomainOfExpertiseSelectorViewModel : BelongsToIterationSelectorView
/// Creates a new instance of <see cref="DomainOfExpertiseSelectorViewModel" />
/// </summary>
/// <param name="sessionService">The <see cref="ISessionService" /></param>
/// <param name="messageBus">The <see cref="ICDPMessageBus"/></param>
/// <param name="messageBus">The <see cref="ICDPMessageBus" /></param>
public DomainOfExpertiseSelectorViewModel(ISessionService sessionService, ICDPMessageBus messageBus)
{
this.SessionService = sessionService;
Expand All @@ -62,7 +62,12 @@ public DomainOfExpertiseSelectorViewModel(ISessionService sessionService, ICDPMe
}

/// <summary>
/// Gets or sets the callback that is executed when the <see cref="SelectedDomainOfExpertise"/> property has changed
/// Gets or sets the condition to check if a null selection can be allowed
/// </summary>
public bool AllowNullSelection { get; set; }

/// <summary>
/// Gets or sets the callback that is executed when the <see cref="SelectedDomainOfExpertise" /> property has changed
/// </summary>
public EventCallback<DomainOfExpertise> OnSelectedDomainOfExpertiseChange { get; set; }

Expand Down Expand Up @@ -91,11 +96,11 @@ public DomainOfExpertise SelectedDomainOfExpertise
}

/// <summary>
/// Sets the <see cref="SelectedDomainOfExpertise"/> property or resets its value
/// Sets the <see cref="SelectedDomainOfExpertise" /> property or resets its value
/// </summary>
/// <param name="reset">The condition to check if the value should be reset</param>
/// <param name="domainOfExpertise">The <see cref="DomainOfExpertise"/> to be set</param>
/// <returns>A <see cref="Task"/></returns>
/// <param name="domainOfExpertise">The <see cref="DomainOfExpertise" /> to be set</param>
/// <returns>A <see cref="Task" /></returns>
public async Task SetSelectedDomainOfExpertiseOrReset(bool reset, DomainOfExpertise domainOfExpertise = null)
{
switch (reset)
Expand Down Expand Up @@ -124,7 +129,7 @@ protected override void UpdateProperties()
/// <summary>
/// Method executed when an iteration domain has changed
/// </summary>
/// <param name="domainChangedEvent">The <see cref="DomainChangedEvent"/> data</param>
/// <param name="domainChangedEvent">The <see cref="DomainChangedEvent" /> data</param>
private void OnDomainChanged(DomainChangedEvent domainChangedEvent)
{
if (domainChangedEvent.Iteration.Iid == this.CurrentIteration?.Iid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,26 @@ public interface IDomainOfExpertiseSelectorViewModel : IBelongsToIterationSelect
ISessionService SessionService { get; }

/// <summary>
/// Gets the <see cref="DomainOfExpertise" /> from the current <see cref="Iteration"/>
/// Gets the <see cref="DomainOfExpertise" /> from the current <see cref="Iteration" />
/// </summary>
DomainOfExpertise CurrentIterationDomain { get; set; }

/// <summary>
/// Gets or sets the callback that is executed when the <see cref="SelectedDomainOfExpertise"/> property has changed
/// Gets or sets the callback that is executed when the <see cref="SelectedDomainOfExpertise" /> property has changed
/// </summary>
EventCallback<DomainOfExpertise> OnSelectedDomainOfExpertiseChange { get; set; }

/// <summary>
/// Sets the <see cref="SelectedDomainOfExpertise"/> property or resets its value
/// Gets or sets the condition to check if a null selection can be allowed
/// </summary>
bool AllowNullSelection { get; set; }

/// <summary>
/// Sets the <see cref="SelectedDomainOfExpertise" /> property or resets its value
/// </summary>
/// <param name="reset">The condition to check if the value should be reset</param>
/// <param name="domainOfExpertise">The <see cref="DomainOfExpertise"/> to be set</param>
/// <returns>A <see cref="Task"/></returns>
/// <param name="domainOfExpertise">The <see cref="DomainOfExpertise" /> to be set</param>
/// <returns>A <see cref="Task" /></returns>
Task SetSelectedDomainOfExpertiseOrReset(bool reset, DomainOfExpertise domainOfExpertise = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Copyright (c) 2024 Starion Group S.A.

@if (this.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType != null)
{
<div class="row pt-2">
<div class="row pt-3">
<div class="col">
<OptionSelector ViewModel="this.ViewModel.OptionSelectorViewModel"/>
</div>
Expand All @@ -47,6 +47,23 @@ Copyright (c) 2024 Starion Group S.A.
</div>
</div>

<div class="row pt-3">
<div class="col">
<h6>Filter on Category:</h6>
<DxComboBox Data="@this.ViewModel.AvailableCategories"
AllowUserInput="true"
@bind-Value="@this.ViewModel.SelectedCategory"
FilteringMode="DataGridFilteringMode.Contains"
TextFieldName="@nameof(Option.Name)"
ClearButtonDisplayMode="@(DataEditorClearButtonDisplayMode.Auto)"
NullText="Select a Category" />
</div>
<div class="col">
<DomainOfExpertiseSelector ViewModel="@(this.ViewModel.DomainOfExpertiseSelectorViewModel)"
DisplayText="Filter on Domain Of Expertise:"/>
</div>
</div>

<div class="row pt-3">
<h6>Select a value:</h6>
<ParameterTypeEditorSelector BindValueMode="BindValueMode.OnDelayedInput"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ protected override void OnInitialized()
this.Disposables.Add(this.WhenAnyValue(
x => x.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType,
x => x.ViewModel.OptionSelectorViewModel.SelectedOption,
x => x.ViewModel.FiniteStateSelectorViewModel.SelectedActualFiniteState)
x => x.ViewModel.FiniteStateSelectorViewModel.SelectedActualFiniteState,
x => x.ViewModel.SelectedCategory,
x => x.ViewModel.DomainOfExpertiseSelectorViewModel.SelectedDomainOfExpertise)
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
}

/// <summary>
/// Gets the group check value based on the given <see cref="ViewModel"/>
/// 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>
Expand Down Expand Up @@ -106,9 +108,9 @@ private void GroupCheckBox_CheckedChanged(bool? value, GridDataColumnGroupRowTem
}

/// <summary>
/// Gets the <see cref="ParameterValueSetBaseRowViewModel"/>s from the selected element name group
/// Gets the <see cref="ParameterValueSetBaseRowViewModel" />s from the selected element name group
/// </summary>
/// <param name="context">The <see cref="GridDataColumnGroupRowTemplateContext"/></param>
/// <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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,30 @@ namespace COMETwebapp.ViewModels.Components.ParameterEditor.BatchParameterEditor
/// </summary>
public class BatchParameterEditorViewModel : BelongsToIterationSelectorViewModel, IBatchParameterEditorViewModel
{
/// <summary>
/// Gets the excluded <see cref="ParameterType" />s for applying the batch updates
/// </summary>
private readonly IEnumerable<ClassKind> excludedParameterTypes = [ClassKind.SampledFunctionParameterType, ClassKind.ArrayParameterType, ClassKind.CompoundParameterType];

/// <summary>
/// Gets the <see cref="ILogger{TCategoryName}" />
/// </summary>
private readonly ILogger<BatchParameterEditorViewModel> logger;

/// <summary>
/// Gets the <see cref="ICDPMessageBus"/>
/// Gets the <see cref="ICDPMessageBus" />
/// </summary>
private readonly ICDPMessageBus messageBus;

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

/// <summary>
/// The backing field for <see cref="IsLoading" />
/// The backing field for <see cref="SelectedCategory" />
/// </summary>
private bool isLoading;
private Category selectedCategory;

/// <summary>
/// Creates a new instance of type <see cref="BatchParameterEditorViewModel" />
Expand All @@ -83,6 +88,12 @@ public BatchParameterEditorViewModel(ISessionService sessionService, ICDPMessage
this.logger = logger;
var eventCallbackFactory = new EventCallbackFactory();

this.DomainOfExpertiseSelectorViewModel = new DomainOfExpertiseSelectorViewModel(sessionService, messageBus)
{
AllowNullSelection = true,
CurrentIteration = this.CurrentIteration
};

this.ConfirmCancelPopupViewModel = new ConfirmCancelPopupViewModel
{
OnCancel = eventCallbackFactory.Create(this, this.OnCancelPopup),
Expand All @@ -92,10 +103,12 @@ public BatchParameterEditorViewModel(ISessionService sessionService, ICDPMessage
};

this.Disposables.Add(this.WhenAnyValue(x => x.ParameterTypeSelectorViewModel.SelectedParameterType).Subscribe(this.OnSelectedParameterTypeChange));

this.Disposables.Add(this.WhenAnyValue(
x => x.OptionSelectorViewModel.SelectedOption,
x => x.FiniteStateSelectorViewModel.SelectedActualFiniteState)
x => x.OptionSelectorViewModel.SelectedOption,
x => x.FiniteStateSelectorViewModel.SelectedActualFiniteState,
x => x.DomainOfExpertiseSelectorViewModel.SelectedDomainOfExpertise,
x => x.SelectedCategory)
.Subscribe(_ => this.ApplyFilters()));
}

Expand All @@ -118,6 +131,20 @@ public bool IsLoading
set => this.RaiseAndSetIfChanged(ref this.isLoading, value);
}

/// <summary>
/// Gets a collection of all available categories
/// </summary>
public IEnumerable<Category> AvailableCategories => this.SessionService.GetSiteDirectory().AvailableReferenceDataLibraries().SelectMany(x => x.DefinedCategory).Distinct();

/// <summary>
/// Gets or sets the selected category
/// </summary>
public Category SelectedCategory
{
get => this.selectedCategory;
set => this.RaiseAndSetIfChanged(ref this.selectedCategory, value);
}

/// <summary>
/// Gets the <see cref="IParameterTypeEditorSelectorViewModel" />
/// </summary>
Expand All @@ -138,13 +165,18 @@ public bool IsLoading
/// </summary>
public IFiniteStateSelectorViewModel FiniteStateSelectorViewModel { get; private set; } = new FiniteStateSelectorViewModel();

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

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

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

Expand All @@ -161,6 +193,8 @@ public void OpenPopup()
this.ParameterTypeSelectorViewModel.SelectedParameterType = null;
this.OptionSelectorViewModel.SelectedOption = null;
this.FiniteStateSelectorViewModel.SelectedActualFiniteState = null;
this.DomainOfExpertiseSelectorViewModel.SelectedDomainOfExpertise = null;
this.SelectedCategory = null;
this.SelectedValueSetsRowsToUpdate = [];
this.IsVisible = true;
}
Expand All @@ -173,6 +207,7 @@ protected override void UpdateProperties()
this.ParameterTypeSelectorViewModel.CurrentIteration = this.CurrentIteration;
this.OptionSelectorViewModel.CurrentIteration = this.CurrentIteration;
this.FiniteStateSelectorViewModel.CurrentIteration = this.CurrentIteration;
this.DomainOfExpertiseSelectorViewModel.CurrentIteration = this.CurrentIteration;

var availableParameterTypeIids = this.CurrentIteration?
.QueryParameterAndOverrideBases()
Expand All @@ -194,7 +229,7 @@ private void OnCancelPopup()
/// <summary>
/// Method executed everytime the <see cref="ConfirmCancelPopupViewModel" /> is confirmed
/// </summary>
/// <returns>A <see cref="Task"/></returns>
/// <returns>A <see cref="Task" /></returns>
private async Task OnConfirmPopup()
{
this.IsLoading = true;
Expand Down Expand Up @@ -233,7 +268,7 @@ private void OnSelectedParameterTypeChange(ParameterType selectedParameterType)
}

/// <summary>
/// Applies the selected filters for the <see cref="Rows"/>
/// Applies the selected filters for the <see cref="Rows" />
/// </summary>
private void ApplyFilters()
{
Expand All @@ -244,11 +279,13 @@ private void ApplyFilters()
return;
}

if (this.ParameterTypeSelectorViewModel.SelectedParameterType != null)
if (this.ParameterTypeSelectorViewModel.SelectedParameterType == null)
{
parameterAndOverrideBases = parameterAndOverrideBases.Where(x => x.ParameterType.Iid == this.ParameterTypeSelectorViewModel.SelectedParameterType.Iid);
return;
}

parameterAndOverrideBases = parameterAndOverrideBases.Where(x => x.ParameterType.Iid == this.ParameterTypeSelectorViewModel.SelectedParameterType.Iid);

var parameterValueSets = parameterAndOverrideBases
.OfType<Parameter>()
.SelectMany(x => x.ValueSet);
Expand All @@ -263,6 +300,20 @@ private void ApplyFilters()
parameterValueSets = parameterValueSets.Where(x => x.ActualState?.Iid == this.FiniteStateSelectorViewModel.SelectedActualFiniteState.Iid);
}

if (this.SelectedCategory != null)
{
var parameterTypeCategories = this.ParameterTypeSelectorViewModel.SelectedParameterType.Category;

parameterValueSets = parameterTypeCategories.Count > 0
? parameterValueSets.Where(x => x.GetContainerOfType<Parameter>().ParameterType.Category.Contains(this.SelectedCategory))
: parameterValueSets.Where(x => x.GetContainerOfType<ElementDefinition>().Category.Contains(this.SelectedCategory));
}

if (this.DomainOfExpertiseSelectorViewModel.SelectedDomainOfExpertise != null)
{
parameterValueSets = parameterValueSets.Where(x => x.GetContainerOfType<Parameter>().Owner.Iid == this.DomainOfExpertiseSelectorViewModel.SelectedDomainOfExpertise.Iid);
}

this.Rows.Edit(action =>
{
action.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace COMETwebapp.ViewModels.Components.ParameterEditor.BatchParameterEditor
{
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.ViewModels.Components;
using COMET.Web.Common.ViewModels.Components.ParameterEditors;
using COMET.Web.Common.ViewModels.Components.Selectors;
Expand Down Expand Up @@ -68,7 +70,7 @@ public interface IBatchParameterEditorViewModel : IBelongsToIterationSelectorVie
IOptionSelectorViewModel OptionSelectorViewModel { get; }

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

Expand All @@ -82,6 +84,21 @@ public interface IBatchParameterEditorViewModel : IBelongsToIterationSelectorVie
/// </summary>
IReadOnlyList<object> SelectedValueSetsRowsToUpdate { get; set; }

/// <summary>
/// Gets a collection of all available categories
/// </summary>
IEnumerable<Category> AvailableCategories { get; }

/// <summary>
/// Gets or sets the selected category
/// </summary>
Category SelectedCategory { get; set; }

/// <summary>
/// Gets the <see cref="IDomainOfExpertiseSelectorViewModel" />
/// </summary>
IDomainOfExpertiseSelectorViewModel DomainOfExpertiseSelectorViewModel { get; }

/// <summary>
/// Method invoked for opening the batch update popup
/// </summary>
Expand Down

0 comments on commit 236878c

Please sign in to comment.