InteractionModal umstellen
This commit is contained in:
@@ -1,61 +1,37 @@
|
||||
@using FoodsharingSiegen.Contracts.Entity
|
||||
@inherits FsBase
|
||||
|
||||
@inherits FsBase
|
||||
@if (ShowNotNeeded)
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<Field>
|
||||
<Switch TValue="bool" @bind-Checked="Interaction.NotNeeded">Nicht benötigt</Switch>
|
||||
</Field>
|
||||
</div>
|
||||
<div class="col">
|
||||
<Field>
|
||||
<Switch TValue="bool" @bind-Checked="Interaction.Alert">Achtung!</Switch>
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<Modal @ref="ModalReference">
|
||||
<ModalContent Centered Size="ModalSize.Default">
|
||||
<ModalHeader>
|
||||
<h6>@_header</h6>
|
||||
<CloseButton/>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
@if (_showNotNeeded)
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<Field>
|
||||
<Switch TValue="bool" @bind-Checked="Interaction.NotNeeded">Nicht benötigt</Switch>
|
||||
</Field>
|
||||
</div>
|
||||
<div class="col">
|
||||
<Field>
|
||||
<Switch TValue="bool" @bind-Checked="Interaction.Alert">Achtung!</Switch>
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<Field>
|
||||
<FieldLabel>Wann?</FieldLabel>
|
||||
<DatePicker TValue="DateTime" @bind-Date="Interaction.Date" ElementId="aim-datepicker" Max="DateTime.UtcNow.AddDays(7)" DisplayFormat="dd.MM.yyyy"/>
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@* <div class="col"> *@
|
||||
@* <Field> *@
|
||||
@* <FieldLabel>Wer?</FieldLabel> *@
|
||||
@* <Select TValue="Guid" @bind-SelectedValue="SelectedUser"> *@
|
||||
@* @foreach (var user in Users ?? []) *@
|
||||
@* { *@
|
||||
@* <SelectItem Value="@user.Id">@user.Name</SelectItem> *@
|
||||
@* } *@
|
||||
@* </Select> *@
|
||||
@* </Field> *@
|
||||
@* </div> *@
|
||||
<div class="col">
|
||||
<Field>
|
||||
<FieldLabel>Wann?</FieldLabel>
|
||||
<DatePicker TValue="DateTime" @bind-Date="Interaction.Date" ElementId="aim-datepicker" Max="DateTime.UtcNow.AddDays(7)" DisplayFormat="dd.MM.yyyy" />
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
@if (ShowInfo)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@InfoName</FieldLabel>
|
||||
<TextEdit @bind-Text="Interaction.Info"></TextEdit>
|
||||
</Field>
|
||||
}
|
||||
|
||||
@if (_showInfo)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@_infoName</FieldLabel>
|
||||
<TextEdit @bind-Text="Interaction.Info"></TextEdit>
|
||||
</Field>
|
||||
}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button Color="Color.Secondary" Clicked="ModalReference.Hide">Abbrechen</Button>
|
||||
<Button Color="Color.Primary" Clicked="@AddInteraction">OK</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
<Button Color="Color.Secondary" Clicked="@ModalService.Hide">Abbrechen</Button>
|
||||
<Button Color="Color.Primary" Clicked="@AddInteractionAsync">OK</Button>
|
||||
@@ -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<Interaction> OnAdd { get; set; }
|
||||
#region Dependencies
|
||||
|
||||
[Parameter]
|
||||
public List<User>? Users { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the prospect service (ab)
|
||||
/// </summary>
|
||||
[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<Task>? 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
|
||||
|
||||
/// <summary>
|
||||
/// Displays a modal dialog for adding an interaction with configurable settings based on the interaction type and associated prospect ID.
|
||||
/// </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>
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous operation of showing the modal dialog.
|
||||
/// </returns>
|
||||
public static async Task ShowAsync(IModalService modalService, Func<Task> 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<AddInteractionModal>(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
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new interaction for the current user using the ProspectService and hides the modal.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A task representing the asynchronous operation.
|
||||
/// </returns>
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user