From 91bff3c127c4581886fff50efee0bdbb1a49000c Mon Sep 17 00:00:00 2001 From: Andre Beging Date: Fri, 28 Mar 2025 19:22:51 +0100 Subject: [PATCH] InteractionModal umstellen --- .../Controls/ProspectContainer.razor.cs | 32 ++- .../Controls/ProspectGrid.razor | 9 +- .../Dialogs/AddInteractionModal.razor | 90 +++---- .../Dialogs/AddInteractionModal.razor.cs | 221 +++++++++++------- .../Pages/Prospects.razor | 9 +- .../Pages/Prospects.razor.cs | 43 ---- .../Pages/ProspectsVerify.razor | 16 +- .../Pages/ProspectsVerify.razor.cs | 20 -- 8 files changed, 205 insertions(+), 235 deletions(-) diff --git a/FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs b/FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs index fa00772..6d62557 100644 --- a/FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs +++ b/FoodsharingSiegen.Server/Controls/ProspectContainer.razor.cs @@ -1,4 +1,5 @@ using FoodsharingSiegen.Contracts.Entity; +using FoodsharingSiegen.Server.Data.Service; using FoodsharingSiegen.Server.Dialogs; using Microsoft.AspNetCore.Components; @@ -8,18 +9,17 @@ namespace FoodsharingSiegen.Server.Controls { [Parameter] public Prospect? Prospect { get; set; } - [Parameter] public AddInteractionModal InteractionModal { get; set; } = null!; - - [Parameter] public Func? RemoveInteraction { get; set; } - [Parameter] public ProspectStateFilter StateFilter { get; set; } [Parameter] public string? CssClass { get; set; } + + [Parameter] public Func? OnDataChanged { get; set; } private async Task AddInteraction(InteractionType type) { - await InteractionModal.ShowAsync(type, Prospect?.Id); + if (Prospect != null && OnDataChanged != null) + await AddInteractionModal.ShowAsync(ModalService, OnDataChanged, type, Prospect.Id); } private List GetTyped(InteractionType type) @@ -31,5 +31,27 @@ namespace FoodsharingSiegen.Server.Controls { await EditProspectDialog.ShowAsync(ModalService, () => InvokeAsync(StateHasChanged), Prospect); } + + /// + /// Gets or sets the value of the prospect service (ab) + /// + [Inject] + public ProspectService ProspectService { get; set; } = null!; + + private async Task RemoveInteraction(Guid arg) + { + var confirm = await Message.Confirm("Interaktion wirklich löschen?", "Bestätigen", o => + { + o.ConfirmButtonText = "Ja, wirklich!"; + o.CancelButtonText = "Abbrechen"; + o.ShowMessageIcon = false; + }); + + if (confirm) + { + var removeR = await ProspectService.RemoveInteraction(arg); + if(removeR.Success && OnDataChanged != null) await OnDataChanged(); + } + } } } \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Controls/ProspectGrid.razor b/FoodsharingSiegen.Server/Controls/ProspectGrid.razor index a588208..5fb9440 100644 --- a/FoodsharingSiegen.Server/Controls/ProspectGrid.razor +++ b/FoodsharingSiegen.Server/Controls/ProspectGrid.razor @@ -3,12 +3,10 @@ @code { [Parameter] public List? Prospects { get; set; } - - [Parameter] public Func? OnRemoveInteraction { get; set; } - - [Parameter] public AddInteractionModal InteractionModal { get; set; } = null!; [Parameter] public ProspectStateFilter StateFilter { get; set; } + + [Parameter] public Func? OnDataChanged { get; set; } }
@(Prospects?.Count ?? 0) Einträge
@@ -19,8 +17,7 @@ diff --git a/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor b/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor index 3287bf3..e043383 100644 --- a/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor +++ b/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor @@ -1,61 +1,37 @@ -@using FoodsharingSiegen.Contracts.Entity +@inherits FsBase -@inherits FsBase +@if (ShowNotNeeded) +{ +
+
+ + Nicht benötigt + +
+
+ + Achtung! + +
+
+} - - - -
@_header
- -
- - @if (_showNotNeeded) - { -
-
- - Nicht benötigt - -
-
- - Achtung! - -
-
- } +
+
+ + Wann? + + +
+
-
- @*
*@ - @* *@ - @* Wer? *@ - @* *@ - @* *@ - @*
*@ -
- - Wann? - - -
-
+@if (ShowInfo) +{ + + @InfoName + + +} - @if (_showInfo) - { - - @_infoName - - - } -
- - - - -
-
\ No newline at end of file + + \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor.cs b/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor.cs index 9ce3b95..8d6f609 100644 --- a/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor.cs +++ b/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor.cs @@ -1,104 +1,151 @@ using Blazorise; using FoodsharingSiegen.Contracts.Entity; -using FoodsharingSiegen.Contracts.Model; +using FoodsharingSiegen.Server.BaseClasses; +using FoodsharingSiegen.Server.Data.Service; using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Options; namespace FoodsharingSiegen.Server.Dialogs { - public partial class AddInteractionModal + public partial class AddInteractionModal : FsBase { - private Modal ModalReference { get; set; } = null!; - - private Interaction Interaction { get; set; } = new(); - - [Parameter] - public EventCallback OnAdd { get; set; } + #region Dependencies - [Parameter] - public List? Users { get; set; } + /// + /// Gets or sets the value of the prospect service (ab) + /// + [Inject] + public ProspectService ProspectService { get; set; } = null!; - public Guid SelectedUser { get; set; } + #endregion - private string? _header; - private string? _infoName; - private bool _showInfo; - private bool _showAlert; - private bool _showNotNeeded; + #region Parameters - protected override async Task OnParametersSetAsync() + [Parameter] + public string? InfoName { get; set; } + + [Parameter] + public Interaction Interaction { get; set; } = new(); + + [Parameter] + public Func? OnSuccess { get; set; } + + [Parameter] + public bool ShowAlert { get; set; } + + [Parameter] + public bool ShowInfo { get; set; } + + [Parameter] + public bool ShowNotNeeded { get; set; } + + #endregion + + #region Public Method ShowAsync + + /// + /// Displays a modal dialog for adding an interaction with configurable settings based on the interaction type and associated prospect ID. + /// + /// + /// The modal service used to display the modal dialog. + /// + /// + /// Callback to be invoked upon successful addition of an interaction + /// + /// + /// The type of interaction to be added. + /// + /// + /// The unique identifier of the prospect associated with the interaction. + /// + /// + /// A task representing the asynchronous operation of showing the modal dialog. + /// + public static async Task ShowAsync(IModalService modalService, Func onSuccess, InteractionType type, Guid prospectId) + { + var headerText = type switch { - if (Users?.Any() == true) SelectedUser = Users.First().Id; - - await base.OnParametersSetAsync(); - } + InteractionType.EinAb => "Einführung eintragen", + InteractionType.Welcome => "Begrüßung eintragen", + InteractionType.IdCheck => "Ausweisprüfung eintragen", + InteractionType.PrintPass => "FS-Ausweis (Print)", + InteractionType.PdfPass => "FS-Ausweis (PDF)", + InteractionType.Verify => "Verifizierung eintragen", + InteractionType.Complete => "Als fertig markieren", + InteractionType.StepInBriefing => $"Neulingstreffen absolviert", + InteractionType.ReleasedForVerification => "Zur Verifizierung freigegeben", + _ => "Neuer Eintrag" + }; - public async Task ShowAsync(InteractionType type, Guid? prospectId) + var showInfo = type switch { - if (prospectId == null) return; - _showInfo = false; - _showNotNeeded = false; - _showAlert = false; - _infoName = "Kommentar"; - - switch (type) - { - case InteractionType.EinAb: - _header = "Einführung eintragen"; - _showInfo = true; - _showAlert = true; - _infoName = "Welcher Betrieb?"; - break; - case InteractionType.Welcome: - _header = "Begrüßung eintragen"; - break; - case InteractionType.IdCheck: - _header = "Ausweisprüfung eintragen"; - _showAlert = true; - _showInfo = true; - break; - case InteractionType.PrintPass: - _header = "FS-Ausweis (Print)"; - _showNotNeeded = true; - _showInfo = true; - break; - case InteractionType.PdfPass: - _header = "FS-Ausweis (PDF)"; - _showNotNeeded = true; - _showInfo = true; - break; - case InteractionType.Verify: - _header = "Verifizierung eintragen"; - break; - case InteractionType.Complete: - _header = "Als fertig markieren"; - _showInfo = true; - break; - case InteractionType.StepInBriefing: - _header = $"{AppSettings.Terms.StepInName} absolviert"; - break; - case InteractionType.ReleasedForVerification: - _header = "Zur Verifizierung freigegeben"; - _showInfo = true; - _infoName = "Hinweis"; - break; - } - - Interaction = new Interaction - { - Type = type, - Date = DateTime.UtcNow, - ProspectID = prospectId.Value - }; - await ModalReference.Show(); - } - - private async Task AddInteraction() + InteractionType.EinAb => true, + InteractionType.Complete => true, + InteractionType.IdCheck => true, + InteractionType.PrintPass => true, + InteractionType.PdfPass => true, + InteractionType.ReleasedForVerification => true, + _ => false + }; + + var infoName = type switch { - Interaction.UserID = SelectedUser; - - await OnAdd.InvokeAsync(Interaction); - await ModalReference.Hide(); - } + InteractionType.EinAb => "Welcher Betrieb?", + InteractionType.ReleasedForVerification => "Hinweis", + _ => "Kommentar" + }; + + var showAlert = type switch + { + InteractionType.EinAb => true, + InteractionType.IdCheck => true, + _ => false + }; + + var showNotNeeded = type switch + { + InteractionType.PrintPass => true, + InteractionType.PdfPass => true, + _ => false + }; + + var interaction = new Interaction + { + Type = type, + Date = DateTime.UtcNow, + ProspectID = prospectId + }; + + await modalService.Show(headerText, parameter => + { + parameter.Add(nameof(Interaction), interaction); + parameter.Add(nameof(ShowInfo), showInfo); + parameter.Add(nameof(InfoName), infoName); + parameter.Add(nameof(ShowAlert), showAlert); + parameter.Add(nameof(ShowNotNeeded), showNotNeeded); + parameter.Add(nameof(OnSuccess), onSuccess); + }); + } + + #endregion + + #region Private Method AddInteractionAsync + + /// + /// Adds a new interaction for the current user using the ProspectService and hides the modal. + /// + /// + /// A task representing the asynchronous operation. + /// + private async Task AddInteractionAsync() + { + Interaction.UserID = CurrentUser.Id; + + var addR = await ProspectService.AddInteraction(Interaction); + if (addR.Success && OnSuccess != null) await OnSuccess.Invoke(); + + await ModalService.Hide(); + } + + #endregion } } \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Pages/Prospects.razor b/FoodsharingSiegen.Server/Pages/Prospects.razor index cc5cae8..315dd52 100644 --- a/FoodsharingSiegen.Server/Pages/Prospects.razor +++ b/FoodsharingSiegen.Server/Pages/Prospects.razor @@ -24,9 +24,6 @@
- - - \ No newline at end of file + OnDataChanged="@LoadProspects" + StateFilter="ProspectStateFilter.OnBoarding"> + \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Pages/Prospects.razor.cs b/FoodsharingSiegen.Server/Pages/Prospects.razor.cs index 58c190e..c19059e 100644 --- a/FoodsharingSiegen.Server/Pages/Prospects.razor.cs +++ b/FoodsharingSiegen.Server/Pages/Prospects.razor.cs @@ -97,49 +97,6 @@ namespace FoodsharingSiegen.Server.Pages #endregion - #region Private Method OnAddInteraction - - /// - /// Ons the add interaction using the specified arg (a. beging, 11.04.2022) - /// - /// The arg - private async Task OnAddInteraction(Interaction arg) - { - arg.UserID = CurrentUser.Id; - await ProspectService.AddInteraction(arg); - await LoadProspects(); - } - - #endregion - - #region Private Method OnAddProspect - - /// - /// Ons the add prospect using the specified arg (a. beging, 11.04.2022) - /// - /// The arg - private async Task OnAddProspect(Prospect arg) - { - var addProspectR = await ProspectService.AddProspectAsync(arg); - if (addProspectR.Success) await LoadProspects(); - } - - #endregion - - #region Private Method OnUpdateProspect - - /// - /// Ons the update prospect using the specified prospect (a. beging, 11.04.2022) - /// - /// The prospect - private async Task OnUpdateProspect(Prospect prospect) - { - var updateProspectR = await ProspectService.UpdateAsync(prospect); - if (updateProspectR.Success) await LoadProspects(); - } - - #endregion - #region Private Method RemoveInteractionAsync /// diff --git a/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor b/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor index 824fa11..fb6e605 100644 --- a/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor +++ b/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor @@ -14,14 +14,8 @@

-
@(filterList.Count) Einträge
-@if (filterList.Any()) -{ -
- - - -
-} - - \ No newline at end of file + + \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor.cs b/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor.cs index 6fd4e56..c2772ed 100644 --- a/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor.cs +++ b/FoodsharingSiegen.Server/Pages/ProspectsVerify.razor.cs @@ -31,11 +31,6 @@ namespace FoodsharingSiegen.Server.Pages private ProspectFilter Filter { get; set; } = new(); - /// - /// Gets or sets the value of the interaction modal (ab) - /// - private AddInteractionModal? InteractionModal { get; set; } - /// /// Gets or sets the value of the prospect list (ab) /// @@ -84,21 +79,6 @@ namespace FoodsharingSiegen.Server.Pages #endregion - #region Private Method OnAddInteraction - - /// - /// Ons the add interaction using the specified arg (a. beging, 11.04.2022) - /// - /// The arg - private async Task OnAddInteraction(Interaction arg) - { - arg.UserID = CurrentUser.Id; - await ProspectService.AddInteraction(arg); - await LoadProspects(); - } - - #endregion - #region Private Method OnUpdateProspect ///