Add Feedback Functions

This commit is contained in:
Andre Beging
2025-04-01 11:34:11 +02:00
parent bf64239625
commit 6d6d79f55a
9 changed files with 435 additions and 42 deletions

View File

@@ -1,78 +1,86 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using FoodsharingSiegen.Contracts.Enums;
namespace FoodsharingSiegen.Contracts.Entity
{
/// <summary>
/// The interaction class (a. beging, 21.05.2022)
/// The interaction class (a. beging, 21.05.2022)
/// </summary>
public class Interaction
{
#region Public Properties
/// <summary>
/// Gets or sets the value of the alert (ab)
/// Gets or sets the value of the alert (ab)
/// </summary>
public bool Alert { get; set; }
/// <summary>
/// Gets or sets the value of the created (ab)
/// Gets or sets the value of the created (ab)
/// </summary>
public DateTime Created { get; set; }
/// <summary>
/// Gets or sets the value of the date (ab)
/// Gets or sets the value of the date (ab)
/// </summary>
public DateTime Date { get; set; }
/// <summary>
/// Gets or sets the value of the id (ab)
/// Gets or sets the feedback associated with the interaction.
/// </summary>
[Key] public Guid Id { get; set; }
public InteractionFeedback Feedback { get; set; } = InteractionFeedback.Neutral;
/// <summary>
/// Gets or sets the value of the info (ab)
/// Gets or sets additional information related to feedback for the interaction.
/// </summary>
public string? FeedbackInfo { get; set; }
/// <summary>
/// Gets or sets the value of the id (ab)
/// </summary>
[Key]
public Guid Id { get; set; }
/// <summary>
/// Gets or sets additional information associated with the interaction.
/// </summary>
public string? Info1 { get; set; }
/// <summary>
/// Gets or sets the value of the not needed (ab)
/// Gets or sets the additional information (Info2) associated with the interaction.
/// </summary>
public string? Info2 { get; set; }
/// <summary>
/// Gets or sets the value of the not needed (ab)
/// </summary>
public bool NotNeeded { get; set; }
/// <summary>
/// Gets or sets the value of the prospect (ab)
/// Gets or sets the value of the prospect (ab)
/// </summary>
public Prospect Prospect { get; set; }
/// <summary>
/// Gets or sets the value of the prospect id (ab)
/// Gets or sets the value of the prospect id (ab)
/// </summary>
public Guid ProspectID { get; set; }
/// <summary>
/// Gets or sets the value of the type (ab)
/// Gets or sets the value of the type (ab)
/// </summary>
public InteractionType Type { get; set; }
/// <summary>
/// Gets or sets the value of the user (ab)
/// Gets or sets the value of the user (ab)
/// </summary>
public User User { get; set; }
/// <summary>
/// Gets or sets the value of the user id (ab)
/// Gets or sets the value of the user id (ab)
/// </summary>
public Guid UserID { get; set; }
#endregion
}
}
}

View File

@@ -0,0 +1,12 @@
namespace FoodsharingSiegen.Contracts.Enums
{
/// <summary>
/// Represents the types of feedback that can be associated with an interaction.
/// </summary>
public enum InteractionFeedback
{
Neutral = 10,
Positive = 20,
Negative = 30
}
}

View File

@@ -31,10 +31,16 @@
}
</div>
@if (!string.IsNullOrWhiteSpace(interaction.Info1))
{
<span>(<i>@interaction.Info1</i>)</span>
}
<div>
@FeedbackBuilder(interaction)
</div>
<div>
@if (!string.IsNullOrWhiteSpace(interaction.FeedbackInfo))
{
<span>(<i>@interaction.FeedbackInfo</i>)</span>
}
</div>
</div>
}
}

View File

@@ -1,7 +1,9 @@
using System.Text;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Enums;
using FoodsharingSiegen.Server.BaseClasses;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Primitives;
namespace FoodsharingSiegen.Server.Controls
{
@@ -91,5 +93,28 @@ namespace FoodsharingSiegen.Server.Controls
private bool NotNeeded => Interactions.Any(x => x.NotNeeded);
#endregion
private MarkupString FeedbackBuilder(Interaction interaction)
{
var infoList = new List<string>();
if(!string.IsNullOrWhiteSpace(interaction.Info1)) infoList.Add(interaction.Info1);
if(!string.IsNullOrWhiteSpace(interaction.Info2)) infoList.Add(interaction.Info2);
var infos = string.Join(" / ", infoList);
if (string.IsNullOrWhiteSpace(infos)) return new();
var sb = new StringBuilder();
sb.Append("(");
if (interaction.Feedback == InteractionFeedback.Positive)
sb.Append("<i class=\"fa-solid fa-thumbs-up\" style=\"margin-right: 0.3rem;\"></i>");
if (interaction.Feedback == InteractionFeedback.Negative)
sb.Append("<i class=\"fa-solid fa-thumbs-down\" style=\"margin-right: 0.3rem;\"></i>");
sb.Append($"<i>{infos}</i>");
sb.Append(")");
return new(sb.ToString());
}
}
}

View File

@@ -1,4 +1,5 @@
@inherits FsBase
@using FoodsharingSiegen.Contracts.Enums
@inherits FsBase
@if (ShowNotNeeded)
{
@@ -25,14 +26,54 @@
</div>
</div>
@if (ShowInfo)
@if (!string.IsNullOrWhiteSpace(Info1Name))
{
<Field>
<FieldLabel>@InfoName</FieldLabel>
<FieldLabel>@Info1Name</FieldLabel>
<TextEdit @bind-Text="Interaction.Info1"></TextEdit>
</Field>
}
@if (!string.IsNullOrWhiteSpace(Info2Name))
{
<Field>
<FieldLabel>@Info2Name</FieldLabel>
<TextEdit @bind-Text="Interaction.Info2"></TextEdit>
</Field>
}
@if (AllowFeedback)
{
<div class="row">
<div class="col-sm">
<Field>
<FieldLabel>Feedback</FieldLabel>
<br/>
<Buttons>
<Button Color="Color.Danger" Outline="@(Interaction.Feedback != InteractionFeedback.Negative)" Clicked="@(() => SetFeedbackAsync(InteractionFeedback.Negative))">
<i class="fa-solid fa-thumbs-down"></i>
</Button>
<Button Color="Color.Warning" Outline="@(Interaction.Feedback != InteractionFeedback.Neutral)" Clicked="@(() => SetFeedbackAsync(InteractionFeedback.Neutral))">
<i class="fa-solid fa-circle-dot"></i>
</Button>
<Button Color="Color.Success" Outline="@(Interaction.Feedback != InteractionFeedback.Positive)" Clicked="@(() => SetFeedbackAsync(InteractionFeedback.Positive))">
<i class="fa-solid fa-thumbs-up"></i>
</Button>
</Buttons>
</Field>
</div>
@if (Interaction.Feedback == InteractionFeedback.Negative)
{
<div class="col-sm">
<Field>
<FieldLabel>Feedback Info</FieldLabel>
<TextEdit @bind-Text="Interaction.FeedbackInfo"></TextEdit>
</Field>
</div>
}
</div>
}
<div class="d-flex justify-content-end">
<Button Color="Color.Secondary" Clicked="@ModalService.Hide">Abbrechen</Button>
<Button Color="Color.Primary" Clicked="@AddInteractionAsync" Class="ml-2">OK</Button>

View File

@@ -24,7 +24,13 @@ namespace FoodsharingSiegen.Server.Dialogs
#region Parameters
[Parameter]
public string? InfoName { get; set; }
public bool AllowFeedback { get; set; }
[Parameter]
public string? Info1Name { get; set; }
[Parameter]
public string? Info2Name { get; set; }
[Parameter]
public Interaction Interaction { get; set; } = new();
@@ -35,9 +41,6 @@ namespace FoodsharingSiegen.Server.Dialogs
[Parameter]
public bool ShowAlert { get; set; }
[Parameter]
public bool ShowInfo { get; set; }
[Parameter]
public bool ShowNotNeeded { get; set; }
@@ -55,21 +58,26 @@ namespace FoodsharingSiegen.Server.Dialogs
/// </returns>
public static async Task ShowAsync(IModalService modalService, InteractionDialogParameter parameter)
{
var showInfo = parameter.Type switch
var allowFeedback = parameter.Type switch
{
InteractionType.EinAb => true,
InteractionType.Complete => true,
InteractionType.IdCheck => true,
InteractionType.PrintPass => true,
InteractionType.ReleasedForVerification => true,
_ => false
};
var infoName = parameter.Type switch
var info1Name = parameter.Type switch
{
InteractionType.EinAb => "Welcher Betrieb?",
InteractionType.Complete => "Kommentar",
InteractionType.IdCheck => "Kommentar",
InteractionType.PrintPass => "Kommentar",
InteractionType.ReleasedForVerification => "Hinweis",
_ => "Kommentar"
_ => null
};
var info2Name = parameter.Type switch
{
InteractionType.EinAb => "Mit wem?",
_ => null
};
var showAlert = parameter.Type switch
@@ -95,8 +103,9 @@ namespace FoodsharingSiegen.Server.Dialogs
await modalService.Show<InteractionDialog>(parameter.HeaderText, p =>
{
p.Add(nameof(Interaction), interaction);
p.Add(nameof(ShowInfo), showInfo);
p.Add(nameof(InfoName), infoName);
p.Add(nameof(AllowFeedback), allowFeedback);
p.Add(nameof(Info1Name), info1Name);
p.Add(nameof(Info2Name), info2Name);
p.Add(nameof(ShowAlert), showAlert);
p.Add(nameof(ShowNotNeeded), showNotNeeded);
p.Add(nameof(OnSuccess), parameter.OnSuccess);
@@ -124,5 +133,22 @@ namespace FoodsharingSiegen.Server.Dialogs
}
#endregion
#region Private Method SetFeedbackAsync
/// <summary>
/// Sets the feedback type for the interaction and updates the feedback property.
/// </summary>
/// <param name="feedback">The feedback type to be set for the interaction.</param>
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
private async Task SetFeedbackAsync(InteractionFeedback feedback)
{
Interaction.Feedback = feedback;
await Task.CompletedTask;
}
#endregion
}
}

View File

@@ -0,0 +1,217 @@
// <auto-generated />
using System;
using FoodsharingSiegen.Server.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace FoodsharingSiegen.Server.Migrations
{
[DbContext(typeof(FsContext))]
[Migration("20250401084453_Interaction-Feedback")]
partial class InteractionFeedback
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Audit", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTime>("Created")
.HasColumnType("TEXT");
b.Property<string>("Data1")
.HasColumnType("TEXT");
b.Property<string>("Data2")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<Guid?>("UserID")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserID");
b.ToTable("Audits");
});
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Interaction", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("Alert")
.HasColumnType("INTEGER");
b.Property<DateTime>("Created")
.HasColumnType("TEXT");
b.Property<DateTime>("Date")
.HasColumnType("TEXT");
b.Property<int>("Feedback")
.HasColumnType("INTEGER");
b.Property<string>("FeedbackInfo")
.HasColumnType("TEXT");
b.Property<string>("Info1")
.HasColumnType("TEXT");
b.Property<string>("Info2")
.HasColumnType("TEXT");
b.Property<bool>("NotNeeded")
.HasColumnType("INTEGER");
b.Property<Guid>("ProspectID")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<Guid>("UserID")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ProspectID");
b.HasIndex("UserID");
b.ToTable("Interactions");
});
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Prospect", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTime>("Created")
.HasColumnType("TEXT");
b.Property<int>("FsId")
.HasColumnType("INTEGER");
b.Property<string>("Memo")
.HasColumnType("TEXT");
b.Property<DateTime?>("Modified")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("RecordState")
.HasColumnType("INTEGER");
b.Property<bool>("Warning")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Prospects");
});
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTime>("Created")
.HasColumnType("TEXT");
b.Property<string>("EncryptedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("ForceLogout")
.HasColumnType("INTEGER");
b.Property<string>("Groups")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Mail")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Memo")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Network")
.HasColumnType("INTEGER");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<bool>("Verified")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Audit", b =>
{
b.HasOne("FoodsharingSiegen.Contracts.Entity.User", "User")
.WithMany()
.HasForeignKey("UserID");
b.Navigation("User");
});
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Interaction", b =>
{
b.HasOne("FoodsharingSiegen.Contracts.Entity.Prospect", "Prospect")
.WithMany("Interactions")
.HasForeignKey("ProspectID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FoodsharingSiegen.Contracts.Entity.User", "User")
.WithMany("Interactions")
.HasForeignKey("UserID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Prospect");
b.Navigation("User");
});
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.Prospect", b =>
{
b.Navigation("Interactions");
});
modelBuilder.Entity("FoodsharingSiegen.Contracts.Entity.User", b =>
{
b.Navigation("Interactions");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,49 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FoodsharingSiegen.Server.Migrations
{
/// <inheritdoc />
public partial class InteractionFeedback : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Feedback",
table: "Interactions",
type: "INTEGER",
nullable: false,
defaultValue: 10);
migrationBuilder.AddColumn<string>(
name: "FeedbackInfo",
table: "Interactions",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Info2",
table: "Interactions",
type: "TEXT",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Feedback",
table: "Interactions");
migrationBuilder.DropColumn(
name: "FeedbackInfo",
table: "Interactions");
migrationBuilder.DropColumn(
name: "Info2",
table: "Interactions");
}
}
}

View File

@@ -60,9 +60,18 @@ namespace FoodsharingSiegen.Server.Migrations
b.Property<DateTime>("Date")
.HasColumnType("TEXT");
b.Property<int>("Feedback")
.HasColumnType("INTEGER");
b.Property<string>("FeedbackInfo")
.HasColumnType("TEXT");
b.Property<string>("Info1")
.HasColumnType("TEXT");
b.Property<string>("Info2")
.HasColumnType("TEXT");
b.Property<bool>("NotNeeded")
.HasColumnType("INTEGER");