FIX: dlvAddress block closing when changing input field.

FIX: deleteDraft and deleteItem on ActivityCreage page did not trigger correct
This commit is contained in:
Frede Hundewadt 2023-05-30 15:28:51 +02:00
parent 7111ec5676
commit 4701783329
19 changed files with 432 additions and 270 deletions

View file

@ -27,9 +27,14 @@ namespace Wonky.Client.Helpers;
/// </summary>
public static class Utils
{
public static List<WorkplaceDocItemDto> GenerateRevListView(IEnumerable<WorkplaceProduct> products)
public static List<ProductVariant> GenerateVariantListDto(IEnumerable<DocView> items)
{
var result = new List<WorkplaceDocItemDto>();
return items.Select(item => new ProductVariant { VariantId = item.VariantId, S5A = item.S5A, S9A = item.S9A }).ToList();
}
public static List<DocView> GenerateRevListView(IEnumerable<WorkplaceProduct> products)
{
var result = new List<DocView>();
var docProducts = products.OrderBy(x => x.TradingName).ToList();
@ -37,7 +42,7 @@ public static class Utils
{
foreach (var variant in product.Variants)
{
var newDoc = new WorkplaceDocItemDto
var newDoc = new DocView
{
ProductId = product.ProductId,
VariantId = variant.VariantId,

View file

@ -86,6 +86,7 @@ public class CrmWorkplaceRepository : ICrmWorkplaceRepository
return JsonSerializer.Deserialize<WorkplaceDocInfo>(content, _options) ?? new WorkplaceDocInfo();
}
public async Task<WorkplaceDocInfo> GetRevisionList(string companyId, string workplaceId)
{
var result = await _client.GetAsync(
@ -97,8 +98,9 @@ public class CrmWorkplaceRepository : ICrmWorkplaceRepository
}
return JsonSerializer.Deserialize<WorkplaceDocInfo>(content, _options) ?? new WorkplaceDocInfo();
}
public async Task<string> CreateWorkplace(string companyId, WorkplaceDto workplace)
public async Task<string> PostWorkplace(string companyId, WorkplaceDto workplace)
{
var result = await _client.PostAsJsonAsync(
$"{_api.CrmCustomers}/{companyId}/{_api.CrmWorkplaceExt}", workplace, _options);
@ -110,13 +112,26 @@ public class CrmWorkplaceRepository : ICrmWorkplaceRepository
return content;
}
public async Task<BucketResultView> PostWorkplaceDocuments(string companyId, string workplaceId, BucketDto bucketDto)
{
var result = await _client.PostAsJsonAsync(
$"{_api.CrmCustomers}/{companyId}/{_api.CrmWorkplaceExt}/{workplaceId}/documents/bop", bucketDto, _options);
var content = await result.Content.ReadAsStringAsync();
if (!result.IsSuccessStatusCode || string.IsNullOrWhiteSpace(content))
{
return new BucketResultView();
}
return JsonSerializer.Deserialize<BucketResultView>(content) ?? new BucketResultView();
}
public async Task UpdateWorkplace(string companyId, WorkplaceDto workplace)
public async Task PutWorkplace(string companyId, WorkplaceDto workplace)
{
await _client.PutAsJsonAsync(
$"{_api.CrmCustomers}/{companyId}/{_api.CrmWorkplaceExt}/{workplace.WorkplaceId}", workplace, _options);
}
public async Task DeleteWorkplace(string companyId, string workplaceId)
{

View file

@ -21,20 +21,22 @@ namespace Wonky.Client.HttpRepository;
public interface ICrmWorkplaceRepository
{
Task<List<WorkplaceListView>> GetWorkplaces(string companyId);
Task<WorkplaceDto> GetWorkplace(string companyId, string workplaceId);
Task<string> CreateWorkplace(string companyId, WorkplaceDto workplace);
Task UpdateWorkplace(string companyId, WorkplaceDto workplace);
Task DeleteWorkplace(string companyId, string workplaceId);
Task<WorkplaceDocInfo> GetDocuments(string companyId, string workplaceId);
Task<WorkplaceDocInfo> GetRevisionList(string companyId, string workplaceId);
Task<string> PostWorkplace(string companyId, WorkplaceDto workplace);
Task<BucketResultView> PostWorkplaceDocuments(string companyId, string workplaceId, BucketDto bucketDto);
Task PutWorkplace(string companyId, WorkplaceDto workplace);
Task DeleteWorkplace(string companyId, string workplaceId);
Task DeleteDocument(string companyId, string workplaceId, string documentId);
Task DeleteVariantDocuments(string companyId, string workplaceId, string apbDocumentId, string apvDocumentId);

View file

@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
namespace Wonky.Client.Models;
public class DocRevision
{
public string ApprovedBy { get; set; } = "";
public string ApprovedDate { get; set; } = "";
public string AuthoredBy { get; set; } = "";
public string FollowupDate { get; set; } = "";
}

View file

@ -4,6 +4,7 @@ namespace Wonky.Client.Models;
public class DocView
{
public bool Added { get; set; }
public string ApbDocId { get; set; } = "";
public string ApbDocLink { get; set; } = "";
public string ApvDocId { get; set; } = "";
@ -12,4 +13,7 @@ public class DocView
public string ProductId { get; set; } = "";
public string VariantId { get; set; } = "";
public string VariantName { get; set; } = "";
public string S5A { get; set; } = "";
public string S9A { get; set; } = "";
public bool Selected { get; set; }
}

View file

@ -1,33 +0,0 @@
using System.ComponentModel.DataAnnotations;
using Wonky.Entity.DTO;
namespace Wonky.Client.Models;
public class WorkplaceDocDto
{
[Required] public string EyeCleanerLocation { get; set; } = "";
[Required]public string FirstAidLocation { get; set; } = "";
[Required]public string GlovesStorage { get; set; } = "";
[Required]public string GogglesStorage { get; set; } = "";
[Required]public string MaskStorage { get; set; } = "";
[Required]public string ProductStorage { get; set; } = "";
[Required]public string WasteDeposit { get; set; } = "";
[Required]public string AuthoredBy { get; set; } = "";
[Required]public string ApprovedBy { get; set; } = "";
[Required]public string ApprovedDate { get; set; } = "";
[Required]public string FollowupDate { get; set; } = "";
public List<WorkplaceDocItemDto> Items { get; set; } = new();
}
public class WorkplaceDocItemDto
{
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; }
public string VariantId { get; set; } = "";
public string VariantName { get; set; } = "";
}

View file

@ -13,52 +13,46 @@
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
*@
@using Wonky.Client.Components
<div class="modal" tabindex="-1" role="dialog" style="display:@_modalDisplay">
@* <div class="modal-dialog modal-dialog-scrollable modal-fullscreen-lg-down modal-xl modal-lg"> *@
<div class="modal-dialog modal-dialog-scrollable modal-fullscreen">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"></h4>
<button type="button" class="btn-close" onclick="@Hide" data-bs-dismiss="modal" aria-label="Luk"></button>
<div class="input-group">
<input id="search-input" type="text" class="form-control" placeholder="Søg ..." aria-described-by="search-addon"
@bind-value="SearchTerm" @bind-value:event="oninput" onkeyup="@OnSearchChanged"/>
<span class="input-group-text" id="search-addon">
<i class="bi-backspace-fill" onclick="@ClearSearch"></i>
</span>
</div>
</div>
<div class="modal-body">
<div class="accordion open" id="productSelection">
<div class="accordion-item">
<h2 class="accordion-header" id="curProducts">
<button class="accordion-button" type="button"
data-bs-toggle="collapse" data-bs-target="#curProductList"
aria-expanded="true" aria-controls="curProductList">
Dokumenterede produkter
</button>
</h2>
<div class="accordion-collapse collapse show" id="curProductList"
data-bs-parent="productSelection" aria-labelledby="curProducts">
<div class="accordion-body">
@if (CurProducts.Any())
{
}
</div>
</div>
@if (NewItems.Any())
{
<div class="list-group">
@foreach (var item in FilteredList)
{
<div class="list-group-item">
<div class="row">
<div class="col-sm-10">
@item.VariantName
</div>
<div class="col-sm-2">
<input type="checkbox" id="@item.VariantId" checked="@item.Added" class="form-check" @onclick="@(() => SelectItem(item))"/>
</div>
</div>
</div>
}
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="newProducts">
<button class="accordion-button" type="button"
data-bs-toggle="collapse" data-bs-target="#newProductList"
aria-expanded="true" aria-controls="newProductList">
Nye kunde produkter
</button>
</h2>
<div class="accordion-collapse collapse show" id="newProductList"
data-bs-parent="productSelection" aria-labelledby="newProducts">
<div class="accordion-body">
@if (NewProducts.Any())
{
}
</div>
</div>
}
</div>
<div class="modal-footer">
<div class="row">
<div class="col text-end">
<button type="button" class="btn btn-secondary" @onclick="@CancelAll">Fortryd</button>
<button type="button" class="btn btn-primary" @onclick="@Hide">OK</button>
</div>
</div>
</div>

View file

@ -22,21 +22,57 @@ namespace Wonky.Client.OverlayDocuments;
public partial class ProductSelectionOverlay
{
//###############################################################
[Parameter] public List<DocView> CurProducts { get; set; } = new();
[Parameter] public List<DocView> NewProducts { get; set; } = new();
[Parameter] public EventCallback<ExternalProductVariantView> OnSelected { get; set; }
[Parameter] public List<DocView> NewItems { get; set; } = new();
[Parameter] public EventCallback<DocView> OnSelectItem { get; set; }
//###############################################################
private string _modalDisplay = "";
private bool _showBackdrop;
private async Task SelectProduct(ExternalProductVariantView product)
private List<DocView> FilteredList { get; set; } = new();
private string SearchTerm { get; set; } = "";
protected override void OnInitialized()
{
await OnSelected.InvokeAsync(product);
FilterItems(SearchTerm);
}
private void ClearSearch()
{
SearchTerm = "";
FilterItems(SearchTerm);
}
private void OnSearchChanged()
{
FilterItems(SearchTerm);
}
private async Task SelectItem(DocView item)
{
item.Added = !item.Added;
await OnSelectItem.InvokeAsync(item);
}
private void FilterItems(string filter)
{
SearchTerm = filter;
FilteredList = string.IsNullOrWhiteSpace(filter)
? NewItems
: NewItems.Where(i => i.VariantName.ToLower().Contains(filter.ToLower())).ToList();
}
private async Task CancelAll()
{
foreach (var item in NewItems.Where(x => x.Added))
{
item.Added = false;
await OnSelectItem.InvokeAsync(item);
}
Hide();
}
public void Show()
{
_modalDisplay = "block;";
@ -44,12 +80,11 @@ public partial class ProductSelectionOverlay
StateHasChanged();
}
public void Hide()
{
_modalDisplay = "none;";
_showBackdrop = false;
StateHasChanged();
}
}

View file

@ -225,7 +225,7 @@ else
@*
***************** Reset draft *****************************
*@
<button type="button" class="btn btn-danger btn-sm" onclick="@DeleteDraft" disabled="@(DraftProvider.Draft.Items.Count == 0)"><i class="bi-trash"></i> Slet kladde</button>
<button type="button" class="btn btn-danger btn-sm" @onclick="@DeleteDraft" disabled="@(DraftProvider.Draft.Items.Count == 0)"><i class="bi-trash"></i> Slet kladde</button>
</th>
</tr>
<tr class="bg-dark opacity-75 text-white">
@ -258,7 +258,7 @@ else
@*
***************** Remove item *****************************
*@
<button type="button" class="btn btn-danger" onclick="@(() => RemoveItem(cartItem))"><i class="bi-trash2"></i> Slet Linje</button>
<button type="button" class="btn btn-danger" @onclick="@(() => RemoveItem(cartItem))"><i class="bi-trash2"></i> Slet Linje</button>
</td>
</tr>
}
@ -337,16 +337,59 @@ else
</div>
@* end draft line ------------------------------------------------- *@
</div>
<div class="accordion" id="crmActivity">
@* <div class="card" id="crmActivity"> *@
@* Delivery address *@
<div class="card mb-3 @(Activity.ActivityStatusEnum == "order" ? "inno-display" : "inno-hidden")">
<div class="card-header text-end">
<button class="btn btn-secondary" type="button" @onclick="@(ToggleDeliveryAddress)">
Leveringsadresse
</button>
</div>
<div class="@(HideDeliveryAddress ? "inno-hidden" : "inno-display")">
<div class="card-body">
<div class="row mb-1">
<label for="dlvName" class="col-sm-2 col-form-label-sm">Lev. Navn</label>
<div class="col-md-10">
<InputText id="dlvName" class="form-control" @bind-Value="Activity.DlvName"/>
</div>
</div>
<div class="row mb-1">
<label for="dlvAddress1" class="col-sm-2 col-form-label-sm">Lev. Adresse</label>
<div class="col-md-10">
<InputText id="dlvAddress1" class="form-control" @bind-Value="Activity.DlvAddress1"/>
</div>
</div>
<div class="row mb-1">
<label for="dlvAddress2" class="col-sm-2 col-form-label-sm">Lev. Adresse</label>
<div class="col-md-10">
<InputText id="dlvAddress2" class="form-control" @bind-Value="Activity.DlvAddress2"/>
</div>
</div>
<div class="row mb-1">
<label for="dlvZipCode" class="col-sm-2 col-form-label-sm">Lev. Postnr</label>
<div class="col-md-10">
<InputText id="dlvZipCode" class="form-control" @bind-Value="Activity.DlvZipCode"/>
</div>
</div>
<div class="row mb-1">
<label for="dlvCity" class="col-sm-2 col-form-label-sm">Lev. Bynavn</label>
<div class="col-md-10">
<InputText id="dlvCity" class="form-control" @bind-Value="Activity.DlvCity"/>
</div>
</div>
</div>
</div>
</div>
@*</div>*@
@*<div class="accordion" id="crmActivity">
$1$ Delivery address #1#
<div class="accordion-item @(Activity.ActivityStatusEnum == "order" ? "inno-display" : "inno-hidden")">
<h2 class="accordion-header" id="deliveryHeader">
<button class="accordion-button collapsed bg-light" type="button" data-bs-toggle="collapse" data-bs-target="#deliveryBody" aria-expanded="false" aria-controls="deliveryBody">
<button class="accordion-button bg-light" type="button" data-bs-toggle="collapse" data-bs-target="#deliveryBody" aria-expanded="false" aria-controls="deliveryBody">
Leveringsadresse
</button>
</h2>
<div id="deliveryBody" class="accordion-collapse collapse"
aria-labelledby="deliveryHeader" data-bs-parent="#crmActivity">
<div id="deliveryBody" class="accordion-collapse collapsed" aria-labelledby="deliveryHeader" data-bs-parent="#crmActivity">
<div class="accordion-body">
<div class="row mb-1">
<label for="dlvName" class="col-sm-2 col-form-label-sm">Lev. Navn</label>
@ -381,7 +424,7 @@ else
</div>
</div>
</div>
</div>
</div>*@
}
</EditForm>

View file

@ -97,6 +97,7 @@ public partial class AdvisorActivityCreatePage : IDisposable
private InvoiceListView CompanyInvoices { get; set; } = new();
private List<ReportItemView> Activities { get; set; } = new();
private bool Kanvas { get; set; }
private bool HideDeliveryAddress { get; set; } = true;
/// <summary>
/// Page initialization
@ -520,6 +521,11 @@ public partial class AdvisorActivityCreatePage : IDisposable
Toaster.ShowError(result.Message);
}
private void ToggleDeliveryAddress()
{
HideDeliveryAddress = !HideDeliveryAddress;
}
private void ShowOrgWarning()
{

View file

@ -76,7 +76,7 @@ public partial class AdvisorCustomerWorkplaceNewPage : IDisposable
Logger.LogDebug("CompanyId {}", JsonSerializer.Serialize(Workplace));
Logger.LogDebug("Workplace {}", JsonSerializer.Serialize(Workplace, new JsonSerializerOptions(JsonSerializerDefaults.Web)));
var result = await WorkplaceRepo.CreateWorkplace(CompanyId, Workplace);
var result = await WorkplaceRepo.PostWorkplace(CompanyId, Workplace);
Logger.LogDebug("HTTP result {}", result);
if (!string.IsNullOrWhiteSpace(result))

View file

@ -15,6 +15,7 @@
@using Microsoft.AspNetCore.Authorization
@using Wonky.Client.Components
@using Wonky.Client.OverlayDocuments
@attribute [Authorize(Roles = "Advisor")]
@page "/advisor/customers/{CompanyId}/workplaces/{WorkplaceId}/documents/new"
<PageTitle>@Workplace.CompanyName - @Workplace.Name</PageTitle>
@ -33,140 +34,124 @@
</div>
</div>
<EditForm EditContext="FormContext" OnValidSubmit="SubmitForm">
<EditForm EditContext="FormContext" OnValidSubmit="SubmitRevision">
<DataAnnotationsValidator/>
@* locations *@
<div class="row g-3 mb-3">
<div class="col-sm-12 col-md-6">
<div class="form-floating">
<InputText id="eyeCleanerLocation" class="form-control" @bind-Value="DocumentsDto.EyeCleanerLocation" placeholder="Øjenskylleflaske"/>
<label for="eyeCleanerLocation">Øjenskylleflaske</label>
<ValidationMessage For="@(() => DocumentsDto.EyeCleanerLocation)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating">
<InputText id="firstAidStorage" class="form-control" @bind-Value="DocumentsDto.FirstAidLocation" placeholder="Førstehjælp"/>
<label for="firstAidStorage">Førstehjælp</label>
<ValidationMessage For="@(() => DocumentsDto.FirstAidLocation)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating">
<InputText id="productStorage" class="form-control" @bind-Value="DocumentsDto.ProductStorage" placeholder="Produkt opbevaring"/>
<label for="productStorage">Produkt Opbevaring</label>
<ValidationMessage For="@(() => DocumentsDto.ProductStorage)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating">
<InputText id="maskStorage" class="form-control" @bind-Value="DocumentsDto.MaskStorage" placeholder="Maske opbevaring"/>
<label for="maskStorage">Maske Opbevaring</label>
<ValidationMessage For="@(() => DocumentsDto.MaskStorage)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating">
<InputText id="glovesStorage" class="form-control" @bind-Value="DocumentsDto.GlovesStorage" placeholder="Handsker"/>
<label for="glovesStorage">Handsker</label>
<ValidationMessage For="@(() => DocumentsDto.GlovesStorage)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating">
<InputText id="gogglesStorage" class="form-control" @bind-Value="DocumentsDto.GogglesStorage" placeholder="Beskyttelsesbriller"/>
<label for="gogglesStorage">Beskyttelsesbriller</label>
<ValidationMessage For="@(() => DocumentsDto.GogglesStorage)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating">
<InputText id="wasteDeposit" class="form-control" @bind-Value="DocumentsDto.WasteDeposit" placeholder="Affald og Spild"/>
<label for="wasteDeposit">Affald og Spild</label>
<ValidationMessage For="@(() => DocumentsDto.WasteDeposit)"></ValidationMessage>
</div>
</div>
</div>
<div class="row g-3 mb-3">
<div class="col-sm-12 col-md-3">
<div class="form-floating">
<InputText id="approvedDate" class="form-control" @bind-Value="DocumentsDto.ApprovedDate" placeholder="Oprettet dato"/>
<InputText id="approvedDate" class="form-control" @bind-Value="Revision.ApprovedDate" placeholder="Oprettet dato"/>
<label for="approvedDate">Oprettet dato</label>
<ValidationMessage For="@(() => DocumentsDto.ApprovedBy)"></ValidationMessage>
<ValidationMessage For="@(() => Revision.ApprovedBy)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-3">
<div class="form-floating">
<InputText id="followupDate" class="form-control" @bind-Value="DocumentsDto.FollowupDate" placeholder="Revisions dato"/>
<InputText id="followupDate" class="form-control" @bind-Value="Revision.FollowupDate" placeholder="Revisions dato"/>
<label for="followupDate">Revisions dato</label>
<ValidationMessage For="@(() => DocumentsDto.FollowupDate)"></ValidationMessage>
<ValidationMessage For="@(() => Revision.FollowupDate)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-3">
<div class="form-floating">
<InputText id="authoredBy" class="form-control" @bind-Value="DocumentsDto.AuthoredBy" placeholder="Oprettet af"/>
<InputText id="authoredBy" class="form-control" @bind-Value="Revision.AuthoredBy" placeholder="Oprettet af"/>
<label for="authoredBy">Oprettet af</label>
<ValidationMessage For="@(() => DocumentsDto.AuthoredBy)"></ValidationMessage>
<ValidationMessage For="@(() => Revision.AuthoredBy)"></ValidationMessage>
</div>
</div>
<div class="col-sm-12 col-md-3">
<div class="form-floating">
<InputText id="approvedBy" class="form-control" @bind-Value="DocumentsDto.ApprovedBy" placeholder="Godkendt af"/>
<InputText id="approvedBy" class="form-control" @bind-Value="Revision.ApprovedBy" placeholder="Godkendt af"/>
<label for="approvedBy">Godkendt af</label>
<ValidationMessage For="@(() => DocumentsDto.ApprovedBy)"></ValidationMessage>
<ValidationMessage For="@(() => Revision.ApprovedBy)"></ValidationMessage>
</div>
</div>
</div>
<div class="row mb-5">
<div class="col-sm-4 d-flex">
<a class="btn btn-primary mx-auto" href="/advisor/customers/@CompanyId"><i class="bi-x-lg"></i> Fortryd</a>
</div>
<div class="col-sm-4 d-flex">
<button type="submit" class="btn btn-success mx-auto" disabled="@FormInvalid"><i class="bi-cloud-upload"></i> Gem</button>
</div>
</div>
<div class="row mb-5">
<div class="col-sm-2 text-start">
<a class="btn btn-primary" href="/advisor/customers/@CompanyId"><i class="bi-x-lg"></i> Fortryd</a>
</div>
<div class="col-sm-10 text-end">
<button type="submit" class="btn btn-success" disabled="@FormInvalid"><i class="bi-cloud-upload"></i> Gem revision</button>
</div>
</div>
<div class="row">
<div class="col text-end">
<button type="button" class="btn btn-secondary" @onclick="@CancelNewProducts"><i class="bi-trash2"></i> Ryd tilføjede produkt(er)</button>
<button type="button" class="btn btn-primary" @onclick="@ShowProductSelectionOverlay"><i class="bi-plus-lg"></i> Produkt(er)</button>
</div>
</div>
@* current documents *@
<div class="list-group list-group-flush">
<div class="list-group-item">
<div class="row">
<div class="col-sm-4 h4">
<div class="col-sm-3">
Produkt Variant
</div>
<div class="col-sm-2 h4">
Opdater
<div class="col-sm-1">
@(AppendItems.Any() ? "Rediger" : "")
</div>
<div class="col-sm-4">
Referencer
</div>
<div class="col-sm-4">
Afvigelser
</div>
</div>
</div>
@foreach (var item in DocumentsDto.Items)
@if (AppendItems.Any())
{
@foreach (var append in AppendItems)
{
<div class="list-group-item">
<div class="row">
<div class="col-sm-3">
<span class="fw-bold">@append.VariantName.ToUpperInvariant()</span>
</div>
<div class="col-sm-1">
<InputCheckbox id="@append.VariantId" class="form-check" @bind-Value="@append.Selected"/>
</div>
<div class="col-sm-4">
@if (append.Selected)
{
<InputTextArea class="form-control" @bind-Value="@append.S5A" rows="1"></InputTextArea>
}
else
{
@append.S5A
}
</div>
<div class="col-sm-4">
@if (append.Selected)
{
<InputTextArea class="form-control" @bind-Value="@append.S9A" rows="1"></InputTextArea>
}
else
{
@append.S9A
}
</div>
</div>
</div>
}
}
@foreach (var item in CurrentItems)
{
<div class="list-group-item">
<div class="row">
<div class="col-sm-4">
<span class="fw-bold">@item.VariantName.ToUpperInvariant()</span>
</div>
<div class="col-sm-1">
<InputCheckbox id="@item.VariantId" class="form-check" @bind-Value="@item.Selected" />
</div>
<div class="col-sm-1">
<button type="button" class="btn btn-danger btn-sm" @onclick="@(() => OnConfirmDeleteVariant(item))">
<i class="bi-trash"></i>
</button>
</div>
<div class="col-sm-3">
<div class="col-sm-4">
@item.S5A
</div>
<div class="col-sm-3">
<div class="col-sm-4">
@item.S9A
</div>
</div>
</div>
}
<div class="list-group-item">
<div class="row">
</div>
</div>
</div>
</EditForm>
@ -176,8 +161,7 @@
<WorkingThreeDots/>
}
<ConfirmDeleteModal BodyMessage="@DeleteMessage" OnOkClicked="RemoveVariant" @ref="ConfirmDeleteVariant"/>
<ProductSelectionOverlay NewItems="AvailableItems" OnSelectItem="AddSelectedItem" @ref="SelectionOverlay"/>
@*
<div class="col-sm-12 col-md-6">
<div class="form-floating">

View file

@ -26,6 +26,7 @@ using Wonky.Client.Shared;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
using Wonky.Client.Helpers;
using Wonky.Client.OverlayDocuments;
#pragma warning disable CS8618
namespace Wonky.Client.Pages;
@ -51,100 +52,149 @@ public partial class AdvisorCustomerWorkplaceRevisionPage : IDisposable
private WorkplaceDto Workplace { get; set; } = new();
private WorkplaceDocInfo WorkplaceInfo { get; set; } = new();
private List<ExternalProductListView> AvailableProducts { get; set; } = new();
private WorkplaceDocDto DocumentsDto { get; set; } = new();
private DocRevision Revision { get; set; } = new();
private bool Working { get; set; } = true;
private bool FormInvalid { get; set; } = true;
private List<WorkplaceDocItemDto> CurrentItems { get; set; } = new();
private List<WorkplaceDocItemDto> NewDocuments { get; set; } = new();
private WorkplaceDocItemDto SelectedItem { get; set; } = new();
private ConfirmDeleteModal ConfirmDeleteVariant { get; set; }
private string DeleteMessage { get; set; } = "";
private List<DocView> CurrentItems { get; set; } = new();
private List<DocView> AvailableItems { get; set; } = new();
private List<DocView> AppendItems { get; set; } = new();
private ProductSelectionOverlay SelectionOverlay { get; set; }
protected override async Task OnInitializedAsync()
{
FormContext = new EditContext(DocumentsDto);
FormContext = new EditContext(Revision);
Interceptor.RegisterEvent();
Interceptor.RegisterBeforeSendEvent();
FormContext.OnFieldChanged += HandleFieldChanged!;
FormContext.OnValidationStateChanged += ValidationChanged!;
UserInfo = await UserService.GetUserInfo();
Workplace = await WorkplaceRepo.GetWorkplace(CompanyId, WorkplaceId);
Logger.LogDebug("Workplace {}", JsonSerializer.Serialize(Workplace, new JsonSerializerOptions(JsonSerializerDefaults.Web)));
Logger.LogDebug("Workplace {}",
JsonSerializer.Serialize(Workplace, new JsonSerializerOptions(JsonSerializerDefaults.Web)));
AvailableProducts = await PublicProductRepo.GetProducts();
WorkplaceInfo = await WorkplaceRepo.GetRevisionList(CompanyId, WorkplaceId);
CurrentItems = Utils.GenerateRevListView(WorkplaceInfo.Products);
Logger.LogDebug("Current Items List {}", JsonSerializer.Serialize(CurrentItems, new JsonSerializerOptions(JsonSerializerDefaults.Web)));
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 WorkplaceDocItemDto { VariantName = variant.Name, VariantId = variant.VariantId };
if (!CurrentItems.Contains(x))
var v = CurrentItems.FirstOrDefault(v => v.VariantId == variant.VariantId);
if (v == null)
{
NewDocuments.Add(x);
AvailableItems.Add(new DocView { VariantName = variant.Name, VariantId = variant.VariantId });
}
}
Logger.LogDebug("New Documents List {}", JsonSerializer.Serialize(NewDocuments, new JsonSerializerOptions(JsonSerializerDefaults.Web)));
DocumentsDto.GlovesStorage = Workplace.GlovesStorage;
DocumentsDto.GogglesStorage = Workplace.GogglesStorage;
DocumentsDto.MaskStorage = Workplace.MaskStorage;
DocumentsDto.ProductStorage = Workplace.ProductStorage;
DocumentsDto.EyeCleanerLocation = Workplace.EyeCleanerLocation;
DocumentsDto.FirstAidLocation = Workplace.FirstAidStorage;
DocumentsDto.WasteDeposit = Workplace.WasteDeposit;
DocumentsDto.ApprovedDate = $"{DateTime.Now:yyyy-MM-dd}";
DocumentsDto.AuthoredBy = $"{UserInfo.FirstName} {UserInfo.LastName}";
DocumentsDto.FollowupDate = $"{DateTime.Now.AddMonths(24):yyyy-MM-dd}";
DocumentsDto.Items = CurrentItems;
Logger.LogDebug("New Products List {}",
JsonSerializer.Serialize(AvailableItems, new JsonSerializerOptions(JsonSerializerDefaults.Web)));
Revision.ApprovedDate = $"{DateTime.Now:yyyy-MM-dd}";
Revision.AuthoredBy = $"{UserInfo.FirstName} {UserInfo.LastName}";
Revision.FollowupDate = $"{DateTime.Now.AddMonths(24):yyyy-MM-dd}";
Revision.ApprovedBy = "";
Working = false;
StateHasChanged();
}
private void SubmitForm()
{
}
private void OnConfirmDeleteVariant(WorkplaceDocItemDto selectedItem)
{
SelectedItem = selectedItem;
DeleteMessage = $"Bekræft at du sletter<br/><strong>{selectedItem.VariantName}</strong> fra <strong>{Workplace.CompanyName}</strong>?<br/>AL INFORMATION slettes og handlingen er uigenkaldelig.";
Logger.LogDebug("ConfirmDeleteProduct");
ConfirmDeleteVariant.Show();
}
private async Task RemoveVariant()
private async Task SubmitRevision()
{
if (Working)
{
return;
}
Toaster.ShowInfo("Sender revision. Vent venligst ...");
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();
FormInvalid = true;
CurrentItems.AddRange(AppendItems);
var x = new BucketDto
{
ApprovedDate = Revision.ApprovedDate,
ApprovedBy = Revision.ApprovedBy,
AuthoredBy = Revision.AuthoredBy,
FollowupDate = Revision.FollowupDate,
GlovesStorage = Workplace.GlovesStorage,
GogglesStorage = Workplace.GogglesStorage,
MaskStorage = Workplace.MaskStorage,
ProductStorage = Workplace.ProductStorage,
WasteDeposit = Workplace.ProductStorage,
EyeCleanerLocation = Workplace.EyeCleanerLocation,
FirstAidLocation = Workplace.FirstAidStorage,
ProductVariants = Utils.GenerateVariantListDto(CurrentItems)
};
Logger.LogDebug("submitRevision {}", JsonSerializer.Serialize(x));
var result = await WorkplaceRepo.PostWorkplaceDocuments(CompanyId, WorkplaceId, x);
Logger.LogDebug("result {}", JsonSerializer.Serialize(result));
Toaster.ClearAll();
Toaster.ShowInfo("Sådan!");
Navigator.NavigateTo($"/advisor/customers/{CompanyId}/workplaces/{WorkplaceId}");
Working = false;
}
private void CancelNewProducts()
{
AppendItems.Clear();
}
private void AddSelectedItem(DocView item)
{
if (item.Added)
{
AppendItems.Add(item);
}
else
{
AppendItems.Remove(item);
}
}
private void ShowProductSelectionOverlay()
{
SelectionOverlay.Show();
}
private void HandleFieldChanged(object sender, FieldChangedEventArgs e)
{
FormInvalid = !FormContext.Validate();
StateHasChanged();
}
private void ValidationChanged(object sender, ValidationStateChangedEventArgs e)
{
FormContext.OnFieldChanged -= HandleFieldChanged!;
FormContext.OnValidationStateChanged -= ValidationChanged!;
FormContext = new EditContext(Revision);
FormContext.OnFieldChanged += HandleFieldChanged!;
FormContext.OnValidationStateChanged += ValidationChanged!;
}
public void Dispose()
{
FormContext.OnFieldChanged += HandleFieldChanged!;
FormContext.OnValidationStateChanged += ValidationChanged!;
Interceptor.DisposeEvent();
}
}
}

View file

@ -161,8 +161,11 @@
<div class="col-sm-4">
<a class="btn btn-dark btn-sm" href="@docView.ApvDocLink" target="_blank"><i class="bi-filetype-html"></i> Kemisk Risiko Vurdering</a>
</div>
<div class="col-sm-1">
</div>
<div class="col-sm-1">
<button type="button" class="btn btn-danger btn-sm" @onclick="@(() => OnConfirmDeleteVariant(docView))">
<i class="bi-trash"></i>
</button>
</div>
<div class="col-sm-2">
@docView.DocumentDate
</div>
@ -184,3 +187,4 @@
}
<ConfirmDeleteModal BodyMessage="@DeleteMessage" OnOkClicked="RemoveWorkplace" @ref="ConfirmDeleteWorkplace"/>
<ConfirmDeleteModal BodyMessage="@DeleteMessage" OnOkClicked="RemoveVariant" @ref="ConfirmDeleteVariant"/>

View file

@ -74,6 +74,8 @@ public partial class AdvisorCustomerWorkplaceViewEditPage : IDisposable
private string _linkButtonText = LinkText;
private string _linkButtonStyle = LinkStyle;
private ConfirmDeleteModal ConfirmDeleteVariant { get; set; }
private DocView SelectedItem { get; set; } = new();
private bool OnlyOne { get; set; } = true;
@ -177,7 +179,7 @@ public partial class AdvisorCustomerWorkplaceViewEditPage : IDisposable
{
Working = true;
await Workplaces.UpdateWorkplace(CompanyId, Workplace);
await Workplaces.PutWorkplace(CompanyId, Workplace);
Working = false;
@ -209,6 +211,37 @@ public partial class AdvisorCustomerWorkplaceViewEditPage : IDisposable
}
private void OnConfirmDeleteVariant(DocView selectedItem)
{
SelectedItem = selectedItem;
DeleteMessage =
$"Bekræft at du sletter<br/><strong>{selectedItem.VariantName}</strong> fra <strong>{Workplace.CompanyName}</strong>?<br/>AL INFORMATION slettes og handlingen er uigenkaldelig.";
Logger.LogDebug("ConfirmDeleteProduct");
ConfirmDeleteVariant.Show();
}
private async Task RemoveVariant()
{
if (Working)
{
return;
}
Working = true;
var item = WorkplaceDocInfo.Products.First(x => x.ProductId == SelectedItem.ProductId);
// send delete request
await WorkplaceRepo
.DeleteVariantDocuments(CompanyId, WorkplaceId, SelectedItem.ApbDocId, SelectedItem.ApvDocId);
Toaster.ShowInfo("Produkt dokument er slettet.");
// update browser
WorkplaceDocInfo.Products.Remove(item);
DocViews = Utils.GenerateDocListView(WorkplaceDocInfo.Products);
SelectedItem = new DocView();
Working = false;
}
private void HandleFieldChanged(object sender, FieldChangedEventArgs e)
{

View file

@ -1,7 +1,7 @@
{
"appInfo": {
"name": "Wonky Online",
"version": "148.1",
"version": "151.1",
"rc": true,
"sandBox": false,
"image": "grumpy-coder.png"

View file

@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
namespace Wonky.Entity.DTO;
public class WorkplaceDocumentDto
public class BucketDto
{
[Required] public string EyeCleanerLocation { get; set; } = "";
[Required]public string FirstAidLocation { get; set; } = "";

View file

@ -1,12 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Wonky.Entity.DTO;
public class UpdateDocHeaderDto
{
[Required][MaxLength(128)] public string ApprovedBy { get; set; } = "";
[Required][MaxLength(10)] public string ApprovedDate { get; set; } = "";
[Required][MaxLength(128)] public string AuthoredBy { get; set; } = "";
[Required][MaxLength(128)] public string DocumentId { get; set; } = "";
[Required][MaxLength(10)] public string FollowupDate { get; set; } = "";
}

View file

@ -0,0 +1,21 @@
namespace Wonky.Entity.Views;
public class BucketResultView
{
public string Workplace { get; set; } = "";
public string WorkplaceDescription { get; set; } = "";
public string WorkplaceDocUrl { get; set; } = "";
public List<BucketVariantDocumentsResultView> Variants { get; set; } = new();
}
public class BucketVariantDocumentsResultView
{
public string ProductName { get; set; } = "";
public List<BucketVariantResultView> Documents { get; set; } = new();
}
public class BucketVariantResultView
{
public string DocumentId { get; set; } = "";
public string DocumentDescription { get; set; } = "";
}