From 328a2d89f80fcb183ef18c723426ff65337e6407 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Sat, 13 May 2023 17:49:51 +0200 Subject: [PATCH] FEAT: link copy to clipboard - send link to email - link to qr-codes --- Wonky.Client/Helpers/Utils.cs | 17 +++- .../Local.Services/ClipboardService.cs | 17 ++++ .../Local.Services/IClipboardService.cs | 6 ++ ...AdvisorCustomerWorkplaceViewEditPage.razor | 35 ++++++-- ...isorCustomerWorkplaceViewEditPage.razor.cs | 82 +++++++++++++++++++ Wonky.Client/Program.cs | 2 + Wonky.Client/Properties/launchSettings.json | 36 -------- Wonky.Client/Wonky.Client.csproj | 3 - Wonky.Client/wwwroot/appsettings.json | 2 +- 9 files changed, 154 insertions(+), 46 deletions(-) create mode 100644 Wonky.Client/Local.Services/ClipboardService.cs create mode 100644 Wonky.Client/Local.Services/IClipboardService.cs diff --git a/Wonky.Client/Helpers/Utils.cs b/Wonky.Client/Helpers/Utils.cs index b179a7f3..7bfa0fda 100644 --- a/Wonky.Client/Helpers/Utils.cs +++ b/Wonky.Client/Helpers/Utils.cs @@ -26,6 +26,22 @@ namespace Wonky.Client.Helpers; /// public static class Utils { + public static List ParseRecipientsFromString(string recipients) + { + var addresses = recipients + .Replace(" ", ",") + .Replace(",,",",") + .Split(","); + + return (from address + in addresses + where IsValidEmail(address) + select new EmailContact + { + Name = address, Email = address + }).ToList(); + } + /// /// map user role edit model to role assignment model /// @@ -150,7 +166,6 @@ public static class Utils { validConditions++; } - else return false; return validConditions == 3; } diff --git a/Wonky.Client/Local.Services/ClipboardService.cs b/Wonky.Client/Local.Services/ClipboardService.cs new file mode 100644 index 00000000..25d53cc9 --- /dev/null +++ b/Wonky.Client/Local.Services/ClipboardService.cs @@ -0,0 +1,17 @@ +using Microsoft.JSInterop; + +namespace Wonky.Client.Local.Services; + +public class ClipboardService :IClipboardService +{ + private readonly IJSRuntime _jsInterop; + + public ClipboardService(IJSRuntime jsInterop) + { + _jsInterop = jsInterop; + } + public async Task CopyToClipboard(string text) + { + await _jsInterop.InvokeVoidAsync("navigator.clipboard.writeText", text); + } +} \ No newline at end of file diff --git a/Wonky.Client/Local.Services/IClipboardService.cs b/Wonky.Client/Local.Services/IClipboardService.cs new file mode 100644 index 00000000..de24ae58 --- /dev/null +++ b/Wonky.Client/Local.Services/IClipboardService.cs @@ -0,0 +1,6 @@ +namespace Wonky.Client.Local.Services; + +public interface IClipboardService +{ + Task CopyToClipboard(string test); +} \ No newline at end of file diff --git a/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor b/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor index 0ad594a8..b253a45d 100644 --- a/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor @@ -105,16 +105,41 @@ +
+
+
+ + + +
+
+
+
+ + + +
+
+
+
  1. -
    - Produkt Liste +
    +
    Produkt Oversigt
    -
    - + +
    +
  2. @@ -153,4 +178,4 @@ } - \ No newline at end of file + \ No newline at end of file diff --git a/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor.cs index ab2d4156..cfb71829 100644 --- a/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor.cs @@ -13,15 +13,19 @@ // along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // +using System.Text; using System.Text.Json; +using Blazored.Toast.Services; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; using Wonky.Client.HttpInterceptors; using Wonky.Client.HttpRepository; +using Wonky.Client.Local.Services; using Wonky.Client.Models; using Wonky.Client.Shared; using Wonky.Entity.DTO; using Wonky.Entity.Views; +using Wonky.Client.Helpers; #pragma warning disable CS8618 namespace Wonky.Client.Pages; @@ -35,6 +39,10 @@ public partial class AdvisorCustomerWorkplaceViewEditPage : IDisposable [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public NavigationManager Navigator { get; set; } [Inject] public ILogger Logger { get; set; } + [Inject] public ISystemSendMailService SendMail { get; set; } + [Inject] public IUserInfoService UserInfo { get; set; } + [Inject] public IClipboardService Clipboard { get; set; } + [Inject] public IToastService Toaster { get; set; } // ############################################################# [Parameter] public string CompanyId { get; set; } = ""; @@ -48,6 +56,14 @@ public partial class AdvisorCustomerWorkplaceViewEditPage : IDisposable private List DocViews { get; set; } = new(); private ConfirmDeleteModal ConfirmDelete { get; set; } private string DeleteMessage { get; set; } = ""; + private string LinkRecipients { get; set; } = ""; + private const string CopyText = "Kopier"; + private const string CopyStyle = "btn btn-primary"; + private const string SuccessText = "Kopieret"; + private const string SuccessStyle = "btn btn-success"; + private string _buttonText = CopyText; + private string _buttonStyle = CopyStyle; + protected override async Task OnInitializedAsync() { @@ -65,7 +81,72 @@ public partial class AdvisorCustomerWorkplaceViewEditPage : IDisposable Working = false; DeleteMessage = $"Bekræft at du sletter
    {Workplace.Name} fra {Workplace.CompanyName}?
    AL INFORMATION slettes og handlingen er uigenkaldelig."; } + + private async Task OnSendLink() + { + if (string.IsNullOrWhiteSpace(LinkRecipients)) + { + return; + } + Logger.LogDebug("email.To => {}", LinkRecipients); + + var bodyText = new StringBuilder(); + bodyText.AppendLine("Produkt oversigt med QR-koder findes ved at følge linket nedenfor."); + bodyText.AppendLine(); + bodyText.AppendLine(); + bodyText.AppendLine(Workplace.ShortUrl); + bodyText.AppendLine(); + bodyText.AppendLine(); + bodyText.AppendLine("Med venlig hilsen"); + bodyText.AppendLine(); + bodyText.AppendLine(); + bodyText.AppendLine("Innotec Danmark A/S"); + bodyText.AppendLine(); + bodyText.AppendLine(); + bodyText.AppendLine("Telefon +45 86 28 63 36"); + bodyText.AppendLine(); + bodyText.AppendLine(); + bodyText.AppendLine("Denne mail er sendt af en robot og kan ikke besvares"); + + var email = new EmailMessage + { + To = Utils.ParseRecipientsFromString(LinkRecipients), + Subject = "Innotec Kemi - Produkt Oversigt", + Body = bodyText.ToString(), + IsBodyHtml = false + }; + + if (email.To.Any()) + { + var result = await SendMail.SendMail("system", email); + if (result.IsSuccess) + { + Toaster.ShowSuccess("Email er sendt"); + } + else + { + Toaster.ShowWarning("Email er ikke sendt."); + } + } + + } + + private async Task OnCopyLink() + { + await Clipboard.CopyToClipboard(Workplace.ShortUrl); + + _buttonText = SuccessText; + _buttonStyle = SuccessStyle; + + StateHasChanged(); + + await Task.Delay(TimeSpan.FromSeconds(2)); + + _buttonText = CopyText; + _buttonStyle = CopyStyle; + + } private async Task OnSubmitUpdate() { @@ -80,6 +161,7 @@ public partial class AdvisorCustomerWorkplaceViewEditPage : IDisposable Logger.LogDebug("ConfirmDeleteWorkplace"); ConfirmDelete.Show(); } + private async Task OnDeleteWorkplace() { diff --git a/Wonky.Client/Program.cs b/Wonky.Client/Program.cs index e6a7fccb..51c8732b 100644 --- a/Wonky.Client/Program.cs +++ b/Wonky.Client/Program.cs @@ -54,6 +54,8 @@ builder.Services.AddHttpClientInterceptor(); builder.Services.Configure(builder.Configuration.GetSection("ApiConfig")); // app info object builder.Services.Configure(builder.Configuration.GetSection("AppInfo")); +// interface +builder.Services.AddScoped(); // user builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Wonky.Client/Properties/launchSettings.json b/Wonky.Client/Properties/launchSettings.json index f67c91cc..f218b342 100644 --- a/Wonky.Client/Properties/launchSettings.json +++ b/Wonky.Client/Properties/launchSettings.json @@ -1,12 +1,4 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:61714", - "sslPort": 44308 - } - }, "profiles": { "Wonky.Client": { "commandName": "Project", @@ -17,34 +9,6 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } - }, - "Chrome": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:7174;http://localhost:5280", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "Firefox": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:7174;http://localhost:5280", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } } } } diff --git a/Wonky.Client/Wonky.Client.csproj b/Wonky.Client/Wonky.Client.csproj index 0897124d..183bd9e9 100644 --- a/Wonky.Client/Wonky.Client.csproj +++ b/Wonky.Client/Wonky.Client.csproj @@ -35,9 +35,6 @@ - - PreserveNewest - diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index e6c65e53..c42c8523 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -1,7 +1,7 @@ { "appInfo": { "name": "Wonky Online", - "version": "138.17", + "version": "141.2", "rc": true, "sandBox": false, "image": "grumpy-coder.png"