Add new filters and refactor InteractionDialog handling
Introduced new filters for prospects: "WithoutIdCheck" and "NoActivity" with associated UI controls. Refactored `InteractionDialog.ShowAsync` to use a new parameter record for cleaner code and better extensibility. These changes enhance usability and maintainability by providing additional filtering options and streamlining dialog interactions.
This commit is contained in:
@@ -5,5 +5,9 @@
|
||||
public string? Text { get; set; }
|
||||
|
||||
public bool WithoutStepInBriefing { get; set; }
|
||||
|
||||
public bool WithoutIdCheck { get; set; }
|
||||
|
||||
public bool NoActivity { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,24 @@ namespace FoodsharingSiegen.Server.Controls
|
||||
private async Task AddInteraction(InteractionType type)
|
||||
{
|
||||
if (Prospect != null && OnDataChanged != null)
|
||||
await InteractionDialog.ShowAsync(ModalService, OnDataChanged, type, Prospect.Id);
|
||||
{
|
||||
var headerText = type switch
|
||||
{
|
||||
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 => $"{AppSettings.Terms.StepInName} absolviert",
|
||||
InteractionType.ReleasedForVerification => "Zur Verifizierung freigegeben",
|
||||
_ => "Neuer Eintrag"
|
||||
};
|
||||
|
||||
await InteractionDialog.ShowAsync(ModalService, new(type, Prospect.Id, headerText, OnDataChanged));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<Interaction> GetTyped(InteractionType type)
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
@inherits FsBase
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public ProspectFilter Filter { get; set; } = new();
|
||||
[Parameter] public ProspectFilter Filter { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<ProspectFilter> FilterChanged { get; set; }
|
||||
[Parameter] public EventCallback<ProspectFilter> FilterChanged { get; set; }
|
||||
|
||||
[Parameter] public ProspectStateFilter StateFilter { get; set; }
|
||||
|
||||
@@ -23,6 +21,18 @@
|
||||
await FilterChanged.InvokeAsync(Filter);
|
||||
}
|
||||
|
||||
private async Task WithoutIdCheckChangedAsync(bool arg)
|
||||
{
|
||||
Filter.WithoutIdCheck = arg;
|
||||
await FilterChanged.InvokeAsync(Filter);
|
||||
}
|
||||
|
||||
private async Task NoActivityChangedAsync(bool arg)
|
||||
{
|
||||
Filter.NoActivity = arg;
|
||||
await FilterChanged.InvokeAsync(Filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
<div class="card">
|
||||
@@ -36,6 +46,18 @@
|
||||
<Switch TValue="bool" Checked="Filter.WithoutStepInBriefing" CheckedChanged="WithoutStepInBriefingChangedAsync">Ohne @AppSettings.Terms.StepInName</Switch>
|
||||
</div>
|
||||
}
|
||||
@if (StateFilter == ProspectStateFilter.Verification)
|
||||
{
|
||||
<div style="margin-left: 1rem;">
|
||||
<Switch TValue="bool" Checked="Filter.WithoutIdCheck" CheckedChanged="WithoutIdCheckChangedAsync">Perso noch nicht geprüft</Switch>
|
||||
</div>
|
||||
}
|
||||
@if (StateFilter is ProspectStateFilter.OnBoarding or ProspectStateFilter.Verification)
|
||||
{
|
||||
<div style="margin-left: 1rem;">
|
||||
<Switch TValue="bool" Checked="Filter.NoActivity" CheckedChanged="NoActivityChangedAsync">Lange keine Aktivität (6 Monate)</Switch>
|
||||
</div>
|
||||
}
|
||||
<TextEdit Text="@Filter.Text" TextChanged="TextChanged" Placeholder="Suchen..." Debounce="true" DebounceInterval="150"/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -6,6 +6,8 @@ using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace FoodsharingSiegen.Server.Dialogs
|
||||
{
|
||||
public record InteractionDialogParameter(InteractionType Type, Guid ProspectId, string HeaderText, Func<Task> OnSuccess);
|
||||
|
||||
public partial class InteractionDialog : FsBase
|
||||
{
|
||||
#region Dependencies
|
||||
@@ -43,40 +45,16 @@ namespace FoodsharingSiegen.Server.Dialogs
|
||||
#region Public Method ShowAsync
|
||||
|
||||
/// <summary>
|
||||
/// Displays a modal dialog for adding an interaction with configurable settings based on the interaction type and associated prospect ID.
|
||||
/// Displays the InteractionDialog modal with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="modalService">
|
||||
/// The modal service used to display the modal dialog.
|
||||
/// </param>
|
||||
/// <param name="onSuccess">
|
||||
/// Callback to be invoked upon successful addition of an interaction
|
||||
/// </param>
|
||||
/// <param name="type">
|
||||
/// The type of interaction to be added.
|
||||
/// </param>
|
||||
/// <param name="prospectId">
|
||||
/// The unique identifier of the prospect associated with the interaction.
|
||||
/// </param>
|
||||
/// <param name="modalService">The modal service used to display the dialog.</param>
|
||||
/// <param name="parameter">The parameters required for the dialog, including type, prospect ID, header text, and success callback.</param>
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous operation of showing the modal dialog.
|
||||
/// A task representing the asynchronous operation.
|
||||
/// </returns>
|
||||
public static async Task ShowAsync(IModalService modalService, Func<Task> onSuccess, InteractionType type, Guid prospectId)
|
||||
public static async Task ShowAsync(IModalService modalService, InteractionDialogParameter parameter)
|
||||
{
|
||||
var headerText = type switch
|
||||
{
|
||||
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"
|
||||
};
|
||||
|
||||
var showInfo = type switch
|
||||
var showInfo = parameter.Type switch
|
||||
{
|
||||
InteractionType.EinAb => true,
|
||||
InteractionType.Complete => true,
|
||||
@@ -87,21 +65,21 @@ namespace FoodsharingSiegen.Server.Dialogs
|
||||
_ => false
|
||||
};
|
||||
|
||||
var infoName = type switch
|
||||
var infoName = parameter.Type switch
|
||||
{
|
||||
InteractionType.EinAb => "Welcher Betrieb?",
|
||||
InteractionType.ReleasedForVerification => "Hinweis",
|
||||
_ => "Kommentar"
|
||||
};
|
||||
|
||||
var showAlert = type switch
|
||||
var showAlert = parameter.Type switch
|
||||
{
|
||||
InteractionType.EinAb => true,
|
||||
InteractionType.IdCheck => true,
|
||||
_ => false
|
||||
};
|
||||
|
||||
var showNotNeeded = type switch
|
||||
var showNotNeeded = parameter.Type switch
|
||||
{
|
||||
InteractionType.PrintPass => true,
|
||||
InteractionType.PdfPass => true,
|
||||
@@ -110,19 +88,19 @@ namespace FoodsharingSiegen.Server.Dialogs
|
||||
|
||||
var interaction = new Interaction
|
||||
{
|
||||
Type = type,
|
||||
Type = parameter.Type,
|
||||
Date = DateTime.UtcNow,
|
||||
ProspectID = prospectId
|
||||
ProspectID = parameter.ProspectId
|
||||
};
|
||||
|
||||
await modalService.Show<InteractionDialog>(headerText, parameter =>
|
||||
await modalService.Show<InteractionDialog>(parameter.HeaderText, p =>
|
||||
{
|
||||
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);
|
||||
p.Add(nameof(Interaction), interaction);
|
||||
p.Add(nameof(ShowInfo), showInfo);
|
||||
p.Add(nameof(InfoName), infoName);
|
||||
p.Add(nameof(ShowAlert), showAlert);
|
||||
p.Add(nameof(ShowNotNeeded), showNotNeeded);
|
||||
p.Add(nameof(OnSuccess), parameter.OnSuccess);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using System.Linq.Expressions;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Contracts.Model;
|
||||
|
||||
namespace FoodsharingSiegen.Shared.Helper
|
||||
@@ -34,6 +35,18 @@ namespace FoodsharingSiegen.Shared.Helper
|
||||
if (filter.WithoutStepInBriefing)
|
||||
filterListQ = filterListQ.Where(x => x.Interactions.All(i => i.Type != InteractionType.StepInBriefing));
|
||||
|
||||
if (filter.WithoutIdCheck)
|
||||
filterListQ = filterListQ.Where(x => x.Interactions.All(i => i.Type != InteractionType.IdCheck));
|
||||
|
||||
if (filter.NoActivity)
|
||||
{
|
||||
var days = 180; // Half year
|
||||
Func<Prospect, bool> q1 = x => x.Interactions.Any() && x.Interactions.All(i => DateTime.Now - i.Date > TimeSpan.FromDays(days));
|
||||
Func<Prospect, bool> q2 = x => DateTime.Now - x.Created > TimeSpan.FromDays(days);
|
||||
|
||||
filterListQ = filterListQ.Where(x => q1(x) && q2(x));
|
||||
}
|
||||
|
||||
return filterListQ.ToList();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user