Skip to content

Commit

Permalink
Fix #627 [Model Editor] Panel Editor - add Parameter and add Element …
Browse files Browse the repository at this point in the history
…Definition improvements (#649)
  • Loading branch information
joao4all authored May 29, 2024
1 parent 7515535 commit 870e28c
Show file tree
Hide file tree
Showing 22 changed files with 415 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// limitations under the License.
------------------------------------------------------------------------------->
@namespace COMET.Web.Common.Components.Selectors
@using COMET.Web.Common.Extensions

@if (this.ViewModel.SessionService != null)
{
Expand All @@ -33,17 +34,18 @@
FilteringMode="DataGridFilteringMode.Contains"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Never"
NullText="Select a Domain Of Expertise"
AllowUserInput="true"
CssClass="@(this.CssClass)">
<ItemTemplate Context="domainOfExpertise">
<div class="@(this.ViewModel.CurrentIterationDomain == domainOfExpertise ? "fw-bold" : string.Empty)">
@GetDomainNameAndShortnameToDisplay(domainOfExpertise)
@(domainOfExpertise.GetSelectorNameAndShortname())
</div>
</ItemTemplate>
<EditBoxTemplate Context="domainOfExpertise">
@if (domainOfExpertise != null)
{
<div class="@(this.ViewModel.CurrentIterationDomain == domainOfExpertise ? "fw-bold" : string.Empty)">
@GetDomainNameAndShortnameToDisplay(domainOfExpertise)
@(domainOfExpertise.GetSelectorNameAndShortname())
</div>
}
</EditBoxTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,5 @@ public partial class DomainOfExpertiseSelector
/// </summary>
[Parameter]
public string CssClass { get; set; }

/// <summary>
/// Gets the domain and shortname to display, in the following format: name [shortname]
/// </summary>
/// <param name="domainOfExpertise">The domain of expertise to get the name and shortname</param>
/// <returns>A string that contains name and shortname</returns>
private static string GetDomainNameAndShortnameToDisplay(DomainOfExpertise domainOfExpertise)
{
return $"{domainOfExpertise.Name} [{domainOfExpertise.ShortName}]";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!------------------------------------------------------------------------------
// Copyright (c) 2023-2024 Starion Group S.A.
//
// 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.
//
// 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
//
// 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.
------------------------------------------------------------------------------->
@namespace COMET.Web.Common.Components.Selectors
@using COMET.Web.Common.Model.Selectors
@using CDP4Common.SiteDirectoryData
@inherits DisposableComponent

<DxComboBox Data="@(this.ViewModel.AvailableMeasurementScales.Select(x => new SelectorModelBaseWrapper<MeasurementScale>(x)))"
TData="SelectorModelBaseWrapper<MeasurementScale>"
TValue="MeasurementScale"
@bind-Value="@(this.ViewModel.SelectedMeasurementScale)"
FilteringMode="DataGridFilteringMode.Contains"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
TextFieldName="@(nameof(SelectorModelBaseWrapper<ParameterType>.DisplayText))"
ValueFieldName="@(nameof(SelectorModelBaseWrapper<ParameterType>.WrappedThing))"
NullText="Select a Measurement Scale"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MeasurementScaleSelector.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, João Rua
//
// 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 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 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>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Components.Selectors
{
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.ViewModels.Components.Selectors;

using Microsoft.AspNetCore.Components;

/// <summary>
/// Component used to select a <see cref="MeasurementScale" />
/// </summary>
public partial class MeasurementScaleSelector : DisposableComponent
{
/// <summary>
/// Gets or sets the <see cref="IMeasurementScaleSelectorViewModel" />
/// </summary>
[Parameter]
public IMeasurementScaleSelectorViewModel ViewModel { get; set; }
}
}
22 changes: 13 additions & 9 deletions COMET.Web.Common/Components/Selectors/ParameterTypeSelector.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!------------------------------------------------------------------------------
// Copyright (c) 2023-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 Starion Web Application implementation of ECSS-E-TM-10-25
Expand All @@ -20,8 +20,9 @@
// limitations under the License.
------------------------------------------------------------------------------->
@namespace COMET.Web.Common.Components.Selectors

@using COMET.Web.Common.Extensions
@using CDP4Common.SiteDirectoryData
@using COMET.Web.Common.Model.Selectors
@inherits BelongsToIterationSelector<COMET.Web.Common.ViewModels.Components.Selectors.IParameterTypeSelectorViewModel>

@if (this.ViewModel.CurrentIteration != null)
Expand All @@ -30,11 +31,14 @@
{
<h6>@(this.DisplayText)</h6>
}
<DxComboBox Data="@this.ViewModel.AvailableParameterTypes"
AllowUserInput="true"
@bind-Value="@this.ViewModel.SelectedParameterType"
FilteringMode="DataGridFilteringMode.Contains"
TextFieldName="@nameof(ParameterType.Name)"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
NullText="Select a Parameter Type" />

<DxComboBox Data="@(this.ViewModel.AvailableParameterTypes.Select(x => new SelectorModelBaseWrapper<ParameterType>(x)))"
TData="SelectorModelBaseWrapper<ParameterType>"
TValue="ParameterType"
@bind-Value="@(this.ViewModel.SelectedParameterType)"
FilteringMode="DataGridFilteringMode.Contains"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
TextFieldName="@(nameof(SelectorModelBaseWrapper<ParameterType>.DisplayText))"
ValueFieldName="@(nameof(SelectorModelBaseWrapper<ParameterType>.WrappedThing))"
NullText="Select a Parameter Type"/>
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@ public partial class ParameterTypeSelector
/// </summary>
[Parameter]
public string DisplayText { get; set; } = "Filter on Parameter Type:";

/// <summary>
/// Condition to check if name and shortname shall be displayed in the selector. If false, only the name is displayed
/// </summary>
[Parameter]
public bool DisplayNameAndShortname { get; set; }
}
}
10 changes: 10 additions & 0 deletions COMET.Web.Common/Extensions/ThingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,5 +570,15 @@ public static string GetShortNameOrName(this Thing thing)

return thingDesignation;
}

/// <summary>
/// Gets the thing and shortname to display, in the following format: name [shortname]
/// </summary>
/// <param name="thing">The thing to get the name and shortname</param>
/// <returns>A string that contains name and shortname</returns>
internal static string GetSelectorNameAndShortname(this DefinedThing thing)
{
return $"{thing.Name} [{thing.ShortName}]";
}
}
}
55 changes: 55 additions & 0 deletions COMET.Web.Common/Model/Selectors/SelectorModelBaseWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SelectorsBaseWrapper.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, João Rua
//
// 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 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 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>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Model.Selectors
{
using CDP4Common.CommonData;

using COMET.Web.Common.Extensions;

/// <summary>
/// The wrapper to be used to display and select data in the <see cref="DefinedThing" />
/// </summary>
public class SelectorModelBaseWrapper<T> where T : DefinedThing
{
/// <summary>
/// Creates a new instance of the <see cref="SelectorModelBaseWrapper{T}" />
/// </summary>
/// <param name="thing">The thing to be wrapped</param>
public SelectorModelBaseWrapper(T thing)
{
this.WrappedThing = thing;
}

/// <summary>
/// The thing to be selected
/// </summary>
public T WrappedThing { get; set; }

/// <summary>
/// The text to display for thing selection
/// </summary>
public string DisplayText => this.WrappedThing?.GetSelectorNameAndShortname();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class DomainOfExpertiseSelectorViewModel : BelongsToIterationSelectorView
public DomainOfExpertiseSelectorViewModel(ISessionService sessionService, ICDPMessageBus messageBus)
{
this.SessionService = sessionService;
this.AvailableDomainsOfExpertise = sessionService.GetSiteDirectory().Domain.OrderBy(x => x.Name);
this.AvailableDomainsOfExpertise = sessionService.GetSiteDirectory().Domain.OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase);

this.Disposables.Add(this.WhenAnyValue(x => x.SelectedDomainOfExpertise).SubscribeAsync(async domain => await this.OnSelectedDomainOfExpertiseChange.InvokeAsync(domain)));
this.Disposables.Add(messageBus.Listen<DomainChangedEvent>().Subscribe(this.OnDomainChanged));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IMeasurementScaleSelectorViewModel.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, João Rua
//
// 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 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 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>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.ViewModels.Components.Selectors
{
using CDP4Common.SiteDirectoryData;

using Microsoft.AspNetCore.Components;

/// <summary>
/// View Model that enables the user to select a <see cref="MeasurementScale" />
/// </summary>
public interface IMeasurementScaleSelectorViewModel
{
/// <summary>
/// Gets or sets the callback that is executed when the <see cref="SelectedMeasurementScale" /> property has changed
/// </summary>
EventCallback<MeasurementScale> OnSelectedMeasurementScaleChange { get; set; }

/// <summary>
/// A collection of available <see cref="DomainOfExpertise" />
/// </summary>
IEnumerable<MeasurementScale> AvailableMeasurementScales { get; set; }

/// <summary>
/// The currently selected <see cref="MeasurementScale" />
/// </summary>
MeasurementScale SelectedMeasurementScale { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ public interface IParameterTypeSelectorViewModel : IBelongsToIterationSelectorVi
/// </summary>
/// <param name="parameterTypesId">A collection of <see cref="Guid" /> for <see cref="ParameterType" /></param>
void FilterAvailableParameterTypes(IEnumerable<Guid> parameterTypesId);

/// <summary>
/// Excludes a collection of <see cref="ParameterType" />s from the <see cref="ParameterTypeSelectorViewModel.AvailableParameterTypes" />
/// </summary>
/// <param name="parameterTypesId">A collection of <see cref="Guid" /> for <see cref="ParameterType" /></param>
void ExcludeAvailableParameterTypes(IEnumerable<Guid> parameterTypesId);
}
}
Loading

0 comments on commit 870e28c

Please sign in to comment.