Move edit prospect dialog logic
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
</Router>
|
||||
|
||||
<MessageAlert/>
|
||||
<ModalProvider Centered="true" />
|
||||
</Blazorise.ThemeProvider>
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,12 @@ namespace FoodsharingSiegen.Server.BaseClasses
|
||||
[Inject]
|
||||
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>
|
||||
/// Gets or sets the value of the navigation manager (ab)
|
||||
/// </summary>
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
<div class="@divClass">
|
||||
<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
|
||||
@@ -28,7 +28,6 @@
|
||||
</Alert>
|
||||
}
|
||||
|
||||
|
||||
<table style="width: 100%;">
|
||||
|
||||
<InteractionRow
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace FoodsharingSiegen.Server.Controls
|
||||
|
||||
[Parameter] public AddInteractionModal InteractionModal { get; set; } = null!;
|
||||
|
||||
[Parameter] public AddProspectModal? ProspectModal { get; set; } = null!;
|
||||
|
||||
[Parameter] public Func<Guid, Task>? RemoveInteraction { get; set; }
|
||||
|
||||
[Parameter] public ProspectStateFilter StateFilter { get; set; }
|
||||
@@ -26,7 +24,12 @@ namespace FoodsharingSiegen.Server.Controls
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,7 @@
|
||||
[Parameter] public Func<Guid, Task>? OnRemoveInteraction { get; set; }
|
||||
|
||||
[Parameter] public AddInteractionModal InteractionModal { get; set; } = null!;
|
||||
|
||||
[Parameter] public AddProspectModal? ProspectModal { get; set; } = null!;
|
||||
|
||||
|
||||
[Parameter] public ProspectStateFilter StateFilter { get; set; }
|
||||
|
||||
}
|
||||
@@ -22,7 +20,6 @@
|
||||
<ProspectContainer
|
||||
Prospect="context"
|
||||
InteractionModal="@InteractionModal"
|
||||
ProspectModal="@ProspectModal"
|
||||
RemoveInteraction="OnRemoveInteraction"
|
||||
StateFilter="StateFilter"></ProspectContainer>
|
||||
</Repeater>
|
||||
|
||||
@@ -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>
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
28
FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor
Normal file
28
FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor
Normal 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>
|
||||
106
FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs
Normal file
106
FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<Button
|
||||
Color="Color.Primary"
|
||||
Clicked="() => ProspectModal.Show()"
|
||||
Clicked="@CreateProspectAsync"
|
||||
Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
|
||||
>Hinzufügen
|
||||
</Button>
|
||||
@@ -26,9 +26,7 @@
|
||||
Prospects="filterList"
|
||||
OnRemoveInteraction="RemoveInteractionAsync"
|
||||
StateFilter="ProspectStateFilter.OnBoarding"
|
||||
InteractionModal="InteractionModal"
|
||||
ProspectModal="@ProspectModal">
|
||||
InteractionModal="InteractionModal">
|
||||
</ProspectGrid>
|
||||
|
||||
<AddProspectModal @ref="ProspectModal" OnAdd="OnAddProspect" OnUpdate="OnUpdateProspect"></AddProspectModal>
|
||||
<AddInteractionModal @ref="InteractionModal" OnAdd="OnAddInteraction" Users="Users"></AddInteractionModal>
|
||||
@@ -30,7 +30,7 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
#region Private Properties
|
||||
|
||||
private ProspectFilter Filter { get; set; } = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the interaction modal (ab)
|
||||
/// </summary>
|
||||
@@ -41,11 +41,6 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
/// </summary>
|
||||
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>
|
||||
/// Gets or sets the value of the users (ab)
|
||||
/// </summary>
|
||||
@@ -69,6 +64,19 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
|
||||
#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
|
||||
|
||||
/// <summary>
|
||||
@@ -80,7 +88,7 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
{
|
||||
CannotHaveInteractions = [InteractionType.Complete, InteractionType.Verify, InteractionType.ReleasedForVerification]
|
||||
};
|
||||
|
||||
|
||||
var prospectsR = await ProspectService.GetProspectsAsync(parameter);
|
||||
if (prospectsR.Success) ProspectList = prospectsR.Data;
|
||||
|
||||
@@ -132,7 +140,7 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method RemoveInteraction
|
||||
#region Private Method RemoveInteractionAsync
|
||||
|
||||
/// <summary>
|
||||
/// Removes the interaction using the specified arg (a. beging, 11.04.2022)
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
@using FoodsharingSiegen.Shared.Helper
|
||||
@inherits FsBase
|
||||
|
||||
<PageTitle>Abgeschlossene Einarbeitungen - @AppSettings.Terms.Title</PageTitle>
|
||||
<h2>Abgeschlossene Einarbeitungen</h2>
|
||||
<PageTitle>Abgeschlossen - @AppSettings.Terms.Title</PageTitle>
|
||||
<h2>Abgeschlossen</h2>
|
||||
|
||||
@{
|
||||
var filterList = ProspectList.ApplyFilter(Filter);
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
{
|
||||
<div class="row m-0">
|
||||
<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>
|
||||
</div>
|
||||
}
|
||||
|
||||
<AddProspectModal @ref="ProspectModal" OnUpdate="OnUpdateProspect"></AddProspectModal>
|
||||
<AddInteractionModal @ref="InteractionModal" OnAdd="OnAddInteraction" Users="Users"></AddInteractionModal>
|
||||
@@ -40,9 +40,7 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
/// Gets or sets the value of the prospect list (ab)
|
||||
/// </summary>
|
||||
private List<Prospect>? ProspectList { get; set; }
|
||||
|
||||
private AddProspectModal? ProspectModal { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the users (ab)
|
||||
/// </summary>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"DetailedErrors": true,
|
||||
"Settings": {
|
||||
"Terms": {
|
||||
"Title": "Foodsharing Musterhausen",
|
||||
|
||||
Reference in New Issue
Block a user