Move edit prospect dialog logic

This commit is contained in:
Andre Beging
2025-03-28 18:49:38 +01:00
parent 97deed7d90
commit d754da76cd
15 changed files with 173 additions and 170 deletions

View File

@@ -14,6 +14,7 @@
</Router> </Router>
<MessageAlert/> <MessageAlert/>
<ModalProvider Centered="true" />
</Blazorise.ThemeProvider> </Blazorise.ThemeProvider>

View File

@@ -37,6 +37,12 @@ namespace FoodsharingSiegen.Server.BaseClasses
[Inject] [Inject]
protected IMessageService Message { get; set; } = null!; protected IMessageService Message { get; set; } = null!;
/// <summary>
/// Gets or sets the modal service for handling modals within the application
/// </summary>
[Inject]
protected IModalService ModalService { get; set; } = null!;
/// <summary> /// <summary>
/// Gets or sets the value of the navigation manager (ab) /// Gets or sets the value of the navigation manager (ab)
/// </summary> /// </summary>

View File

@@ -7,9 +7,9 @@
<div class="@divClass"> <div class="@divClass">
<h5 class="mb-0"> <h5 class="mb-0">
@if (ProspectModal != null && CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador)) @if (CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))
{ {
<a href=""><i class="fa-solid fa-pen-to-square" @onclick="() => ProspectModal.Show(Prospect)" @onclick:preventDefault></i> </a> <a href=""><i class="fa-solid fa-pen-to-square" @onclick="EditProspectAsync" @onclick:preventDefault></i> </a>
} }
@Prospect?.Name @Prospect?.Name
@@ -28,7 +28,6 @@
</Alert> </Alert>
} }
<table style="width: 100%;"> <table style="width: 100%;">
<InteractionRow <InteractionRow

View File

@@ -10,8 +10,6 @@ namespace FoodsharingSiegen.Server.Controls
[Parameter] public AddInteractionModal InteractionModal { get; set; } = null!; [Parameter] public AddInteractionModal InteractionModal { get; set; } = null!;
[Parameter] public AddProspectModal? ProspectModal { get; set; } = null!;
[Parameter] public Func<Guid, Task>? RemoveInteraction { get; set; } [Parameter] public Func<Guid, Task>? RemoveInteraction { get; set; }
[Parameter] public ProspectStateFilter StateFilter { get; set; } [Parameter] public ProspectStateFilter StateFilter { get; set; }
@@ -26,7 +24,12 @@ namespace FoodsharingSiegen.Server.Controls
private List<Interaction> GetTyped(InteractionType type) private List<Interaction> GetTyped(InteractionType type)
{ {
return Prospect?.Interactions?.Where(x => x.Type == type).ToList() ?? new List<Interaction>(); return Prospect?.Interactions?.Where(x => x.Type == type).ToList() ?? [];
}
private async Task EditProspectAsync()
{
await EditProspectDialog.ShowAsync(ModalService, () => InvokeAsync(StateHasChanged), Prospect);
} }
} }
} }

View File

@@ -8,8 +8,6 @@
[Parameter] public AddInteractionModal InteractionModal { get; set; } = null!; [Parameter] public AddInteractionModal InteractionModal { get; set; } = null!;
[Parameter] public AddProspectModal? ProspectModal { get; set; } = null!;
[Parameter] public ProspectStateFilter StateFilter { get; set; } [Parameter] public ProspectStateFilter StateFilter { get; set; }
} }
@@ -22,7 +20,6 @@
<ProspectContainer <ProspectContainer
Prospect="context" Prospect="context"
InteractionModal="@InteractionModal" InteractionModal="@InteractionModal"
ProspectModal="@ProspectModal"
RemoveInteraction="OnRemoveInteraction" RemoveInteraction="OnRemoveInteraction"
StateFilter="StateFilter"></ProspectContainer> StateFilter="StateFilter"></ProspectContainer>
</Repeater> </Repeater>

View File

@@ -1,38 +0,0 @@
@using FoodsharingSiegen.Contracts.Entity
<Modal @ref="@ModalReference">
<ModalContent Centered Size="ModalSize.Default">
<ModalHeader>
<ModalTitle>@Header</ModalTitle>
<CloseButton/>
</ModalHeader>
<ModalBody>
<div class="row">
<div class="col">
<Field>
<FieldLabel>Name</FieldLabel>
<TextEdit @bind-Text="Prospect.Name"/>
</Field>
</div>
<div class="col">
<Field>
<FieldLabel>Foodsharing-ID</FieldLabel>
<NumericEdit TValue="int" @bind-Value="Prospect.FsId"></NumericEdit>
</Field>
</div>
</div>
<Field>
<FieldLabel>Info (optional)</FieldLabel>
<TextEdit @bind-Text="Prospect.Memo" Placeholder="Beliebige Info"></TextEdit>
</Field>
<Field>
<Switch TValue="bool" @bind-Checked="Prospect.Warning">Achtung!</Switch>
</Field>
</ModalBody>
<ModalFooter>
<Button Color="Color.Primary" Clicked="@SaveClick">@SaveButtonText</Button>
</ModalFooter>
</ModalContent>
</Modal>

View File

@@ -1,103 +0,0 @@
using Blazorise;
using FoodsharingSiegen.Contracts.Entity;
using Microsoft.AspNetCore.Components;
namespace FoodsharingSiegen.Server.Dialogs
{
/// <summary>
/// The add prospect modal class (a. beging, 31.05.2022)
/// </summary>
public partial class AddProspectModal
{
#region Parameters
/// <summary>
/// Gets or sets the value of the on add (ab)
/// </summary>
[Parameter]
public EventCallback<Prospect> OnAdd { get; set; }
/// <summary>
/// Gets or sets the value of the on update (ab)
/// </summary>
[Parameter]
public EventCallback<Prospect> OnUpdate { get; set; }
#endregion
#region Private Properties
/// <summary>
/// Gets or sets the value of the header (ab)
/// </summary>
private string? Header { get; set; }
/// <summary>
/// Gets or sets the value of the is update mode (ab)
/// </summary>
private bool IsUpdateMode { get; set; }
/// <summary>
/// Gets or sets the value of the modal reference (ab)
/// </summary>
private Modal ModalReference { get; set; } = null!;
/// <summary>
/// Gets or sets the value of the prospect (ab)
/// </summary>
private Prospect Prospect { get; set; } = new();
/// <summary>
/// Gets or sets the value of the save button text (ab)
/// </summary>
private string? SaveButtonText { get; set; }
#endregion
#region Public Method Show
/// <summary>
/// Shows this instance (a. beging, 31.05.2022)
/// </summary>
public async Task Show()
{
Prospect = new Prospect();
Header = "Neuling hinzufügen";
SaveButtonText = "Hinzufügen";
await ModalReference.Show();
}
/// <summary>
/// Shows the prospect (a. beging, 31.05.2022)
/// </summary>
/// <param name="prospect">The prospect</param>
public async Task Show(Prospect? prospect)
{
if (prospect == null) return;
Prospect = prospect;
IsUpdateMode = true;
Header = $"{Prospect.Name} bearbeiten";
SaveButtonText = "Speichern";
await ModalReference.Show();
}
#endregion
#region Private Method SaveClick
/// <summary>
/// Saves the click (a. beging, 31.05.2022)
/// </summary>
private async Task SaveClick()
{
if (IsUpdateMode)
await OnUpdate.InvokeAsync(Prospect);
else
await OnAdd.InvokeAsync(Prospect);
await ModalReference.Hide();
}
#endregion
}
}

View File

@@ -0,0 +1,28 @@
@using FoodsharingSiegen.Contracts.Entity
@inherits FsBase
<div class="row">
<div class="col">
<Field>
<FieldLabel>Name</FieldLabel>
<TextEdit @bind-Text="Prospect.Name"/>
</Field>
</div>
<div class="col">
<Field>
<FieldLabel>Foodsharing-ID</FieldLabel>
<NumericEdit TValue="int" @bind-Value="Prospect.FsId"></NumericEdit>
</Field>
</div>
</div>
<Field>
<FieldLabel>Info (optional)</FieldLabel>
<TextEdit @bind-Text="Prospect.Memo" Placeholder="Beliebige Info"></TextEdit>
</Field>
<Field>
<Switch TValue="bool" @bind-Checked="Prospect.Warning">Achtung!</Switch>
</Field>
<Button Color="Color.Primary" Clicked="@SaveClick">@SaveButtonText</Button>

View File

@@ -0,0 +1,106 @@
using Blazorise;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Server.BaseClasses;
using FoodsharingSiegen.Server.Data.Service;
using Microsoft.AspNetCore.Components;
namespace FoodsharingSiegen.Server.Dialogs
{
/// <summary>
/// The add prospect modal class (a. beging, 31.05.2022)
/// </summary>
public partial class EditProspectDialog : FsBase
{
#region Dependencies
/// <summary>
/// Gets or sets the value of the prospect service (ab)
/// </summary>
[Inject]
public ProspectService ProspectService { get; set; } = null!;
#endregion
#region Parameters
/// <summary>
/// Gets or sets the value of the is update mode (ab)
/// </summary>
[Parameter]
public bool IsUpdateMode { get; set; }
[Parameter]
public Func<Task>? OnSuccess { get; set; }
/// <summary>
/// Gets or sets the value of the on add (ab)
/// </summary>
[Parameter]
public EventCallback<Prospect> OnAdd { get; set; }
/// <summary>
/// Gets or sets the value of the on update (ab)
/// </summary>
[Parameter]
public EventCallback<Prospect> OnUpdate { get; set; }
/// <summary>
/// Gets or sets the value of the prospect (ab)
/// </summary>
[Parameter]
public Prospect Prospect { get; set; } = new();
/// <summary>
/// Gets or sets the value of the save button text (ab)
/// </summary>
[Parameter]
public string? SaveButtonText { get; set; }
#endregion
#region Public Method ShowAsync
/// <summary>
/// Displays the AddProspectModal dialog asynchronously, allowing for the creation or editing of a prospect.
/// </summary>
/// <param name="modalService">The modal service used to display the dialog.</param>
/// <param name="onSuccess">Callback to be invoked upon successful addition or update of a prospect.</param>
/// <param name="prospect">The prospect to be edited, or null for creating a new prospect.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public static async Task ShowAsync(IModalService modalService, Func<Task> onSuccess, Prospect? prospect = null)
{
await modalService.Show<EditProspectDialog>(prospect == null ? "Neuling hinzufügen" : $"{prospect.Name} bearbeiten", p =>
{
p.Add(nameof(Prospect), prospect ?? new Prospect());
p.Add(nameof(IsUpdateMode), prospect != null);
p.Add(nameof(SaveButtonText), prospect == null ? "Hinzufügen" : "Speichern");
p.Add(nameof(OnSuccess), onSuccess);
});
}
#endregion
#region Private Method SaveClick
/// <summary>
/// Saves the click (a. beging, 31.05.2022)
/// </summary>
private async Task SaveClick()
{
if (IsUpdateMode)
{
var updateR = await ProspectService.UpdateAsync(Prospect);
if (updateR.Success && OnSuccess != null) await OnSuccess.Invoke();
}
else
{
var addR = await ProspectService.AddProspectAsync(Prospect);
if (addR.Success && OnSuccess != null) await OnSuccess.Invoke();
}
await ModalService.Hide();
}
#endregion
}
}

View File

@@ -10,7 +10,7 @@
<Button <Button
Color="Color.Primary" Color="Color.Primary"
Clicked="() => ProspectModal.Show()" Clicked="@CreateProspectAsync"
Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)" Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
>Hinzufügen >Hinzufügen
</Button> </Button>
@@ -26,9 +26,7 @@
Prospects="filterList" Prospects="filterList"
OnRemoveInteraction="RemoveInteractionAsync" OnRemoveInteraction="RemoveInteractionAsync"
StateFilter="ProspectStateFilter.OnBoarding" StateFilter="ProspectStateFilter.OnBoarding"
InteractionModal="InteractionModal" InteractionModal="InteractionModal">
ProspectModal="@ProspectModal">
</ProspectGrid> </ProspectGrid>
<AddProspectModal @ref="ProspectModal" OnAdd="OnAddProspect" OnUpdate="OnUpdateProspect"></AddProspectModal>
<AddInteractionModal @ref="InteractionModal" OnAdd="OnAddInteraction" Users="Users"></AddInteractionModal> <AddInteractionModal @ref="InteractionModal" OnAdd="OnAddInteraction" Users="Users"></AddInteractionModal>

View File

@@ -41,11 +41,6 @@ namespace FoodsharingSiegen.Server.Pages
/// </summary> /// </summary>
private List<Prospect>? ProspectList { get; set; } private List<Prospect>? ProspectList { get; set; }
/// <summary>
/// Gets or sets the value of the prospect modal (ab)
/// </summary>
private AddProspectModal ProspectModal { get; set; } = null!;
/// <summary> /// <summary>
/// Gets or sets the value of the users (ab) /// Gets or sets the value of the users (ab)
/// </summary> /// </summary>
@@ -69,6 +64,19 @@ namespace FoodsharingSiegen.Server.Pages
#endregion #endregion
#region Private Method CreateProspectAsync
/// <summary>
/// Asynchronously creates a new prospect by displaying the AddProspectModal dialog and refreshing the prospect list.
/// </summary>
/// <returns>A task that represents the asynchronous operation.</returns>
private async Task CreateProspectAsync()
{
await EditProspectDialog.ShowAsync(ModalService, LoadProspects);
}
#endregion
#region Private Method LoadProspects #region Private Method LoadProspects
/// <summary> /// <summary>
@@ -132,7 +140,7 @@ namespace FoodsharingSiegen.Server.Pages
#endregion #endregion
#region Private Method RemoveInteraction #region Private Method RemoveInteractionAsync
/// <summary> /// <summary>
/// Removes the interaction using the specified arg (a. beging, 11.04.2022) /// Removes the interaction using the specified arg (a. beging, 11.04.2022)

View File

@@ -3,8 +3,8 @@
@using FoodsharingSiegen.Shared.Helper @using FoodsharingSiegen.Shared.Helper
@inherits FsBase @inherits FsBase
<PageTitle>Abgeschlossene Einarbeitungen - @AppSettings.Terms.Title</PageTitle> <PageTitle>Abgeschlossen - @AppSettings.Terms.Title</PageTitle>
<h2>Abgeschlossene Einarbeitungen</h2> <h2>Abgeschlossen</h2>
@{ @{
var filterList = ProspectList.ApplyFilter(Filter); var filterList = ProspectList.ApplyFilter(Filter);

View File

@@ -19,10 +19,9 @@
{ {
<div class="row m-0"> <div class="row m-0">
<Repeater Items="@filterList"> <Repeater Items="@filterList">
<ProspectContainer Prospect="context" InteractionModal="InteractionModal" ProspectModal="ProspectModal" RemoveInteraction="RemoveInteraction" StateFilter="ProspectStateFilter.Verification"></ProspectContainer> <ProspectContainer Prospect="context" InteractionModal="InteractionModal" RemoveInteraction="RemoveInteraction" StateFilter="ProspectStateFilter.Verification"></ProspectContainer>
</Repeater> </Repeater>
</div> </div>
} }
<AddProspectModal @ref="ProspectModal" OnUpdate="OnUpdateProspect"></AddProspectModal>
<AddInteractionModal @ref="InteractionModal" OnAdd="OnAddInteraction" Users="Users"></AddInteractionModal> <AddInteractionModal @ref="InteractionModal" OnAdd="OnAddInteraction" Users="Users"></AddInteractionModal>

View File

@@ -41,8 +41,6 @@ namespace FoodsharingSiegen.Server.Pages
/// </summary> /// </summary>
private List<Prospect>? ProspectList { get; set; } private List<Prospect>? ProspectList { get; set; }
private AddProspectModal? ProspectModal { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value of the users (ab) /// Gets or sets the value of the users (ab)
/// </summary> /// </summary>

View File

@@ -6,6 +6,7 @@
} }
} }
}, },
"DetailedErrors": true,
"Settings": { "Settings": {
"Terms": { "Terms": {
"Title": "Foodsharing Musterhausen", "Title": "Foodsharing Musterhausen",