Files
mapo-core/MP.Prog/Components/CodArtSelector.razor
T
2021-09-06 18:34:38 +02:00

110 lines
2.8 KiB
Plaintext

@using MP.FileData.DatabaseModels
@using MP.Prog.Data
@inject FileArchDataService DataService
@inject MessageService AppMService
@if (ArtList == null)
{
<LoadingData></LoadingData>
}
else
{
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-search" aria-hidden="true"></span>
</span>
</div>
<input type="text" class="form-control form-control-sm" placeholder="Ricerca Articolo" @bind-value="@SearchArt" />
<select @bind="@SelCodArt" class="form-control form-control-sm">
@if (ArtList != null)
{
foreach (var item in ArtList)
{
<option value="@item.CodArticolo">@item.Disegno | @item.DescArticolo [@item.CodArticolo]</option>
}
}
</select>
<div class="input-group-append">
<button id="searchReset" class="btn btn-sm btn-secondary" @onclick="() => ResetSearchArt()" title="Reset ricerca articolo"><i class="fas fa-ban"></i></button>
</div>
</div>
}
@code {
[Parameter]
public EventCallback<string> searchUpdated { get; set; }
[Parameter]
public string SelCodArt
{
get
{
string answ = "";
if (AppMService.File_Filter != null)
{
answ = AppMService.File_Filter.CodArticolo;
}
return answ;
}
set
{
if (!AppMService.File_Filter.CodArticolo.Equals(value))
{
AppMService.File_Filter.CodArticolo = value;
}
reportChange();
}
}
private void reportChange()
{
searchUpdated.InvokeAsync(SelCodArt);
}
protected string _SearchArt;
protected string defCodArt = "";
protected List<ArticoloModel> ArtList;
protected string SearchArt
{
get
{
return _SearchArt;
}
set
{
_SearchArt = value;
// se son > 3 char... debounce...
if (string.IsNullOrEmpty(value))
{
_SearchArt = defCodArt;
}
if (value.Length >= defCodArt.Length)
{
var pUpd = Task.Run(async () =>
{
ArtList = await DataService.ArticoliGetFilt(SearchArt);
});
pUpd.Wait();
}
}
}
protected override async Task OnInitializedAsync()
{
await ReloadAllData();
_SearchArt = defCodArt;
}
protected async Task ReloadAllData()
{
SelCodArt = defCodArt;
ArtList = await DataService.ArticoliGetFilt(SearchArt);
}
protected void ResetSearchArt()
{
SearchArt = defCodArt;
}
}