From 7111ec567609f2c895b5e1d6aab6e7ec410121c3 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Sun, 28 May 2023 14:12:20 +0200 Subject: [PATCH] wip: v148.1 --- Wonky.Client/Helpers/Utils.cs | 160 ++++++++++-------- .../HttpRepository/CrmWorkplaceRepository.cs | 21 ++- .../HttpRepository/ICrmWorkplaceRepository.cs | 64 +------ Wonky.Client/Models/DocSelectDisplay.cs | 10 -- .../{DocRevisionDto.cs => WorkplaceDocDto.cs} | 15 +- .../ProductSelectionOverlay.razor.cs | 4 +- .../Pages/AdvisorCustomerViewEditPage.razor | 10 +- ...=> AdvisorCustomerWorkplaceListPage.razor} | 0 ...AdvisorCustomerWorkplaceListPage.razor.cs} | 2 +- ... => AdvisorCustomerWorkplaceNewPage.razor} | 0 ... AdvisorCustomerWorkplaceNewPage.razor.cs} | 4 +- ...dvisorCustomerWorkplaceRevisionPage.razor} | 51 +++--- ...sorCustomerWorkplaceRevisionPage.razor.cs} | 74 ++++++-- ...dvisorCustomerWorkplaceViewEditPage.razor} | 10 +- ...sorCustomerWorkplaceViewEditPage.razor.cs} | 118 ++++--------- Wonky.Client/wwwroot/appsettings.json | 4 +- ...kplaceInventory.cs => WorkplaceDocInfo.cs} | 2 +- .../Views/WorkplaceProductVariantDoc.cs | 4 +- 18 files changed, 261 insertions(+), 292 deletions(-) delete mode 100644 Wonky.Client/Models/DocSelectDisplay.cs rename Wonky.Client/Models/{DocRevisionDto.cs => WorkplaceDocDto.cs} (75%) rename Wonky.Client/Pages/{CrmCustomerWorkplaceListPage.razor => AdvisorCustomerWorkplaceListPage.razor} (100%) rename Wonky.Client/Pages/{CrmCustomerWorkplaceListPage.razor.cs => AdvisorCustomerWorkplaceListPage.razor.cs} (97%) rename Wonky.Client/Pages/{CrmCustomerWorkplaceNewPage.razor => AdvisorCustomerWorkplaceNewPage.razor} (100%) rename Wonky.Client/Pages/{CrmCustomerWorkplaceNewPage.razor.cs => AdvisorCustomerWorkplaceNewPage.razor.cs} (96%) rename Wonky.Client/Pages/{CrmCustomerWorkplaceDocumentAddPage.razor => AdvisorCustomerWorkplaceRevisionPage.razor} (87%) rename Wonky.Client/Pages/{CrmCustomerWorkplaceDocumentAddPage.razor.cs => AdvisorCustomerWorkplaceRevisionPage.razor.cs} (63%) rename Wonky.Client/Pages/{CrmCustomerWorkplaceViewEditPage.razor => AdvisorCustomerWorkplaceViewEditPage.razor} (94%) rename Wonky.Client/Pages/{CrmCustomerWorkplaceViewEditPage.razor.cs => AdvisorCustomerWorkplaceViewEditPage.razor.cs} (69%) rename Wonky.Entity/Views/{WorkplaceInventory.cs => WorkplaceDocInfo.cs} (92%) diff --git a/Wonky.Client/Helpers/Utils.cs b/Wonky.Client/Helpers/Utils.cs index 7bfa0fda..b9e33a3e 100644 --- a/Wonky.Client/Helpers/Utils.cs +++ b/Wonky.Client/Helpers/Utils.cs @@ -18,6 +18,7 @@ using System.Text.RegularExpressions; using Wonky.Client.Enums; using Wonky.Client.Models; using Wonky.Entity.DTO; +using Wonky.Entity.Views; namespace Wonky.Client.Helpers; @@ -26,6 +27,85 @@ namespace Wonky.Client.Helpers; /// public static class Utils { + public static List GenerateRevListView(IEnumerable products) + { + var result = new List(); + + var docProducts = products.OrderBy(x => x.TradingName).ToList(); + + foreach (var product in docProducts) + { + foreach (var variant in product.Variants) + { + var newDoc = new WorkplaceDocItemDto + { + ProductId = product.ProductId, + VariantId = variant.VariantId, + VariantName = variant.VariantName, + }; + + var docs = variant.Docs.OrderBy(x => x.DocumentTypeEnum).ToList(); + foreach (var doc in docs) + { + switch (doc.DocumentTypeEnum.ToLower()) + { + case "apb": + newDoc.ApbDocId = doc.DocumentId; + break; + case "apv": + newDoc.ApvDocId = doc.DocumentId; + newDoc.S5A = doc.S5A; + newDoc.S9A = doc.S9A; + break; + } + } + result.Add(newDoc); + } + } + return result.OrderBy(x => x.VariantName).ToList(); + } + + + public static List GenerateDocListView(IEnumerable products) + { + var result = new List(); + + var docProducts = products.OrderBy(x => x.TradingName).ToList(); + + foreach (var product in docProducts) + { + foreach (var variant in product.Variants) + { + var newDoc = new DocView + { + ProductId = product.ProductId, + VariantId = variant.VariantId, + VariantName = variant.VariantName, + DocumentDate = variant.Docs[0].DocumentDate + }; + + var docs = variant.Docs.OrderBy(x => x.DocumentTypeEnum).ToList(); + foreach (var doc in docs) + { + switch (doc.DocumentTypeEnum.ToLower()) + { + case "apb": + newDoc.ApbDocLink = doc.DocumentLink; + newDoc.ApbDocId = doc.DocumentId; + break; + case "apv": + newDoc.ApvDocLink = doc.DocumentLink; + newDoc.ApvDocId = doc.DocumentId; + break; + } + } + result.Add(newDoc); + } + } + return result.OrderBy(x => x.VariantName).ToList(); + } + + public static List ParseRecipientsFromString(string recipients) { var addresses = recipients @@ -42,11 +122,7 @@ public static class Utils }).ToList(); } - /// - /// map user role edit model to role assignment model - /// - /// - /// + public static List MapSaveAssignedRoles(RoleAssignment model) { return new List() @@ -62,11 +138,7 @@ public static class Utils }; } - /// - /// map user role assignment to edit model - /// - /// - /// + public static RoleAssignment MapEditAssignedRoles(UserManagerEditView model) { var x = new RoleAssignment(); @@ -103,11 +175,7 @@ public static class Utils return x; } - /// - /// Sanitize string by removing everything but digits - /// - /// - /// + public static string StringToDigits(string digitString) { if (string.IsNullOrWhiteSpace(digitString)) @@ -116,16 +184,13 @@ public static class Utils return regexObj.Replace(digitString, ""); } - /// - /// Validate string is only numbers - /// - /// - /// + private static bool IsDigitsOnly(string check) { return check.All(c => c is >= '0' and <= '9'); } + public static bool Validate(ValidateType validateType, string toValidate) { return validateType switch @@ -138,12 +203,7 @@ public static class Utils }; } - /// - /// validate password to contain a-z and A-Z and 0-9 - /// - /// - /// optional (default 10) - /// + public static bool IsValidPasswd(string toValidate, int length = 10) { if (toValidate.Length < length) @@ -170,11 +230,7 @@ public static class Utils return validConditions == 3; } - /// - /// return Country Name from countryCode - /// - /// - /// + public static string CountryName(string countryCode) { return countryCode.ToLower() switch @@ -186,11 +242,7 @@ public static class Utils }; } - /// - /// Helper to parse querystring - /// - /// - /// + public static Dictionary ParseQuery(string query) { if (string.IsNullOrWhiteSpace(query) || query.Contains("://")) @@ -206,11 +258,7 @@ public static class Utils .ToDictionary(element => element[0], element => element[1]); } - /// - /// Validate email format - /// - /// - /// + public static bool IsValidEmail(string email) { var trimmedEmail = email.Trim(); @@ -231,41 +279,25 @@ public static class Utils } } - /// - /// return enum as the string value - /// - /// - /// + public static string EnumToString(Enum value) { return value.ToString(); } - /// - /// Parse string to enum of T - /// - /// - /// - /// + public static T StringToEnum(string value) { return (T)Enum.Parse(typeof(T), value, true); } - /// - /// Generate unique hashcode from time - /// - /// + public static int GetHashFromNow() { return DateTime.Now.ToFileTimeUtc().GetHashCode(); } - /// - /// Get visit state as colored icon - /// - /// - /// + public static string GetVisitState(string dtNextVisit) { if (dtNextVisit is "0001-01-01" or "1970-01-01") @@ -281,11 +313,7 @@ public static class Utils return dtNow > dtNext.AddDays(-14) ? "the-bad" : "the-good"; } - /// - /// Translate process status to icon - /// - /// - /// + public static string GetProcessStatus(string processStatus) { return processStatus.ToLower() switch diff --git a/Wonky.Client/HttpRepository/CrmWorkplaceRepository.cs b/Wonky.Client/HttpRepository/CrmWorkplaceRepository.cs index b70714da..d08b6be9 100644 --- a/Wonky.Client/HttpRepository/CrmWorkplaceRepository.cs +++ b/Wonky.Client/HttpRepository/CrmWorkplaceRepository.cs @@ -74,18 +74,29 @@ public class CrmWorkplaceRepository : ICrmWorkplaceRepository } - public async Task GetWorkplaceInventory(string companyId, string workplaceId) + public async Task GetDocuments(string companyId, string workplaceId) { var result = await _client.GetAsync( $"{_api.CrmCustomers}/{companyId}/{_api.CrmWorkplaceExt}/{workplaceId}/documents"); var content = await result.Content.ReadAsStringAsync(); if (!result.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content)) { - return new WorkplaceInventory(); + return new WorkplaceDocInfo(); } - return JsonSerializer.Deserialize(content, _options) ?? new WorkplaceInventory(); + return JsonSerializer.Deserialize(content, _options) ?? new WorkplaceDocInfo(); } + public async Task GetRevisionList(string companyId, string workplaceId) + { + var result = await _client.GetAsync( + $"{_api.CrmCustomers}/{companyId}/{_api.CrmWorkplaceExt}/{workplaceId}/documents/revision"); + var content = await result.Content.ReadAsStringAsync(); + if (!result.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content)) + { + return new WorkplaceDocInfo(); + } + return JsonSerializer.Deserialize(content, _options) ?? new WorkplaceDocInfo(); + } public async Task CreateWorkplace(string companyId, WorkplaceDto workplace) { @@ -114,14 +125,14 @@ public class CrmWorkplaceRepository : ICrmWorkplaceRepository } - public async Task DeleteWorkplaceDocuments(string companyId, string workplaceId, string documentId) + public async Task DeleteDocument(string companyId, string workplaceId, string documentId) { await _client.DeleteAsync( $"{_api.CrmCustomers}/{companyId}/{_api.CrmWorkplaceExt}/{workplaceId}/documents/{documentId}"); } - public async Task DeleteWorkplaceDocuments(string companyId, string workplaceId, string apbDocumentId, string apvDocumentId) + public async Task DeleteVariantDocuments(string companyId, string workplaceId, string apbDocumentId, string apvDocumentId) { await _client.DeleteAsync( $"{_api.CrmCustomers}/{companyId}/{_api.CrmWorkplaceExt}/{workplaceId}/documents/{apvDocumentId}"); diff --git a/Wonky.Client/HttpRepository/ICrmWorkplaceRepository.cs b/Wonky.Client/HttpRepository/ICrmWorkplaceRepository.cs index 98f0b6e2..76ef5735 100644 --- a/Wonky.Client/HttpRepository/ICrmWorkplaceRepository.cs +++ b/Wonky.Client/HttpRepository/ICrmWorkplaceRepository.cs @@ -18,74 +18,24 @@ using Wonky.Entity.Views; namespace Wonky.Client.HttpRepository; -/// -/// Interface for handling Customer Workplaces (chemical document service) -/// public interface ICrmWorkplaceRepository { - /// - /// Get Workplaces for given customer id - /// - /// - /// Task> GetWorkplaces(string companyId); - /// - /// Get specific workplace using customer id and workplace id - /// - /// - /// - /// + Task GetWorkplace(string companyId, string workplaceId); - /// - /// Create new workplace given the customer id and workplace data - /// - /// - /// - /// Task CreateWorkplace(string companyId, WorkplaceDto workplace); - /// - /// Update workplace given the customer id and updated data - /// - /// - /// - /// Task UpdateWorkplace(string companyId, WorkplaceDto workplace); - /// - /// Delete workplace given customer id and workplace id - /// - /// - /// - /// Task DeleteWorkplace(string companyId, string workplaceId); - /// - /// Get list of products and documentation for workplace - /// - /// - /// - /// - Task GetWorkplaceInventory(string companyId, string workplaceId); - - /// - /// Remove single document by Id - /// - /// - /// - /// - /// - Task DeleteWorkplaceDocuments(string companyId, string workplaceId, string documentId); + Task GetDocuments(string companyId, string workplaceId); - /// - /// Remove a document pair from the workplace - /// - /// - /// - /// - /// - /// - Task DeleteWorkplaceDocuments(string companyId, string workplaceId, string apbDocumentId, string apvDocumentId); + Task GetRevisionList(string companyId, string workplaceId); + + Task DeleteDocument(string companyId, string workplaceId, string documentId); + + Task DeleteVariantDocuments(string companyId, string workplaceId, string apbDocumentId, string apvDocumentId); } \ No newline at end of file diff --git a/Wonky.Client/Models/DocSelectDisplay.cs b/Wonky.Client/Models/DocSelectDisplay.cs deleted file mode 100644 index 73d3e241..00000000 --- a/Wonky.Client/Models/DocSelectDisplay.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Wonky.Client.Models; - -public class DocSelectDisplay -{ - public string S5A { get; set; } = ""; - public string S9A { get; set; } = ""; - public bool Selected { get; set; } - public string VariantId { get; set; } = ""; - public string VariantName { get; set; } = ""; -} \ No newline at end of file diff --git a/Wonky.Client/Models/DocRevisionDto.cs b/Wonky.Client/Models/WorkplaceDocDto.cs similarity index 75% rename from Wonky.Client/Models/DocRevisionDto.cs rename to Wonky.Client/Models/WorkplaceDocDto.cs index 4a7692f9..52b53ec8 100644 --- a/Wonky.Client/Models/DocRevisionDto.cs +++ b/Wonky.Client/Models/WorkplaceDocDto.cs @@ -3,7 +3,7 @@ using Wonky.Entity.DTO; namespace Wonky.Client.Models; -public class DocRevisionDto +public class WorkplaceDocDto { [Required] public string EyeCleanerLocation { get; set; } = ""; [Required]public string FirstAidLocation { get; set; } = ""; @@ -17,14 +17,17 @@ public class DocRevisionDto [Required]public string ApprovedDate { get; set; } = ""; [Required]public string FollowupDate { get; set; } = ""; - public List Items { get; set; } = new(); + public List Items { get; set; } = new(); } -public class DocRevisionItemDto +public class WorkplaceDocItemDto { - public string VariantId { get; set; } = ""; - public string VariantName { get; set; } = ""; + public string ApbDocId { get; set; } = ""; + public string ApvDocId { get; set; } = ""; + public string ProductId { get; set; } = ""; public string S5A { get; set; } = ""; public string S9A { get; set; } = ""; - public bool Selected { get; set; } = true; + public bool Selected { get; set; } + public string VariantId { get; set; } = ""; + public string VariantName { get; set; } = ""; } diff --git a/Wonky.Client/OverlayDocuments/ProductSelectionOverlay.razor.cs b/Wonky.Client/OverlayDocuments/ProductSelectionOverlay.razor.cs index 917cb4c0..7f5d7ac2 100644 --- a/Wonky.Client/OverlayDocuments/ProductSelectionOverlay.razor.cs +++ b/Wonky.Client/OverlayDocuments/ProductSelectionOverlay.razor.cs @@ -22,8 +22,8 @@ namespace Wonky.Client.OverlayDocuments; public partial class ProductSelectionOverlay { //############################################################### - [Parameter] public List CurProducts { get; set; } = new(); - [Parameter] public List NewProducts { get; set; } = new(); + [Parameter] public List CurProducts { get; set; } = new(); + [Parameter] public List NewProducts { get; set; } = new(); [Parameter] public EventCallback OnSelected { get; set; } //############################################################### diff --git a/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor b/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor index 0e4d587d..e7a94698 100644 --- a/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerViewEditPage.razor @@ -28,12 +28,12 @@ }
-
+
@Company.Name (@Company.Account)
-
+
@if (AppInfo!.Value!.Rc) { @if (UserInfo.CountryCode is "DK") @@ -106,9 +106,9 @@
@* Email *@ - +
- +
@@ -288,7 +288,7 @@
- +
diff --git a/Wonky.Client/Pages/CrmCustomerWorkplaceListPage.razor b/Wonky.Client/Pages/AdvisorCustomerWorkplaceListPage.razor similarity index 100% rename from Wonky.Client/Pages/CrmCustomerWorkplaceListPage.razor rename to Wonky.Client/Pages/AdvisorCustomerWorkplaceListPage.razor diff --git a/Wonky.Client/Pages/CrmCustomerWorkplaceListPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerWorkplaceListPage.razor.cs similarity index 97% rename from Wonky.Client/Pages/CrmCustomerWorkplaceListPage.razor.cs rename to Wonky.Client/Pages/AdvisorCustomerWorkplaceListPage.razor.cs index 5c9c0a35..0ae6c3b3 100644 --- a/Wonky.Client/Pages/CrmCustomerWorkplaceListPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerWorkplaceListPage.razor.cs @@ -24,7 +24,7 @@ using Wonky.Entity.Views; namespace Wonky.Client.Pages; -public partial class CrmCustomerWorkplaceListPage : IDisposable +public partial class AdvisorCustomerWorkplaceListPage : IDisposable { // ############################################################### [Inject] public ICrmWorkplaceRepository WorkplaceRepo { get; set; } diff --git a/Wonky.Client/Pages/CrmCustomerWorkplaceNewPage.razor b/Wonky.Client/Pages/AdvisorCustomerWorkplaceNewPage.razor similarity index 100% rename from Wonky.Client/Pages/CrmCustomerWorkplaceNewPage.razor rename to Wonky.Client/Pages/AdvisorCustomerWorkplaceNewPage.razor diff --git a/Wonky.Client/Pages/CrmCustomerWorkplaceNewPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerWorkplaceNewPage.razor.cs similarity index 96% rename from Wonky.Client/Pages/CrmCustomerWorkplaceNewPage.razor.cs rename to Wonky.Client/Pages/AdvisorCustomerWorkplaceNewPage.razor.cs index 11842e59..6c686df9 100644 --- a/Wonky.Client/Pages/CrmCustomerWorkplaceNewPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerWorkplaceNewPage.razor.cs @@ -25,14 +25,14 @@ namespace Wonky.Client.Pages; #pragma warning disable CS8618 -public partial class CrmCustomerWorkplaceNewPage : IDisposable +public partial class AdvisorCustomerWorkplaceNewPage : IDisposable { // ############################################################### [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public ICrmCustomerRepository CustomerRepo { get; set; } [Inject] public ICrmWorkplaceRepository WorkplaceRepo { get; set; } [Inject] public IToastService Toaster { get; set; } - [Inject] public ILogger Logger { get; set; } + [Inject] public ILogger Logger { get; set; } [Inject] public NavigationManager Navigator { get; set; } // ############################################################### diff --git a/Wonky.Client/Pages/CrmCustomerWorkplaceDocumentAddPage.razor b/Wonky.Client/Pages/AdvisorCustomerWorkplaceRevisionPage.razor similarity index 87% rename from Wonky.Client/Pages/CrmCustomerWorkplaceDocumentAddPage.razor rename to Wonky.Client/Pages/AdvisorCustomerWorkplaceRevisionPage.razor index 8b825b08..ce5267d5 100644 --- a/Wonky.Client/Pages/CrmCustomerWorkplaceDocumentAddPage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerWorkplaceRevisionPage.razor @@ -20,7 +20,7 @@ @Workplace.CompanyName - @Workplace.Name
- @Workplace.CompanyName + @Workplace.CompanyName
@* Stamkort *@ @@ -88,34 +88,34 @@
-
+
- - - + + +
-
+
-
+
+
+ + + +
+
+
-
-
- - - -
-
@@ -138,22 +138,28 @@
- @foreach (var doc in DocumentsDto.Items) + @foreach (var item in DocumentsDto.Items) {
- @doc.VariantName.ToUpperInvariant() + @item.VariantName.ToUpperInvariant()
-
- +
+ +
+
+ +
+
+ @item.S5A
- @doc.S5A -
-
- @doc.S9A + @item.S9A
+
} @@ -170,6 +176,7 @@ } + @*
diff --git a/Wonky.Client/Pages/CrmCustomerWorkplaceDocumentAddPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerWorkplaceRevisionPage.razor.cs similarity index 63% rename from Wonky.Client/Pages/CrmCustomerWorkplaceDocumentAddPage.razor.cs rename to Wonky.Client/Pages/AdvisorCustomerWorkplaceRevisionPage.razor.cs index e64bd0ce..69604a97 100644 --- a/Wonky.Client/Pages/CrmCustomerWorkplaceDocumentAddPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerWorkplaceRevisionPage.razor.cs @@ -30,14 +30,14 @@ using Wonky.Client.Helpers; #pragma warning disable CS8618 namespace Wonky.Client.Pages; -public partial class CrmCustomerWorkplaceDocumentAddPage : IDisposable +public partial class AdvisorCustomerWorkplaceRevisionPage : IDisposable { // ############################################################# [Inject] public ICrmWorkplaceRepository WorkplaceRepo { get; set; } [Inject] public ICrmPublicProductRepository PublicProductRepo { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public NavigationManager Navigator { get; set; } - [Inject] public ILogger Logger { get; set; } + [Inject] public ILogger Logger { get; set; } [Inject] public IToastService Toaster { get; set; } [Inject] public IUserInfoService UserService { get; set; } @@ -49,14 +49,18 @@ public partial class CrmCustomerWorkplaceDocumentAddPage : IDisposable private UserManagerEditView UserInfo { get; set; } private EditContext FormContext { get; set; } private WorkplaceDto Workplace { get; set; } = new(); - private WorkplaceInventory WorkplaceInventory { get; set; } = new(); + private WorkplaceDocInfo WorkplaceInfo { get; set; } = new(); private List AvailableProducts { get; set; } = new(); - private DocRevisionDto DocumentsDto { get; set; } = new(); + private WorkplaceDocDto DocumentsDto { get; set; } = new(); private bool Working { get; set; } = true; private bool FormInvalid { get; set; } = true; - private List CurDocuments { get; set; } = new(); - private List NewDocuments { get; set; } = new(); - + private List CurrentItems { get; set; } = new(); + private List NewDocuments { get; set; } = new(); + private WorkplaceDocItemDto SelectedItem { get; set; } = new(); + private ConfirmDeleteModal ConfirmDeleteVariant { get; set; } + private string DeleteMessage { get; set; } = ""; + + protected override async Task OnInitializedAsync() { FormContext = new EditContext(DocumentsDto); @@ -64,28 +68,29 @@ public partial class CrmCustomerWorkplaceDocumentAddPage : IDisposable Interceptor.RegisterBeforeSendEvent(); UserInfo = await UserService.GetUserInfo(); + Workplace = await WorkplaceRepo.GetWorkplace(CompanyId, WorkplaceId); + Logger.LogDebug("Workplace {}", JsonSerializer.Serialize(Workplace, new JsonSerializerOptions(JsonSerializerDefaults.Web))); - WorkplaceInventory = await WorkplaceRepo.GetWorkplaceInventory(CompanyId, WorkplaceId); + AvailableProducts = await PublicProductRepo.GetProducts(); + + WorkplaceInfo = await WorkplaceRepo.GetRevisionList(CompanyId, WorkplaceId); - foreach (var variant in WorkplaceInventory.Products.SelectMany(product => product.Variants)) - { - CurDocuments.Add(new DocRevisionItemDto { VariantName = variant.VariantName, VariantId = variant.VariantId }); - } - - DocumentsDto.Items = CurDocuments; - Logger.LogDebug("Current Documents List {}", JsonSerializer.Serialize(CurDocuments, new JsonSerializerOptions(JsonSerializerDefaults.Web))); + CurrentItems = Utils.GenerateRevListView(WorkplaceInfo.Products); + Logger.LogDebug("Current Items List {}", JsonSerializer.Serialize(CurrentItems, new JsonSerializerOptions(JsonSerializerDefaults.Web))); + + // create list with variants not in the current variant list foreach (var variant in AvailableProducts.SelectMany(product => product.Variants)) { - var x = new DocRevisionItemDto { VariantName = variant.Name, VariantId = variant.VariantId }; - if (!CurDocuments.Contains(x)) + var x = new WorkplaceDocItemDto { VariantName = variant.Name, VariantId = variant.VariantId }; + if (!CurrentItems.Contains(x)) { NewDocuments.Add(x); } } Logger.LogDebug("New Documents List {}", JsonSerializer.Serialize(NewDocuments, new JsonSerializerOptions(JsonSerializerDefaults.Web))); - + DocumentsDto.GlovesStorage = Workplace.GlovesStorage; DocumentsDto.GogglesStorage = Workplace.GogglesStorage; DocumentsDto.MaskStorage = Workplace.MaskStorage; @@ -98,6 +103,8 @@ public partial class CrmCustomerWorkplaceDocumentAddPage : IDisposable DocumentsDto.AuthoredBy = $"{UserInfo.FirstName} {UserInfo.LastName}"; DocumentsDto.FollowupDate = $"{DateTime.Now.AddMonths(24):yyyy-MM-dd}"; + DocumentsDto.Items = CurrentItems; + Working = false; } @@ -105,6 +112,37 @@ public partial class CrmCustomerWorkplaceDocumentAddPage : IDisposable { } + + private void OnConfirmDeleteVariant(WorkplaceDocItemDto selectedItem) + { + SelectedItem = selectedItem; + DeleteMessage = $"Bekræft at du sletter
{selectedItem.VariantName} fra {Workplace.CompanyName}?
AL INFORMATION slettes og handlingen er uigenkaldelig."; + Logger.LogDebug("ConfirmDeleteProduct"); + ConfirmDeleteVariant.Show(); + } + + + private async Task RemoveVariant() + { + if (Working) + { + return; + } + Working = true; + var item = WorkplaceInfo + .Products + .First(x => x.ProductId == SelectedItem.ProductId); + + await WorkplaceRepo + .DeleteVariantDocuments(CompanyId, WorkplaceId, SelectedItem.ApbDocId, SelectedItem.ApvDocId); + WorkplaceInfo.Products.Remove(item); + CurrentItems = Utils.GenerateRevListView(WorkplaceInfo.Products); + Toaster.ShowInfo("Produkt dokumenter er slettet."); + SelectedItem = new WorkplaceDocItemDto(); + Working = false; + } + + public void Dispose() { Interceptor.DisposeEvent(); diff --git a/Wonky.Client/Pages/CrmCustomerWorkplaceViewEditPage.razor b/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor similarity index 94% rename from Wonky.Client/Pages/CrmCustomerWorkplaceViewEditPage.razor rename to Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor index 769cc6a3..e1f00766 100644 --- a/Wonky.Client/Pages/CrmCustomerWorkplaceViewEditPage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor @@ -123,7 +123,7 @@ Vis QR-koder
@@ -141,13 +141,13 @@ - +
- @if (WorkplaceInventory.Products.Any()) + @if (WorkplaceDocInfo.Products.Any()) { @foreach (var docView in DocViews) { @@ -162,9 +162,6 @@ Kemisk Risiko Vurdering
-
@docView.DocumentDate @@ -187,4 +184,3 @@ } - \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmCustomerWorkplaceViewEditPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor.cs similarity index 69% rename from Wonky.Client/Pages/CrmCustomerWorkplaceViewEditPage.razor.cs rename to Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor.cs index 009c89f0..bbecf1be 100644 --- a/Wonky.Client/Pages/CrmCustomerWorkplaceViewEditPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerWorkplaceViewEditPage.razor.cs @@ -30,7 +30,7 @@ using Wonky.Client.Helpers; #pragma warning disable CS8618 namespace Wonky.Client.Pages; -public partial class CrmCustomerWorkplaceViewEditPage : IDisposable +public partial class AdvisorCustomerWorkplaceViewEditPage : IDisposable { // ############################################################# [Inject] public ICrmWorkplaceRepository Workplaces { get; set; } @@ -38,7 +38,7 @@ public partial class CrmCustomerWorkplaceViewEditPage : IDisposable [Inject] public ICrmWorkplaceRepository WorkplaceRepo { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; } [Inject] public NavigationManager Navigator { get; set; } - [Inject] public ILogger Logger { 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; } @@ -52,10 +52,9 @@ public partial class CrmCustomerWorkplaceViewEditPage : IDisposable private WorkplaceDto Workplace { get; set; } = new(); private EditContext WorkplaceContext { get; set; } private bool Working { get; set; } = true; - private WorkplaceInventory WorkplaceInventory { get; set; } = new(); + private WorkplaceDocInfo WorkplaceDocInfo { get; set; } = new(); private List DocViews { get; set; } = new(); private ConfirmDeleteModal ConfirmDeleteWorkplace { get; set; } - private ConfirmDeleteModal ConfirmDeleteVariant { get; set; } private string DeleteMessage { get; set; } = ""; private string LinkRecipients { get; set; } = ""; private const string CopyText = "Kopier"; @@ -64,7 +63,17 @@ public partial class CrmCustomerWorkplaceViewEditPage : IDisposable private const string CopySuccessStyle = "btn btn-success"; private string _copyButtonText = CopyText; private string _copyButtonStyle = CopyStyle; - private DocView SelectedProduct { get; set; } = new(); + private const string LinkText = "Send Link"; + private const string LinkStyle = "btn btn-primary"; + private const string LinkSuccessText = "Link Sendt"; + private const string LinkSuccessStyle = "btn btn-success"; + private const string LinkFailText = "Link ikke Sendt"; + private const string LinkFailStyle = "btn btn-danger"; + private const string LinkSendingText = "Arbejder"; + private const string LinkSendingStyle = "btn btn-warning"; + private string _linkButtonText = LinkText; + private string _linkButtonStyle = LinkStyle; + private bool OnlyOne { get; set; } = true; @@ -79,10 +88,12 @@ public partial class CrmCustomerWorkplaceViewEditPage : IDisposable var x = await Workplaces.GetWorkplaces(CompanyId); OnlyOne = x.Count is 1; await Task.Delay(250); - Workplace = await Workplaces.GetWorkplace(CompanyId, WorkplaceId); - WorkplaceInventory = await WorkplaceRepo.GetWorkplaceInventory(CompanyId, WorkplaceId); - DocViews = GenerateDocumentListView(); + Workplace = await Workplaces.GetWorkplace(CompanyId, WorkplaceId); + WorkplaceDocInfo = await WorkplaceRepo.GetDocuments(CompanyId, WorkplaceId); + + DocViews = Utils.GenerateDocListView(WorkplaceDocInfo.Products); + Working = false; } @@ -94,6 +105,8 @@ public partial class CrmCustomerWorkplaceViewEditPage : IDisposable return; } Logger.LogDebug("email.To => {}", LinkRecipients); + _linkButtonText = LinkSendingText; + _linkButtonStyle = LinkSendingStyle; var bodyText = new StringBuilder(); bodyText.AppendLine("Produkt oversigt med QR-koder findes ved at følge linket nedenfor."); @@ -126,12 +139,20 @@ public partial class CrmCustomerWorkplaceViewEditPage : IDisposable var result = await SendMail.SendMail("system", email); if (result.IsSuccess) { - Toaster.ShowSuccess("Email er sendt"); + _linkButtonText = LinkSuccessText; + _linkButtonStyle = LinkSuccessStyle; + StateHasChanged(); + await Task.Delay(TimeSpan.FromSeconds(2)); } else { - Toaster.ShowWarning("Email er ikke sendt."); + _linkButtonText = LinkFailText; + _linkButtonStyle = LinkFailStyle; + StateHasChanged(); + await Task.Delay(TimeSpan.FromSeconds(2)); } + _linkButtonText = LinkText; + _linkButtonStyle = LinkStyle; } } @@ -188,83 +209,6 @@ public partial class CrmCustomerWorkplaceViewEditPage : IDisposable } - private void OnConfirmDeleteVariant(DocView selectedProduct) - { - SelectedProduct = selectedProduct; - - DeleteMessage = $"Bekræft at du sletter
{selectedProduct.VariantName} fra {Workplace.CompanyName}?
AL INFORMATION slettes og handlingen er uigenkaldelig."; - - Logger.LogDebug("ConfirmDeleteProduct"); - - ConfirmDeleteVariant.Show(); - } - - - private async Task RemoveVariant() - { - if (Working) - { - return; - } - Working = true; - - var product = WorkplaceInventory - .Products - .First(x => x.ProductId == SelectedProduct.ProductId); - - await WorkplaceRepo - .DeleteWorkplaceDocuments(CompanyId, WorkplaceId, SelectedProduct.ApbDocId, SelectedProduct.ApvDocId); - - WorkplaceInventory.Products.Remove(product); - - DocViews = GenerateDocumentListView(); - - Toaster.ShowInfo("Produkt dokumenter er slettet."); - - Working = false; - } - - - private List GenerateDocumentListView() - { - var docViews = new List(); - - var docProducts = WorkplaceInventory.Products.OrderBy(x => x.TradingName).ToList(); - - foreach (var product in docProducts) - { - foreach (var variant in product.Variants) - { - var newDoc = new DocView - { - ProductId = product.ProductId, - VariantId = variant.VariantId, - VariantName = variant.VariantName, - DocumentDate = variant.Docs[0].DocumentDate - }; - - var docs = variant.Docs.OrderBy(x => x.DocumentTypeEnum).ToList(); - foreach (var doc in docs) - { - switch (doc.DocumentTypeEnum.ToLower()) - { - case "apb": - newDoc.ApbDocLink = doc.DocumentLink; - newDoc.ApbDocId = doc.DocumentId; - break; - case "apv": - newDoc.ApvDocLink = doc.DocumentLink; - newDoc.ApvDocId = doc.DocumentId; - break; - } - } - docViews.Add(newDoc); - } - } - return docViews.OrderBy(x => x.VariantName).ToList(); - } - - private void HandleFieldChanged(object sender, FieldChangedEventArgs e) { diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index 704590ff..060d88cf 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -1,9 +1,9 @@ { "appInfo": { "name": "Wonky Online", - "version": "148.0", + "version": "148.1", "rc": true, - "sandBox": true, + "sandBox": false, "image": "grumpy-coder.png" }, "Logging": { diff --git a/Wonky.Entity/Views/WorkplaceInventory.cs b/Wonky.Entity/Views/WorkplaceDocInfo.cs similarity index 92% rename from Wonky.Entity/Views/WorkplaceInventory.cs rename to Wonky.Entity/Views/WorkplaceDocInfo.cs index 9c905476..c71674f9 100644 --- a/Wonky.Entity/Views/WorkplaceInventory.cs +++ b/Wonky.Entity/Views/WorkplaceDocInfo.cs @@ -3,7 +3,7 @@ using System.Diagnostics.Contracts; namespace Wonky.Entity.Views; -public class WorkplaceInventory +public class WorkplaceDocInfo { public string WorkplaceId { get; set; } = ""; public string CompanyName { get; set; } = ""; diff --git a/Wonky.Entity/Views/WorkplaceProductVariantDoc.cs b/Wonky.Entity/Views/WorkplaceProductVariantDoc.cs index 4ef818a3..12c4758c 100644 --- a/Wonky.Entity/Views/WorkplaceProductVariantDoc.cs +++ b/Wonky.Entity/Views/WorkplaceProductVariantDoc.cs @@ -6,5 +6,7 @@ public class WorkplaceProductVariantDoc public string DocumentTypeEnum { get; set; } = ""; public string DocumentDescription { get; set; } = ""; public string DocumentDate { get; set; } = ""; - public string DocumentLink { get; set; } = ""; + public string DocumentLink { get; set; } = ""; + public string S5A { get; set; } = ""; + public string S9A { get; set; } = ""; } \ No newline at end of file