Skip to content

Commit

Permalink
Feat #576 [SiteDirectory/ServerAdmin] split Person roles and Particia…
Browse files Browse the repository at this point in the history
…pnt roles in 2 dedicated pages (#581)
  • Loading branch information
joao4all authored Apr 17, 2024
1 parent 8125e3f commit 01c15f9
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace COMETwebapp.Tests.Components.SiteDirectory.Roles

using DynamicData;

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;

using Moq;

Expand All @@ -56,7 +56,6 @@ public class ParticipantRolesTableTestFixture
private IRenderedComponent<ParticipantRolesTable> renderer;
private Mock<IParticipantRolesTableViewModel> viewModel;
private ParticipantRole participantRole1;
private bool wasRoleSelected;

[SetUp]
public void SetUp()
Expand All @@ -76,17 +75,11 @@ public void SetUp()

this.viewModel.Setup(x => x.Rows).Returns(rows);
this.viewModel.Setup(x => x.Thing).Returns(this.participantRole1);
this.context.ConfigureDevExpressBlazor();

this.renderer = this.context.RenderComponent<ParticipantRolesTable>(parameters =>
{
parameters.Add(p => p.ViewModel, this.viewModel.Object);
this.context.Services.AddSingleton(this.viewModel.Object);
this.context.ConfigureDevExpressBlazor();

parameters.Add(p => p.OnRoleSelected, new EventCallbackFactory().Create<ParticipantRole>(this, () =>
{
this.wasRoleSelected = true;
}));
});
this.renderer = this.context.RenderComponent<ParticipantRolesTable>();
}

[TearDown]
Expand Down Expand Up @@ -124,13 +117,20 @@ public async Task VerifyAddParticipantRoleClick()
[Test]
public async Task VerifyRowClick()
{
Assert.That(this.wasRoleSelected, Is.EqualTo(false));
Assert.That(this.renderer.Instance.IsRoleSelected, Is.EqualTo(false));

var firstRow = this.viewModel.Object.Rows.Items.First();
var grid = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(async () => await grid.Instance.SelectedDataItemChanged.InvokeAsync(firstRow));

Assert.That(this.wasRoleSelected, Is.EqualTo(true));
Assert.That(this.renderer.Instance.IsRoleSelected, Is.EqualTo(true));

var details = this.renderer.FindComponent<ParticipantRoleDetails>();
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.IsRoleSelected, Is.EqualTo(false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace COMETwebapp.Tests.Components.SiteDirectory.Roles

using DynamicData;

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;

using Moq;

Expand All @@ -56,7 +56,6 @@ public class PersonRolesTableTestFixture
private IRenderedComponent<PersonRolesTable> renderer;
private Mock<IPersonRolesTableViewModel> viewModel;
private PersonRole personRole;
private bool wasRoleSelected;

[SetUp]
public void SetUp()
Expand All @@ -76,17 +75,11 @@ public void SetUp()

this.viewModel.Setup(x => x.Rows).Returns(rows);
this.viewModel.Setup(x => x.Thing).Returns(this.personRole);
this.context.ConfigureDevExpressBlazor();

this.renderer = this.context.RenderComponent<PersonRolesTable>(parameters =>
{
parameters.Add(p => p.ViewModel, this.viewModel.Object);
this.context.Services.AddSingleton(this.viewModel.Object);
this.context.ConfigureDevExpressBlazor();

parameters.Add(p => p.OnRoleSelected, new EventCallbackFactory().Create<PersonRole>(this, () =>
{
this.wasRoleSelected = true;
}));
});
this.renderer = this.context.RenderComponent<PersonRolesTable>();
}

[TearDown]
Expand Down Expand Up @@ -124,13 +117,20 @@ public async Task VerifyAddPersonRoleClick()
[Test]
public async Task VerifyRowClick()
{
Assert.That(this.wasRoleSelected, Is.EqualTo(false));
Assert.That(this.renderer.Instance.IsRoleSelected, Is.EqualTo(false));

var firstRow = this.viewModel.Object.Rows.Items.First();
var grid = this.renderer.FindComponent<DxGrid>();
await this.renderer.InvokeAsync(async () => await grid.Instance.SelectedDataItemChanged.InvokeAsync(firstRow));

Assert.That(this.wasRoleSelected, Is.EqualTo(true));
Assert.That(this.renderer.Instance.IsRoleSelected, Is.EqualTo(true));

var details = this.renderer.FindComponent<PersonRoleDetails>();
await this.renderer.InvokeAsync(details.Instance.OnSubmit.InvokeAsync);
this.viewModel.Verify(x => x.CreateOrEditPersonRole(false), Times.Once);

await this.renderer.InvokeAsync(details.Instance.OnCancel.InvokeAsync);
Assert.That(this.renderer.Instance.IsRoleSelected, Is.EqualTo(false));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,59 @@ Copyright (c) 2023-2024 RHEA System S.A.
@inherits SelectedDeprecatableDataItemBase<ParticipantRole, ParticipantRoleRowViewModel>

<LoadingComponent IsVisible="@(this.ViewModel.IsLoading)">
<h3>Participant Roles</h3>
<DxGrid @ref="this.Grid"
Data="this.ViewModel.Rows.Items"
ColumnResizeMode="GridColumnResizeMode.ColumnsContainer"
ShowSearchBox="true"
SearchBoxNullText="Search for a participant role..."
AllowSelectRowByClick="true"
SelectedDataItemChanged="@(async row => await this.OnSelectedDataItemChanged((ParticipantRoleRowViewModel)row))"
PopupEditFormCssClass="pw-800"
PopupEditFormHeaderText="Participant Role"
CustomizeElement="DisableDeprecatedThing"
CustomizeEditModel="this.CustomizeEditThing"
EditMode="GridEditMode.PopupEditForm"
EditModelSaving="@(() => this.OnEditThingSaving())"
EditFormButtonsVisible="false"
PageSize="20"
PagerNavigationMode="PagerNavigationMode.Auto"
PageSizeSelectorVisible="true"
PageSizeSelectorItems="@(new[] { 20, 35, 50 })"
PageSizeSelectorAllRowsItemVisible="true"
CssClass="d-inline">
<Columns>
<DxGridDataColumn FieldName="@nameof(ParticipantRoleRowViewModel.Name)" MinWidth="150"/>
<DxGridDataColumn FieldName="@nameof(ParticipantRoleRowViewModel.ShortName)" MinWidth="80"/>
<DxGridDataColumn FieldName="@nameof(ParticipantRoleRowViewModel.IsDeprecated)" MinWidth="80" Visible="false"/>
<DxGridCommandColumn Width="200px" EditButtonVisible="false" DeleteButtonVisible="false">
<HeaderTemplate>
<DxButton Id="addParticipantRoleButton" Text="Add Participant Role" IconCssClass="oi oi-plus" Click="() => this.Grid.StartEditNewRowAsync()"/>
</HeaderTemplate>
</DxGridCommandColumn>
</Columns>
<div style="display: flex; justify-content: space-between;">
<DxGrid @ref="this.Grid"
Data="this.ViewModel.Rows.Items"
ColumnResizeMode="GridColumnResizeMode.ColumnsContainer"
ShowSearchBox="true"
SearchBoxNullText="Search for a participant role..."
AllowSelectRowByClick="true"
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"
PageSize="20"
PagerNavigationMode="PagerNavigationMode.Auto"
PageSizeSelectorVisible="true"
PageSizeSelectorItems="@(new[] { 20, 35, 50 })"
PageSizeSelectorAllRowsItemVisible="true"
CssClass="d-inline">
<Columns>
<DxGridDataColumn FieldName="@nameof(ParticipantRoleRowViewModel.Name)" MinWidth="150"/>
<DxGridDataColumn FieldName="@nameof(ParticipantRoleRowViewModel.ShortName)" MinWidth="80"/>
<DxGridDataColumn FieldName="@nameof(ParticipantRoleRowViewModel.IsDeprecated)" MinWidth="80" Visible="false"/>
<DxGridCommandColumn Width="200px" EditButtonVisible="false" DeleteButtonVisible="false">
<HeaderTemplate>
<DxButton Id="addParticipantRoleButton" Text="Add Participant Role" IconCssClass="oi oi-plus" Click="() => this.Grid.StartEditNewRowAsync()"/>
</HeaderTemplate>
</DxGridCommandColumn>
</Columns>

<EditFormTemplate Context="EditFormContext">
<ParticipantRoleDetails ViewModel="@this.ViewModel"
OnSubmit="@(async () => await this.Grid.SaveChangesAsync())"
OnCancel="@(async () => await this.Grid.CancelEditAsync())"/>
</EditFormTemplate>
<EditFormTemplate Context="EditFormContext">
<ParticipantRoleDetails ViewModel="@this.ViewModel"
OnSubmit="@(async () => await this.Grid.SaveChangesAsync())"
OnCancel="@(async () => await this.Grid.CancelEditAsync())"/>
</EditFormTemplate>

<CustomValidators>
<FluentValidationValidator/>
</CustomValidators>
<CustomValidators>
<FluentValidationValidator/>
</CustomValidators>

</DxGrid>
<div class="pb-3"></div>
</DxGrid>

@if (this.IsRoleSelected)
{
<div style="width: 70%; padding: 30px;">
<ParticipantRoleDetails ViewModel="@this.ViewModel"
OnCancel="@(() => this.IsRoleSelected = false)"
OnSubmit="@(() => this.ViewModel.CreateOrEditParticipantRole(false))"/>
</div>
}
</div>
</LoadingComponent>

<DxPopup @bind-Visible="@(this.ViewModel.IsOnDeprecationMode)" HeaderText="Please confirm" Width="auto" CloseOnOutsideClick="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

namespace COMETwebapp.Components.SiteDirectory.Roles
{
using System.ComponentModel.DataAnnotations;

using CDP4Common.SiteDirectoryData;

using COMETwebapp.Components.Common;
Expand All @@ -44,14 +42,13 @@ public partial class ParticipantRolesTable : SelectedDeprecatableDataItemBase<Pa
/// <summary>
/// The <see cref="IParticipantRolesTableViewModel" /> for this component
/// </summary>
[Parameter, Required]
[Inject]
public IParticipantRolesTableViewModel ViewModel { get; set; }

/// <summary>
/// The callback for when a participant role is selected
/// Gets the value to check if a role has been selected
/// </summary>
[Parameter]
public EventCallback<ParticipantRole> OnRoleSelected { get; set; }
public bool IsRoleSelected { get; private set; }

/// <summary>
/// Method invoked when the component is ready to start, having received its
Expand Down Expand Up @@ -85,13 +82,13 @@ protected override void CustomizeEditThing(GridCustomizeEditModelEventArgs e)
}

/// <summary>
/// Metgid invoked everytime a row is selected
/// Method invoked everytime a row is selected
/// </summary>
/// <param name="row">The selected row</param>
private async Task OnSelectedDataItemChanged(ParticipantRoleRowViewModel row)
private void OnSelectedDataItemChanged(ParticipantRoleRowViewModel row)
{
this.ViewModel.Thing = row.Thing.Clone(true);
await this.OnRoleSelected.InvokeAsync(row.Thing);
this.IsRoleSelected = true;
}
}
}
Loading

0 comments on commit 01c15f9

Please sign in to comment.