From 3c843f143a68e45bafa1a2d1146bf922775dfe00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rua?= <140734849+joao4all@users.noreply.github.com> Date: Wed, 29 May 2024 14:28:42 +0100 Subject: [PATCH] Feat #611 [Server Administration] Refactor Participant Roles page to be inline with Measurement Scale page (#650) --- .../MeasurementUnitsTableTestFixture.cs | 2 - .../ParticipantRoleDetailsTestFixture.cs | 120 ------------------ .../Roles/ParticipantRolesTableTestFixture.cs | 105 ++++++++------- ...rticipantRolesTableViewModelTestFixture.cs | 6 +- ...etails.razor => ParticipantRoleForm.razor} | 28 ++-- ....razor.cs => ParticipantRoleForm.razor.cs} | 33 ++--- .../Roles/ParticipantRolesTable.razor | 65 ++++------ .../Roles/ParticipantRolesTable.razor.cs | 73 +++++------ .../Roles/ParticipantRolesTableViewModel.cs | 81 ++++++------ 9 files changed, 183 insertions(+), 330 deletions(-) delete mode 100644 COMETwebapp.Tests/Components/SiteDirectory/Roles/ParticipantRoleDetailsTestFixture.cs rename COMETwebapp/Components/SiteDirectory/Roles/{ParticipantRoleDetails.razor => ParticipantRoleForm.razor} (74%) rename COMETwebapp/Components/SiteDirectory/Roles/{ParticipantRoleDetails.razor.cs => ParticipantRoleForm.razor.cs} (68%) diff --git a/COMETwebapp.Tests/Components/ReferenceData/MeasurementUnitsTableTestFixture.cs b/COMETwebapp.Tests/Components/ReferenceData/MeasurementUnitsTableTestFixture.cs index 9d3aa358..ac619e73 100644 --- a/COMETwebapp.Tests/Components/ReferenceData/MeasurementUnitsTableTestFixture.cs +++ b/COMETwebapp.Tests/Components/ReferenceData/MeasurementUnitsTableTestFixture.cs @@ -32,11 +32,9 @@ namespace COMETwebapp.Tests.Components.ReferenceData using COMET.Web.Common.Test.Helpers; using COMETwebapp.Components.ReferenceData.MeasurementUnits; - using COMETwebapp.Components.SiteDirectory; using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.ReferenceData.MeasurementUnits; using COMETwebapp.ViewModels.Components.ReferenceData.Rows; - using COMETwebapp.ViewModels.Components.SiteDirectory.Rows; using COMETwebapp.Wrappers; using DevExpress.Blazor; diff --git a/COMETwebapp.Tests/Components/SiteDirectory/Roles/ParticipantRoleDetailsTestFixture.cs b/COMETwebapp.Tests/Components/SiteDirectory/Roles/ParticipantRoleDetailsTestFixture.cs deleted file mode 100644 index e58b9f81..00000000 --- a/COMETwebapp.Tests/Components/SiteDirectory/Roles/ParticipantRoleDetailsTestFixture.cs +++ /dev/null @@ -1,120 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2023-2024 Starion Group S.A. -// -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, 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. -// -// The CDP4-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, -// 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 . -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace COMETwebapp.Tests.Components.SiteDirectory.Roles -{ - using System.Linq; - using System.Threading.Tasks; - - using Bunit; - - using CDP4Common.SiteDirectoryData; - - using COMET.Web.Common.Test.Helpers; - - using COMETwebapp.Components.SiteDirectory.Roles; - using COMETwebapp.ViewModels.Components.SiteDirectory.Roles; - - using DevExpress.Blazor; - - using Microsoft.AspNetCore.Components; - using Microsoft.AspNetCore.Components.Forms; - - using Moq; - - using NUnit.Framework; - - using TestContext = Bunit.TestContext; - - [TestFixture] - public class ParticipantRoleDetailsTestFixture - { - private TestContext context; - private Mock viewModel; - private ParticipantRole participantRole; - - [SetUp] - public void SetUp() - { - this.context = new TestContext(); - this.viewModel = new Mock(); - - this.participantRole = new ParticipantRole() - { - Name = "Role 1", - ShortName = "role1", - Container = new SiteDirectory(){ ShortName = "siteDir" }, - }; - - this.viewModel.Setup(x => x.CurrentThing).Returns(this.participantRole); - this.context.ConfigureDevExpressBlazor(); - } - - [TearDown] - public void Teardown() - { - this.context.CleanContext(); - this.context.Dispose(); - } - - [Test] - public async Task VerifyParticipantRoleForm() - { - var wasOnSubmitCallbackInvoked = false; - var wasOnCancelCallbackInvoked = false; - - var renderer = this.context.RenderComponent(parameters => - { - parameters.Add(p => p.ViewModel, this.viewModel.Object); - }); - - var form = renderer.FindComponent(); - await renderer.InvokeAsync(form.Instance.OnValidSubmit.InvokeAsync); - - Assert.Multiple(() => - { - this.viewModel.Verify(x => x.CreateOrEditParticipantRole(false), Times.Once); - Assert.That(wasOnSubmitCallbackInvoked, Is.EqualTo(false)); - }); - - renderer.SetParametersAndRender(parameters => - { - parameters.Add(p => p.OnCancel, new EventCallbackFactory().Create(this, () => { wasOnCancelCallbackInvoked = true; })); - parameters.Add(p => p.OnSubmit, new EventCallbackFactory().Create(this, () => { wasOnSubmitCallbackInvoked = true; })); - }); - - await renderer.InvokeAsync(form.Instance.OnValidSubmit.InvokeAsync); - - Assert.Multiple(() => - { - this.viewModel.Verify(x => x.CreateOrEditParticipantRole(false), Times.Once); - Assert.That(wasOnSubmitCallbackInvoked, Is.EqualTo(true)); - }); - - var cancelParticipantRoleButton = renderer.FindComponents().First(x => x.Instance.Id == "cancelItemButton"); - await renderer.InvokeAsync(cancelParticipantRoleButton.Instance.Click.InvokeAsync); - Assert.That(wasOnCancelCallbackInvoked, Is.EqualTo(true)); - } - } -} diff --git a/COMETwebapp.Tests/Components/SiteDirectory/Roles/ParticipantRolesTableTestFixture.cs b/COMETwebapp.Tests/Components/SiteDirectory/Roles/ParticipantRolesTableTestFixture.cs index 5d2a216b..90a3c6f6 100644 --- a/COMETwebapp.Tests/Components/SiteDirectory/Roles/ParticipantRolesTableTestFixture.cs +++ b/COMETwebapp.Tests/Components/SiteDirectory/Roles/ParticipantRolesTableTestFixture.cs @@ -1,32 +1,29 @@ // -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2023-2024 Starion Group S.A. -// -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, 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. -// -// The CDP4-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, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// 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 . -// -// -------------------------------------------------------------------------------------------------------------------- +// +// -------------------------------------------------------------------------------------------------------------------- namespace COMETwebapp.Tests.Components.SiteDirectory.Roles { - using System.Linq; - using System.Threading.Tasks; - using Bunit; using CDP4Common.SiteDirectoryData; @@ -41,6 +38,7 @@ namespace COMETwebapp.Tests.Components.SiteDirectory.Roles using DynamicData; + using Microsoft.AspNetCore.Components.Forms; using Microsoft.Extensions.DependencyInjection; using Moq; @@ -63,11 +61,11 @@ public void SetUp() this.context = new TestContext(); this.viewModel = new Mock(); - this.participantRole1 = new ParticipantRole() + this.participantRole1 = new ParticipantRole { Name = "Role 1", ShortName = "role1", - Container = new SiteDirectory(){ ShortName = "siteDir" }, + Container = new SiteDirectory { ShortName = "siteDir" } }; var rows = new SourceList(); @@ -90,47 +88,46 @@ public void Teardown() } [Test] - public void VerifyOnInitialized() + public async Task VerifyAddingOrEditingParticipantRole() { + var addParticipantRoleButton = this.renderer.FindComponents().First(x => x.Instance.Id == "dataItemDetailsButton"); + await this.renderer.InvokeAsync(addParticipantRoleButton.Instance.Click.InvokeAsync); + Assert.Multiple(() => { - Assert.That(this.renderer.Instance.ShouldCreateThing, Is.EqualTo(false)); - Assert.That(this.renderer.Instance.ViewModel, Is.Not.Null); - Assert.That(this.renderer.Markup, Does.Contain(this.participantRole1.Name)); - this.viewModel.Verify(x => x.InitializeViewModel(), Times.Once); + Assert.That(this.renderer.Instance.ShouldCreateThing, Is.EqualTo(true)); + Assert.That(this.viewModel.Object.CurrentThing, Is.InstanceOf(typeof(ParticipantRole))); }); - } - [Test] - public async Task VerifyAddParticipantRoleClick() - { - var addParticipantRoleButton = this.renderer.FindComponents().First(x => x.Instance.Id == "addParticipantRoleButton"); - await this.renderer.InvokeAsync(addParticipantRoleButton.Instance.Click.InvokeAsync); + var participantRolesGrid = this.renderer.FindComponent(); + await this.renderer.InvokeAsync(() => participantRolesGrid.Instance.SelectedDataItemChanged.InvokeAsync(new ParticipantRoleRowViewModel(this.participantRole1))); + Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(true)); - var grid = this.renderer.FindComponent(); - Assert.That(grid.Instance.IsEditing(), Is.EqualTo(true)); + var participantRoleForm = this.renderer.FindComponent(); + var participantRoleEditForm = participantRoleForm.FindComponent(); + await participantRoleForm.InvokeAsync(participantRoleEditForm.Instance.OnValidSubmit.InvokeAsync); - await this.renderer.InvokeAsync(grid.Instance.EditModelSaving.InvokeAsync); - this.viewModel.Verify(x => x.CreateOrEditParticipantRole(true), Times.Once); + Assert.Multiple(() => + { + this.viewModel.Verify(x => x.CreateOrEditParticipantRole(false), Times.Once); + Assert.That(this.viewModel.Object.CurrentThing, Is.InstanceOf(typeof(ParticipantRole))); + }); + + var form = this.renderer.FindComponent(); + await this.renderer.InvokeAsync(form.Instance.EditModelSaving.InvokeAsync); + this.viewModel.Verify(x => x.CreateOrEditParticipantRole(false), Times.Once); } [Test] - public async Task VerifyRowClick() + public void VerifyOnInitialized() { - Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(false)); - - var firstRow = this.viewModel.Object.Rows.Items.First(); - var grid = this.renderer.FindComponent(); - await this.renderer.InvokeAsync(async () => await grid.Instance.SelectedDataItemChanged.InvokeAsync(firstRow)); - - Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(true)); - - var details = this.renderer.FindComponent(); - await this.renderer.InvokeAsync(details.Instance.OnSubmit.InvokeAsync); - this.viewModel.Verify(x => x.CreateOrEditParticipantRole(false), Times.Once); - - await this.renderer.InvokeAsync(details.Instance.OnCancel.InvokeAsync); - Assert.That(this.renderer.Instance.IsOnEditMode, Is.EqualTo(false)); + Assert.Multiple(() => + { + Assert.That(this.renderer.Instance.ShouldCreateThing, Is.EqualTo(false)); + Assert.That(this.renderer.Instance.ViewModel, Is.Not.Null); + Assert.That(this.renderer.Markup, Does.Contain(this.participantRole1.Name)); + this.viewModel.Verify(x => x.InitializeViewModel(), Times.Once); + }); } } } diff --git a/COMETwebapp.Tests/ViewModels/Components/SiteDirectory/Roles/ParticipantRolesTableViewModelTestFixture.cs b/COMETwebapp.Tests/ViewModels/Components/SiteDirectory/Roles/ParticipantRolesTableViewModelTestFixture.cs index 458c400f..c59733dd 100644 --- a/COMETwebapp.Tests/ViewModels/Components/SiteDirectory/Roles/ParticipantRolesTableViewModelTestFixture.cs +++ b/COMETwebapp.Tests/ViewModels/Components/SiteDirectory/Roles/ParticipantRolesTableViewModelTestFixture.cs @@ -37,6 +37,7 @@ namespace COMETwebapp.Tests.ViewModels.Components.SiteDirectory.Roles using COMET.Web.Common.Enumerations; using COMET.Web.Common.Model; using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.Test.Helpers; using COMETwebapp.Services.ShowHideDeprecatedThingsService; using COMETwebapp.ViewModels.Components.SiteDirectory.Roles; @@ -177,8 +178,11 @@ public async Task VerifyParticipantRoleCreation() { this.viewModel.InitializeViewModel(); await this.viewModel.CreateOrEditParticipantRole(true); - this.sessionService.Verify(x => x.CreateOrUpdateThingsWithNotification(It.IsAny(), It.IsAny>(), It.IsAny()), Times.Once); + + this.sessionService.Setup(x => x.CreateOrUpdateThingsWithNotification(It.IsAny(), It.IsAny>(), It.IsAny())).Throws(new Exception()); + await this.viewModel.CreateOrEditParticipantRole(false); + this.loggerMock.Verify(LogLevel.Error, x => !string.IsNullOrWhiteSpace(x.ToString()), Times.Once()); } } } diff --git a/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleDetails.razor b/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleForm.razor similarity index 74% rename from COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleDetails.razor rename to COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleForm.razor index adfe9065..95be9bbb 100644 --- a/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleDetails.razor +++ b/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleForm.razor @@ -1,20 +1,25 @@  -@inherits DisposableComponent +@inherits SelectedDataItemForm @@ -47,6 +52,7 @@ Copyright (c) 2023-2024 Starion Group S.A. - + \ No newline at end of file diff --git a/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleDetails.razor.cs b/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleForm.razor.cs similarity index 68% rename from COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleDetails.razor.cs rename to COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleForm.razor.cs index dc3211a0..28b038ce 100644 --- a/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleDetails.razor.cs +++ b/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRoleForm.razor.cs @@ -26,16 +26,15 @@ namespace COMETwebapp.Components.SiteDirectory.Roles { using System.ComponentModel.DataAnnotations; - using COMET.Web.Common.Components; - + using COMETwebapp.Components.Common; using COMETwebapp.ViewModels.Components.SiteDirectory.Roles; using Microsoft.AspNetCore.Components; /// - /// Support class for the + /// Support class for the /// - public partial class ParticipantRoleDetails : DisposableComponent + public partial class ParticipantRoleForm : SelectedDataItemForm { /// /// The for this component @@ -44,29 +43,13 @@ public partial class ParticipantRoleDetails : DisposableComponent public IParticipantRolesTableViewModel ViewModel { get; set; } /// - /// Method that is executed when the current edit form is submitted - /// - [Parameter] - public EventCallback OnSubmit { get; set; } - - /// - /// Method that is executed when the current edit form is canceled + /// Method that is executed when there is a valid submit /// - [Parameter] - public EventCallback OnCancel { get; set; } - - /// - /// Method that executes the default creation method in case the property is not set - /// - private async Task OnValidSubmit() + /// A + protected override async Task OnValidSubmit() { - if (this.OnSubmit.HasDelegate) - { - await this.OnSubmit.InvokeAsync(); - return; - } - - await this.ViewModel.CreateOrEditParticipantRole(false); + await this.ViewModel.CreateOrEditParticipantRole(this.ShouldCreate); + await base.OnValidSubmit(); } } } diff --git a/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRolesTable.razor b/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRolesTable.razor index 5f6c4cb8..632d261b 100644 --- a/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRolesTable.razor +++ b/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRolesTable.razor @@ -1,18 +1,23 @@  @inherits SelectedDeprecatableDataItemBase @@ -22,51 +27,33 @@ Copyright (c) 2023-2024 Starion Group S.A. Data="this.ViewModel.Rows.Items" ColumnResizeMode="GridColumnResizeMode.ColumnsContainer" ShowSearchBox="true" - SearchBoxNullText="Search for a participant role..." + SearchBoxNullText="Search for a participant role ..." AllowSelectRowByClick="true" + SelectionMode="GridSelectionMode.Single" SelectedDataItemChanged="@(row => this.OnSelectedDataItemChanged((ParticipantRoleRowViewModel)row))" - PopupEditFormCssClass="pw-800" - PopupEditFormHeaderText="Participant Role" - CustomizeElement="DisableDeprecatedThing" - CustomizeEditModel="this.CustomizeEditThing" - EditMode="GridEditMode.PopupEditForm" - EditModelSaving="@(() => this.OnEditThingSaving())" EditFormButtonsVisible="false" + CustomizeElement="DisableDeprecatedThing" PageSize="20" PagerNavigationMode="PagerNavigationMode.Auto" PageSizeSelectorVisible="true" PageSizeSelectorItems="@(new[] { 20, 35, 50 })" PageSizeSelectorAllRowsItemVisible="true" - CssClass="d-inline height-fit-content"> + FilterMenuButtonDisplayMode="GridFilterMenuButtonDisplayMode.Always" + CssClass="height-fit-content"> - - - - - - - + - - - - - - - + - - - - + - + \ No newline at end of file diff --git a/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRolesTable.razor.cs b/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRolesTable.razor.cs index 0d2c3afd..d7d4bf20 100644 --- a/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRolesTable.razor.cs +++ b/COMETwebapp/Components/SiteDirectory/Roles/ParticipantRolesTable.razor.cs @@ -1,26 +1,26 @@ // -------------------------------------------------------------------------------------------------------------------- -// -// 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. -// -// The CDP4-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, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// 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 . -// -// -------------------------------------------------------------------------------------------------------------------- +// +// -------------------------------------------------------------------------------------------------------------------- namespace COMETwebapp.Components.SiteDirectory.Roles { @@ -30,12 +30,10 @@ namespace COMETwebapp.Components.SiteDirectory.Roles using COMETwebapp.ViewModels.Components.SiteDirectory.Roles; using COMETwebapp.ViewModels.Components.SiteDirectory.Rows; - using DevExpress.Blazor; - using Microsoft.AspNetCore.Components; /// - /// Support class for the + /// Support class for the /// public partial class ParticipantRolesTable : SelectedDeprecatableDataItemBase { @@ -56,34 +54,25 @@ protected override void OnInitialized() } /// - /// Method that is invoked when the edit/add thing form is being saved + /// Method invoked every time a row is selected /// - /// A - protected override async Task OnEditThingSaving() + /// The selected row + protected override void OnSelectedDataItemChanged(ParticipantRoleRowViewModel row) { - await this.ViewModel.CreateOrEditParticipantRole(true); + base.OnSelectedDataItemChanged(row); + this.ShouldCreateThing = false; + this.ViewModel.CurrentThing = row.Thing.Clone(true); } /// - /// Method invoked when creating a new thing + /// Method invoked before creating a new thing /// - /// A - protected override void CustomizeEditThing(GridCustomizeEditModelEventArgs e) + private void OnAddThingClick() { - base.CustomizeEditThing(e); - + this.ShouldCreateThing = true; + this.IsOnEditMode = true; this.ViewModel.CurrentThing = new ParticipantRole(); - e.EditModel = this.ViewModel.CurrentThing; - } - - /// - /// Method invoked everytime a row is selected - /// - /// The selected row - protected override void OnSelectedDataItemChanged(ParticipantRoleRowViewModel row) - { - base.OnSelectedDataItemChanged(row); - this.ViewModel.CurrentThing = row.Thing.Clone(true); + this.InvokeAsync(this.StateHasChanged); } } } diff --git a/COMETwebapp/ViewModels/Components/SiteDirectory/Roles/ParticipantRolesTableViewModel.cs b/COMETwebapp/ViewModels/Components/SiteDirectory/Roles/ParticipantRolesTableViewModel.cs index a5f4a598..d4098ae8 100644 --- a/COMETwebapp/ViewModels/Components/SiteDirectory/Roles/ParticipantRolesTableViewModel.cs +++ b/COMETwebapp/ViewModels/Components/SiteDirectory/Roles/ParticipantRolesTableViewModel.cs @@ -1,26 +1,26 @@ // -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2023-2024 Starion Group S.A. -// -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Antoine Théate, 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. -// -// The CDP4-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, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// 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 . -// -// -------------------------------------------------------------------------------------------------------------------- +// +// -------------------------------------------------------------------------------------------------------------------- namespace COMETwebapp.ViewModels.Components.SiteDirectory.Roles { @@ -45,8 +45,8 @@ public class ParticipantRolesTableViewModel : DeprecatableDataItemTableViewModel /// /// The /// The - /// The - /// The + /// The + /// The public ParticipantRolesTableViewModel(ISessionService sessionService, IShowHideDeprecatedThingsService showHideDeprecatedThingsService, ICDPMessageBus messageBus, ILogger logger) : base(sessionService, messageBus, showHideDeprecatedThingsService, logger) { @@ -59,29 +59,38 @@ public ParticipantRolesTableViewModel(ISessionService sessionService, IShowHideD public IEnumerable ParticipantAccessKinds { get; private set; } = [ParticipantAccessRightKind.NONE, ParticipantAccessRightKind.MODIFY, ParticipantAccessRightKind.MODIFY_IF_OWNER, ParticipantAccessRightKind.READ]; /// - /// Creates or edits a + /// Creates or edits a /// - /// The value to check if a new should be created - /// A + /// The value to check if a new should be created + /// A public async Task CreateOrEditParticipantRole(bool shouldCreate) { - this.IsLoading = true; + try + { + this.IsLoading = true; - var siteDirectoryClone = this.SessionService.GetSiteDirectory().Clone(false); - var thingsToCreate = new List(); + var siteDirectoryClone = this.SessionService.GetSiteDirectory().Clone(false); + var thingsToCreate = new List(); - thingsToCreate.AddRange(this.CurrentThing.ParticipantPermission); + thingsToCreate.AddRange(this.CurrentThing.ParticipantPermission); - if (shouldCreate) + if (shouldCreate) + { + siteDirectoryClone.ParticipantRole.Add(this.CurrentThing); + thingsToCreate.Add(siteDirectoryClone); + } + + thingsToCreate.Add(this.CurrentThing); + await this.SessionService.CreateOrUpdateThingsWithNotification(siteDirectoryClone, thingsToCreate, this.GetNotificationDescription(shouldCreate)); + } + catch (Exception ex) { - siteDirectoryClone.ParticipantRole.Add(this.CurrentThing); - thingsToCreate.Add(siteDirectoryClone); + this.Logger.LogError(ex, "Create or Update ParticipantRole failed"); + } + finally + { + this.IsLoading = false; } - - thingsToCreate.Add(this.CurrentThing); - await this.SessionService.CreateOrUpdateThingsWithNotification(siteDirectoryClone, thingsToCreate, this.GetNotificationDescription(shouldCreate)); - - this.IsLoading = false; } ///