wip - test popup price list

This commit is contained in:
Frede Hundewadt 2022-07-31 10:12:28 +02:00
parent b741e2bb07
commit 5456dfbbcf
18 changed files with 657 additions and 62 deletions

View file

@ -0,0 +1,11 @@
namespace Wonky.Client.Helpers;
public static class StringExtensions
{
public static string Left(this string value, int maxLength)
{
if (string.IsNullOrEmpty(value)) return value;
maxLength = Math.Abs(maxLength);
return value.Length <= maxLength ? value : $"{value[..maxLength]} ...";
}
}

View file

@ -75,6 +75,7 @@ namespace Wonky.Client.HttpInterceptors
// set new token
e.Request.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);
}
}
}

View file

@ -1,10 +1,11 @@
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.HttpRepository;
public interface IWorkplaceHttpRepository
{
Task<List<WorkplaceDto>> GetWorkplaces(string companyId);
Task<List<WorkplaceListView>> GetWorkplaces(string companyId);
Task<WorkplaceDto> GetWorkplace(string companyId, string workplaceId);
Task CreateWorkplace(string companyId, WorkplaceDto workplace);
Task UpdateWorkplace(string companyId, WorkplaceDto workplace);

View file

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options;
using Wonky.Entity.Configuration;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.HttpRepository;
@ -30,11 +31,11 @@ public class WorkplaceHttpRepository : IWorkplaceHttpRepository
_api = configuration.Value;
}
public async Task<List<WorkplaceDto>> GetWorkplaces(string companyId)
public async Task<List<WorkplaceListView>> GetWorkplaces(string companyId)
{
var result = await _client.GetFromJsonAsync<List<WorkplaceDto>>(
var result = await _client.GetFromJsonAsync<List<WorkplaceListView>>(
$"{_api.CrmCustomer}/{companyId}/{_api.CrmWorkplace}", _options);
return result ?? new List<WorkplaceDto>();
return result ?? new List<WorkplaceListView>();
}
public async Task<WorkplaceDto> GetWorkplace(string companyId, string workplaceId)

View file

@ -0,0 +1,8 @@
namespace Wonky.Client.Models;
public class SelectedSku
{
public string ItemId { get; set; } = "";
public string Quantity { get; set; } = "";
public string Rate { get; set; } = "";
}

View file

@ -233,11 +233,11 @@
<div class="row">
<div class="col">
@* catalog *@
<div class="sticky-top bg-success bg-opacity-50 rounded-2 px-3 pt-3">
<div class="sticky-top bg-dark rounded-2 px-3 pt-3">
<div class="row mb-2">
<div class="col">
<ItemGroupComponent OnChanged="SetItemGroup"/>
</div>
@* <div class="col"> *@
@* <ItemGroupComponent OnChanged="SetItemGroup"/> *@
@* </div> *@
<div class="col">
<ItemSearchComponent OnChanged="SetSearchCol"/>
</div>
@ -248,14 +248,14 @@
<ItemSortComponent OnChanged="SetSortCol"/>
</div>
<div class="col">
<PageSizeComponent OnChanged="SetPageSize"></PageSizeComponent>
</div>
</div>
<div class="row">
<div class="col">
<PaginationComponent MetaData="_metaData" Spread="2" SelectedPage="SelectedPage"></PaginationComponent>
<PageSizeComponent OnChanged="SetPageSize" />
</div>
</div>
@* <div class="row"> *@
@* <div class="col"> *@
@* <PaginationComponent MetaData="_metaData" Spread="2" SelectedPage="SelectedPage"></PaginationComponent> *@
@* </div> *@
@* </div> *@
</div>
@if (_catalog.Any())
{

View file

@ -196,13 +196,7 @@
<div class="card-footer">
<div class="row">
<div class="col">
<button type="submit" class="btn btn-light border-dark">Gem</button>
</div>
<div class="col">
<a class="btn btn-light border-dark" href="/companies">Til Oversigt</a>
</div>
<div class="col">
<a class="btn btn-light border-dark" href="/companies/@_company.CompanyId/workplaces">Kemi</a>
<a class="btn btn-light border-dark" href="/companies">Oversigt</a>
</div>
<div class="col">
<a class="btn btn-light border-dark" href="/companies/@_company.CompanyId/h/i">Produktkøb</a>
@ -210,6 +204,12 @@
<div class="col">
<a class="btn btn-light border-dark" href="/companies/@_company.CompanyId/h/p">Varelinjer</a>
</div>
<div class="col">
<a class="btn btn-light border-dark" href="/companies/@_company.CompanyId/workplaces">Kemi</a>
</div>
<div class="col">
<button type="submit" class="btn btn-light border-dark">Gem</button>
</div>
<div class="col">
<ActivityButton ActionLink="@_actionLink"
ButtonText="Besøg"

View file

@ -42,10 +42,10 @@
</div>
<div class="row mb-3">
<div class="col-md-10">
<PaginationComponent MetaData="_metaDate" Spread="2" SelectedPage="SelectedPage"></PaginationComponent>
<PaginationComponent MetaData="_metaData" Spread="2" SelectedPage="SelectedPage" />
</div>
</div>
</div>
</div>
<ItemTableComponent SalesItems="_items"></ItemTableComponent>
<ItemTableComponent SalesItems="_items" />

View file

@ -35,7 +35,7 @@ public partial class ItemCatalogPage : IDisposable
[Inject] private HttpInterceptorService _interceptor { get; set; }
[Inject] private UserPreferenceService _preferenceService { get; set; }
private List<SalesItemView> _items { get; set; } = new();
private MetaData? _metaDate { get; set; } = new();
private MetaData? _metaData { get; set; } = new();
private CatalogPagingParams _paging = new();
private Preferences _preferences = new();
@ -51,18 +51,11 @@ public partial class ItemCatalogPage : IDisposable
await GetSalesItems();
}
private async Task SelectedPage(int page)
{
_items = new List<SalesItemView>();
_paging.PageNumber = page;
await GetSalesItems();
}
private async Task GetSalesItems()
{
var pagingResponse = await _itemRepo.GetSalesItemsPaged(_paging);
_items = pagingResponse.Items!;
_metaDate = pagingResponse.MetaData;
_metaData = pagingResponse.MetaData;
}
private async Task SetPageSize(string pageSize)
@ -73,13 +66,6 @@ public partial class ItemCatalogPage : IDisposable
await GetSalesItems();
}
private async Task SetItemGroup(string groupFilter)
{
_items = new List<SalesItemView>();
_paging.PageNumber = 1;
_paging.SelectGroup = groupFilter;
await GetSalesItems();
}
private async Task SetSearchCol(string columnName)
{
_items = new List<SalesItemView>();
@ -102,6 +88,21 @@ public partial class ItemCatalogPage : IDisposable
await GetSalesItems();
}
private async Task SelectedPage(int page)
{
_items = new List<SalesItemView>();
_paging.PageNumber = page;
await GetSalesItems();
}
private async Task SetItemGroup(string groupFilter)
{
_items = new List<SalesItemView>();
_paging.PageNumber = 1;
_paging.SelectGroup = groupFilter;
await GetSalesItems();
}
public void Dispose() => _interceptor.DisposeEvent();
}

View file

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
@ -12,7 +13,7 @@ public partial class WorkplaceListPage : IDisposable
[Inject] private IWorkplaceHttpRepository _workplaceRepo { get; set; }
[Inject] private ICompanyHttpRepository _companyRepo { get; set; }
[Inject] private HttpInterceptorService _interceptor { get; set; }
private List<WorkplaceDto> _workplaces { get; set; } = new();
private List<WorkplaceListView> _workplaces { get; set; } = new();
private CompanyDto _company { get; set; } = new();
protected override async Task OnParametersSetAsync()

View file

@ -5,22 +5,99 @@
<div class="card">
<div class="card-header">
<div class="card-title">
<h2>@_company.Name</h2>
<h2>@_workplace.CompanyName</h2>
<h3>@_workplace.Name @(!string.IsNullOrWhiteSpace(_workplace.Description) ? $"- {_workplace.Description}" : "")</h3>
</div>
</div>
<div class="card-body">
<div>
@_workplace.WorkplaceId
<EditForm EditContext="_editContext" OnValidSubmit="SubmitUpdate">
<DataAnnotationsValidator/>
<table class="table">
<thead>
<tr>
<th colspan="4">
Stamdata
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="align-middle">Navn</td>
<td class="align-middle">
<InputText id="name" class="form-control" @bind-Value="_workplace.Name"/>
<ValidationMessage For="@(() => _workplace.Name)"></ValidationMessage>
</td>
<td class="align-middle">Beskrivelse</td>
<td class="align-middle">
<InputText id="description" class="form-control" @bind-Value="_workplace.Description"/>
<ValidationMessage For="@(() => _workplace.Description)"></ValidationMessage>
</td>
</tr>
<tr>
<th class="align-middle text-center" colspan="4">Placering og Opbevaring</th>
</tr>
<tr>
<td class="align-middle">Produkter</td>
<td class="align-middle">
<InputText id="productStorage" class="form-control" @bind-Value="_workplace.ProductStorage"/>
<ValidationMessage For="@(() => _workplace.ProductStorage)"></ValidationMessage>
</td>
<td class="align-middle" colspan="2"></td>
</tr>
<tr>
<td class="align-middle">Masker</td>
<td class="align-middle">
<InputText id="maskStorage" class="form-control" @bind-Value="_workplace.MaskStorage"/>
<ValidationMessage For="@(() => _workplace.MaskStorage)"></ValidationMessage>
</td>
<td class="align-middle">Øjenskylleflaske</td>
<td class="align-middle">
<InputText id="eyeCleanerLocation" class="form-control" @bind-Value="_workplace.EyeCleanerLocation"/>
<ValidationMessage For="@(() => _workplace.EyeCleanerLocation)"></ValidationMessage>
</td>
</tr>
<tr>
<td class="align-middle">Handsker</td>
<td class="align-middle">
<InputText id="glovesStorage" class="form-control" @bind-Value="_workplace.GlovesStorage"/>
<ValidationMessage For="@(() => _workplace.GlovesStorage)"></ValidationMessage>
</td>
<td class="align-middle">Førstehjælp</td>
<td class="align-middle">
<InputText id="firstAidStorage" class="form-control" @bind-Value="_workplace.FirstAidStorage"/>
<ValidationMessage For="@(() => _workplace.FirstAidStorage)"></ValidationMessage>
</td>
</tr>
<tr>
<td class="align-middle">Sikkerhedsbriller</td>
<td class="align-middle">
<InputText id="gogglesStorage" class="form-control" @bind-Value="_workplace.GogglesStorage"/>
<ValidationMessage For="@(() => _workplace.GogglesStorage)"></ValidationMessage>
</td>
<td class="align-middle" colspan="2"></td>
</tr>
<tr>
<td class="align-middle">Affald</td>
<td class="align-middle">
<InputText id="masteDeposit" class="form-control" @bind-Value="_workplace.WasteDeposit"/>
<ValidationMessage For="@(() => _workplace.WasteDeposit)"></ValidationMessage>
</td>
<td class="align-middle" colspan="2"></td>
</tr>
</tbody>
</table>
<div class="row mb-2">
<div class="col-md-4">
<button type="button" class="btn btn-danger" @onclick="DeleteWorkplace">Slet</button>
</div>
<div>
@_workplace.Name
<div class="col-md-4">
<button type="submit" class="btn btn-success">Gem</button>
</div>
<div>
@_workplace.Description
</div>
<div>
@_workplace.ShortUrl
<div class="col-md-4">
<a class="btn btn-primary" href="/companies/@CompanyId/workplaces/@WorkplaceId/documents">Dokumenter</a>
</div>
</div>
</EditForm>
</div>
</div>

View file

@ -1,8 +1,10 @@
using System.Text.Json;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Wonky.Entity.DTO;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
@ -13,17 +15,31 @@ public partial class WorkplaceViewPage : IDisposable
[Inject] private IWorkplaceHttpRepository _workplaceRepo { get; set; }
[Inject] private ICompanyHttpRepository _companyRepo { get; set; }
[Inject] private HttpInterceptorService _interceptor { get; set; }
[Inject] private NavigationManager _navigator { get; set; }
private WorkplaceDto _workplace { get; set; } = new();
private CompanyDto _company { get; set; } = new();
private EditContext _editContext { get; set; }
protected override async Task OnParametersSetAsync()
{
_interceptor.RegisterEvent();
_interceptor.RegisterBeforeSendEvent();
_company = await _companyRepo.GetCompanyById(CompanyId);
_workplace = await _workplaceRepo.GetWorkplace(CompanyId, WorkplaceId);
}
Console.WriteLine(JsonSerializer.Serialize(_workplace));
protected override void OnInitialized()
{
_editContext = new EditContext(_workplace);
}
private async Task SubmitUpdate()
{
await _workplaceRepo.UpdateWorkplace(CompanyId, _workplace);
}
private async Task DeleteWorkplace()
{
await _workplaceRepo.DeleteWorkplace(CompanyId, _workplace.WorkplaceId);
_navigator.NavigateTo($"/companies/{CompanyId}/workplaces");
}
public void Dispose()

View file

@ -0,0 +1,121 @@
@*
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
*@
@page "/xtest"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "Advisor")]
<div class="row">
<div class="col">
@* Order draft lines *@
<table class="sticky-top table table-hover table-striped table-bordered">
<thead>
<tr class="bg-dark text-white">
<th scope="col" colspan="6">
Ordrekladde <span class="mx-2 draft-expires-msg">Global kladde (udløber efter @(DraftStateProvider.Draft.TimeToLiveInSeconds / 60)m inaktivitet)</span>
</th>
<th scope="col" class="text-end">
<button type="button" class="btn btn-danger btn-sm" @onclick="@DeleteDraft" disabled="@(DraftStateProvider.Draft.Items.Count == 0)">Slet kladde</button>
</th>
</tr>
<tr class="bg-dark opacity-75 text-white">
<th scope="col">Navn</th>
<th scope="col" class="text-nowrap">Varenr</th>
<th scope="col" class="text-end">Antal</th>
<th scope="col" class="text-end">Enhedspris</th>
<th scope="col" class="text-end">Linjesum</th>
<th scope="col" class="text-end">SAS</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@if (DraftStateProvider != null && DraftStateProvider.Draft.Items.Count > 0)
{
@foreach (var cartItem in DraftStateProvider.Draft.Items)
{
<tr>
<td class="align-middle">@cartItem.Item.Name</td>
<td class="align-middle">@cartItem.Item.Sku</td>
<td class="align-middle text-end">@cartItem.Quantity</td>
<td class="align-middle text-end">@cartItem.Price</td>
<td class="align-middle text-end">@cartItem.LineTotal</td>
<td class="align-middle text-center">
<input type="checkbox" checked="@cartItem.Sas" disabled/>
</td>
<td class="align-middle text-end">
<button type="button" class="btn btn-danger" @onclick="@(() => RemoveItem(cartItem))">Slet Linje</button>
</td>
</tr>
}
}
<tr>
<td></td>
<td></td>
<td></td>
<td class="align-middle text-black text-end fw-bold">Total</td>
<td class="align-middle text-black text-end fw-bold">@DraftStateProvider.Draft.Total</td>
<td></td>
<td class="align-middle text-end"><button class="btn btn-primary" type="button" @onclick="CallPriceListModal"><i class="oi oi-plus"></i></button></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col">
@* draft line *@
@if (_selectedItem != null && ShowItem)
{
<table id="draft-line" class="table table-bordered">
<thead>
<tr class="bg-dark text-white">
<th scope="col" colspan="6">Kladdelinje</th>
</tr>
<tr>
<th scope="col">Antal</th>
<th scope="col">Pris</th>
<th scope="col">Rabat</th>
<th class="align-content-center justify-content-center" scope="col">SAS</th>
<th scope="col">Varenr.</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr>
<td class="align-middle">
<input type="number" class="form-control" @bind-value="@Quantity"/>
</td>
<td class="align-middle">
<input type="number" class="form-control" @bind-value="@Price"/>
</td>
<td class="align-middle">
<input type="number" class="form-control" @bind-value="@Discount"/>
</td>
<td class="align-middle align-content-center justify-content-center">
<input type="checkbox" class="form-check" @bind-value="@Sas"/>
</td>
<td class="align-middle">@_selectedItem.Sku</td>
<td class="align-middle">
<button type="button" class="btn btn-warning text-nowrap d-block" @onclick="@(() => AddItem(_selectedItem))">bestil @Quantity stk @_selectedItem.Name</button>
</td>
</tr>
</tbody>
</table>
}
</div>
</div>
<PriceListModal OnSelectedItem="SelectSku" @ref="_priceList" />

View file

@ -0,0 +1,102 @@
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
using System.Globalization;
using System.Text.Json;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Wonky.Client.Models;
using Microsoft.AspNetCore.Components;
using Wonky.Client.Shared;
using Wonky.Entity.Views;
namespace Wonky.Client.Pages;
public partial class XTestPriceListPopupPage : IDisposable
{
[Inject] private ISalesItemHttpRepository _itemRepo { get; set; }
[Inject] private HttpInterceptorService _interceptor { get; set; }
[CascadingParameter] DraftStateProvider DraftStateProvider { get; set; }
private string Quantity = "1";
private string Price = "0";
private string Discount = "0";
private bool ShowItem { get; set; }
private bool Sas { get; set; }
private SalesItemView _selectedItem { get; set; } = new();
private PriceListModal _priceList = new();
private SelectedSku _sku { get; set; } = new();
protected override async Task OnInitializedAsync()
{
_interceptor.RegisterEvent();
_interceptor.RegisterBeforeSendEvent();
}
private void CallPriceListModal()
{
_priceList.Show();
}
private async Task SelectSku(SelectedSku sku)
{
ShowItem = true;
Console.WriteLine($"XTextPriceList => sku: {JsonSerializer.Serialize(sku)}");
_selectedItem = await _itemRepo.GetSalesItem(sku.ItemId);
Price = sku.Rate;
Quantity = sku.Quantity;
}
private async Task DeleteDraft()
{
await DraftStateProvider.DeleteDraftAsync();
}
private async Task AddItem(SalesItemView salesItem)
{
ShowItem = false;
// create a new cart item
var item = new DraftItem
{
Item = salesItem,
Quantity = Convert.ToInt32(Quantity),
Price = Convert.ToDecimal(Price, CultureInfo.InvariantCulture),
Discount = Convert.ToDecimal(Discount, CultureInfo.InvariantCulture),
Sas = Sas
};
// reset internals to initial state
Sas = false;
Quantity = "1";
Price = "0";
Discount = "0";
// add it to the cart
DraftStateProvider.Draft.Items.Add(item);
// save the item using the CartStateProvider's save method
await DraftStateProvider.SaveChangesAsync();
}
private async Task RemoveItem(DraftItem item)
{
// remove item
DraftStateProvider.Draft.Items.Remove(item);
// save the remaining draft
await DraftStateProvider.SaveChangesAsync();
}
public void Dispose()
{
_interceptor.DisposeEvent();
}
}

View file

@ -0,0 +1,93 @@
@*
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
*@
@using Wonky.Client.Components
@using Wonky.Client.Helpers
<div class="modal" tabindex="-1" role="dialog" style="display:@_modalDisplay">
<div class="modal-dialog modal-lg modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Pris Katalog</h5>
<button type="button" class="btn-close" @onclick="Hide" data-bs-dismiss="modal" aria-label="Luk"></button>
</div>
<div class="modal-body">
<div class="sticky-top bg-dark rounded-2 p-3">
<div class="row">
<div class="col">
<ItemSearchComponent OnChanged="SetSearchCol"/>
</div>
<div class="col">
<SearchPhraseComponent OnChanged="SetSearchPhrase"/>
</div>
@* <div class="col"> *@
@* <ItemSortComponent OnChanged="SetSortCol"/> *@
@* </div> *@
<div class="col">
<PageSizeComponent OnChanged="SetPageSize"/>
</div>
</div>
</div>
@if (_items.Any())
{
<ul class="list-group">
@foreach (var item in _items)
{
<li class="list-group-item">
<div class="row align-middle">
<div class="col-sm-4 text-sm-start">
@item.Name
</div>
<div class="col-sm-2 text-sm-start">
@item.Sku
</div>
<div class="col-sm-2 text-sm-start">
@item.ShortName
</div>
<div class="col-sm-4">
<ul class="list-group">
@foreach (var rate in item.Rates)
{
<li class="list-group-item d-flex justify-content-between align-items-end">
<div class="text-sm-end me-1">@rate.Quantity</div>
<div class="text-sm-end me-1">@rate.Rate</div>
<div>
<a class="btn btn-primary btn-sm" @onclick="@(() => SelectItem(item.ItemId, rate.Quantity, rate.Rate))">
<i class="oi oi-plus"></i>
</a>
</div>
</li>
}
</ul>
</div>
</div>
</li>
}
</ul>
}
else
{
<div>Der er ingen data</div>
}
</div>
</div>
</div>
</div>
@if (_showBackdrop)
{
<div class="modal-backdrop fade show"></div>
}

View file

@ -0,0 +1,107 @@
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
//
using Microsoft.AspNetCore.Components;
using Wonky.Client.HttpInterceptors;
using Wonky.Client.HttpRepository;
using Wonky.Client.Models;
using Wonky.Client.Services;
using Wonky.Entity.Requests;
using Wonky.Entity.Views;
namespace Wonky.Client.Shared;
public partial class PriceListModal : IDisposable
{
private string _modalDisplay = "";
private bool _showBackdrop;
private List<SalesItemView> _items { get; set; } = new();
[Parameter] public EventCallback<SelectedSku> OnSelectedItem { get; set; }
[Inject] private ISalesItemHttpRepository _itemRepo { get; set; }
[Inject] private HttpInterceptorService _interceptor { get; set; }
[Inject] private UserPreferenceService _preferenceService { get; set; }
private MetaData? _metaData { get; set; } = new();
private CatalogPagingParams _paging = new();
private Preferences _preferences = new();
protected override async Task OnInitializedAsync()
{
_preferences = await _preferenceService.GetPreferences();
_paging.OrderBy = _preferences.ItemSort;
_paging.SearchColumn = _preferences.ItemSort;
_paging.PageSize = Convert.ToInt32((_preferences.PageSize));
_interceptor.RegisterEvent();
await GetSalesItems();
}
public void Show()
{
_modalDisplay = "block;";
_showBackdrop = true;
StateHasChanged();
}
private void SelectItem(string itemId, string quantity, string rate)
{
OnSelectedItem.InvokeAsync(new SelectedSku { Quantity = quantity, Rate = rate, ItemId = itemId });
Hide();
}
private void Hide()
{
_modalDisplay = "none;";
_showBackdrop = false;
StateHasChanged();
}
private async Task GetSalesItems()
{
var pagingResponse = await _itemRepo.GetSalesItemsPaged(_paging);
_items = pagingResponse.Items!;
_metaData = pagingResponse.MetaData;
}
private async Task SetPageSize(string pageSize)
{
_items = new List<SalesItemView>();
_paging.PageSize = Convert.ToInt32(pageSize);
_paging.PageNumber = 1;
await GetSalesItems();
}
private async Task SetSearchCol(string columnName)
{
_items = new List<SalesItemView>();
_paging.PageNumber = 1;
_paging.SearchColumn = columnName;
await GetSalesItems();
}
private async Task SetSearchPhrase(string searchTerm)
{
_items = new List<SalesItemView>();
_paging.PageNumber = 1;
_paging.SearchTerm = searchTerm;
await GetSalesItems();
}
private async Task SetSortCol(string orderBy)
{
_items = new List<SalesItemView>();
_paging.OrderBy = orderBy;
await GetSalesItems();
}
public void Dispose() => _interceptor.DisposeEvent();
}

View file

@ -1,9 +1,55 @@
using System.ComponentModel.DataAnnotations;
namespace Wonky.Entity.DTO;
public class WorkplaceDto
{
/// <summary>
/// Workplace entity id
/// </summary>
public string WorkplaceId { get; set; } = "";
public string Name { get; set; } = "";
public string Description { get; set; } = "";
/// <summary>
/// Company name
/// </summary>
public string CompanyName { get; set; } = "";
/// <summary>
/// Workplace name
/// </summary>
[Required(ErrorMessage = "Navn skal angives")] [MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string Name { get; set; } = "";
/// <summary>
/// Workplace description
/// </summary>
[MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string Description { get; set; } = "";
/// <summary>
/// Short url to document overview
/// </summary>
public string ShortUrl { get; set; } = "";
/// <summary>
/// Product storage location
/// </summary>
[Required(ErrorMessage = "Opbevaringssted skal angives")] [MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string ProductStorage { get; set; } = "";
/// <summary>
/// Mask storage location
/// </summary>
[Required(ErrorMessage = "Opbevaringssted skal angives")] [MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string MaskStorage { get; set; } = "";
/// <summary>
/// Gloves storage location
/// </summary>
[Required(ErrorMessage = "Opbevaringssted skal angives")] [MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string GlovesStorage { get; set; } = "";
/// <summary>
/// Goggles storage location
/// </summary>
[Required(ErrorMessage = "Opbevaringssted skal angives")] [MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string GogglesStorage { get; set; } = "";
/// <summary>
/// Eye cleaner storage location
/// </summary>
[Required(ErrorMessage = "Opbevaringssted skal angives")] [MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string EyeCleanerLocation { get; set; } = "";
/// <summary>
/// First aid storage location
/// </summary>
[Required(ErrorMessage = "Opbevaringssted skal angives")] [MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string FirstAidStorage { get; set; } = "";
/// <summary>
/// Waste deposit location
/// </summary>
[Required(ErrorMessage = "Opbevaringssted skal angives")] [MaxLength(128, ErrorMessage = "Der kan højst anvendes 128 tegn")] public string WasteDeposit { get; set; } = "";
}

View file

@ -0,0 +1,9 @@
namespace Wonky.Entity.Views;
public class WorkplaceListView
{
public string WorkplaceId { get; set; } = "";
public string Name { get; set; } = "";
public string Description { get; set; } = "";
public string ShortUrl { get; set; } = "";
}