OK WebAPI!!! legge elenco articoli filtrati
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
|
||||
@using NLog;
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http.Json
|
||||
|
||||
@inject HttpClient Http
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-3 mb-2">
|
||||
@@ -9,18 +13,26 @@
|
||||
</div>
|
||||
<div class="col-12 col-md-6 mb-2">
|
||||
<div class="form-floating">
|
||||
<select class="form-select" disabled="@ListArtDisabled">
|
||||
<option value="0" selected>-- Selezione Articolo --</option>
|
||||
<option value="1">One</option>
|
||||
<option value="2">Two</option>
|
||||
<option value="3">Three</option>
|
||||
<select class="form-select" disabled="@ListArtDisabled" @bind="@CodArtSel">
|
||||
<option value="" selected>-- No Select --</option>
|
||||
@if (ListArticoli == null)
|
||||
{
|
||||
<option value="" disabled>No record found</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var item in ListArticoli)
|
||||
{
|
||||
<option value="@item.CodArticolo">@item.CodArticolo | @item.DescArticolo | @item.Disegno</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
<label for="floatingSelect">Selezione Articolo</label>
|
||||
<label for="floatingSelect">Selezione Articolo (@Num2Displ / <b>@TotalCount</b>)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-md-3 mb-2">
|
||||
<div class="form-floating">
|
||||
<select class="form-select" disabled="@ListArtDisabled">
|
||||
<select class="form-select" disabled="@ListMacDisabled">
|
||||
<option value="0" selected>-- Selezione Impianto --</option>
|
||||
<option value="1">One</option>
|
||||
<option value="2">Two</option>
|
||||
@@ -82,10 +94,46 @@
|
||||
|
||||
@code {
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
await ReloadAllData();
|
||||
}
|
||||
|
||||
// protected override Task OnInitializedAsync()
|
||||
// {
|
||||
// return base.OnInitializedAsync();
|
||||
// }
|
||||
|
||||
string BaseAddr = "https://localhost:7057/MP/TAB2/";
|
||||
|
||||
protected async Task ReloadAllData()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(SearchVal))
|
||||
{
|
||||
string ArtApiUrl = $"{BaseAddr}api/ListSelect/GetArticoli?SearchArt={SearchVal}";
|
||||
var rawData = await Http.GetFromJsonAsync<List<AnagArticoli>>(ArtApiUrl);
|
||||
if (rawData != null)
|
||||
{
|
||||
ListArticoliAll = rawData;
|
||||
}
|
||||
|
||||
if (ListArticoliAll != null)
|
||||
{
|
||||
TotalCount = ListArticoliAll.Count;
|
||||
ListArticoli = ListArticoliAll.Take(Num2Displ).ToList();
|
||||
}
|
||||
}
|
||||
await Task.Delay(1);
|
||||
}
|
||||
|
||||
|
||||
protected bool ListArtDisabled
|
||||
{
|
||||
get => string.IsNullOrEmpty(SearchVal) || SearchVal.Length < 3;// ? "disabled" : "";
|
||||
get => string.IsNullOrEmpty(SearchVal) || SearchVal.Length < SearchMinChar;
|
||||
}
|
||||
protected bool ListMacDisabled
|
||||
{
|
||||
get => string.IsNullOrEmpty(CodArtSel);
|
||||
}
|
||||
|
||||
protected async Task FixDisplay()
|
||||
@@ -94,7 +142,6 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected string SearchVal
|
||||
{
|
||||
get => searchVal;
|
||||
@@ -103,17 +150,36 @@
|
||||
if (searchVal != value)
|
||||
{
|
||||
searchVal = value;
|
||||
// InvokeAsync(StateHasChanged).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
// await E_SearchUpd.InvokeAsync(value);
|
||||
// await Task.Delay(1);
|
||||
await ReloadAllData();
|
||||
});
|
||||
pUpd.Wait();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"SearchVal{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private string searchVal { get; set; } = "";
|
||||
|
||||
|
||||
protected string CodArtSel { get; set; } = "";
|
||||
|
||||
|
||||
[Parameter]
|
||||
public int SearchMinChar { get; set; }
|
||||
[Parameter]
|
||||
public EventCallback<string> E_SearchUpd { get; set; }
|
||||
|
||||
|
||||
|
||||
@@ -124,28 +190,18 @@
|
||||
[Parameter]
|
||||
public List<AnagArticoli> ListArticoliAll { get; set; } = new List<AnagArticoli>();
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<TcFilt> E_FiltUpdated { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public int MatrOpr { get; set; } = 102;
|
||||
[Parameter]
|
||||
public string Title { get; set; } = "TC History";
|
||||
|
||||
public class TcFilt
|
||||
{
|
||||
public string SearchVal { get; set; } = "";
|
||||
public string Azienda { get; set; } = "*";
|
||||
}
|
||||
|
||||
protected int MaxRec { get; set; } = 100000;
|
||||
protected int Num2Displ { get; set; } = 10;
|
||||
protected int Num2Displ { get; set; } = 50;
|
||||
protected int TotalCount { get; set; } = 0;
|
||||
|
||||
|
||||
|
||||
protected List<AnagArticoli>? ListArticoli { get; set; } = null;
|
||||
protected TcFilt CurrFilt { get; set; } = new TcFilt();
|
||||
|
||||
protected void LoadMore()
|
||||
{
|
||||
@@ -157,18 +213,7 @@
|
||||
}
|
||||
|
||||
|
||||
protected async Task ReloadAllData()
|
||||
{
|
||||
TotalCount = ListArticoliAll.Count;
|
||||
ListArticoli = ListArticoliAll.Take(Num2Displ).ToList();
|
||||
await Task.Delay(1);
|
||||
}
|
||||
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
// await ReloadAllData();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,61 +3,8 @@
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<MP_TAB.Client.Components.HistTCFilt Title="Storico Tempi Ciclo"></MP_TAB.Client.Components.HistTCFilt>
|
||||
<MP_TAB.Client.Components.HistTCFilt Title="Storico Tempi Ciclo" SearchMinChar="@SearchMinChar" E_SearchUpd="RepSearchUpd" ListArticoliAll="ListArticoli"></MP_TAB.Client.Components.HistTCFilt>
|
||||
|
||||
|
||||
@* <MP_TAB.Client.Components.HistTCFilt Title="Storico Tempi Ciclo" ListMacchineAll="@ListMacchine" ListArticoliAll="@SearchArticoli" E_FiltUpdated="UpdatedFilt"></MP_TAB.Client.Components.HistTCFilt> *@
|
||||
|
||||
|
||||
@* <div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<h4>Storico Tempi Ciclo</h4>
|
||||
<button class="btn btn-primary" @onclick="LoadMore" title="Show more"><b>+10</b</button>
|
||||
</div>
|
||||
<div class="d-flex flex-row-reverse">
|
||||
<div class="px-1">
|
||||
<div class="input-group" title="Filtro Impianto">
|
||||
<span class="input-group-text"><i class="fa-solid fa-industry"></i></span>
|
||||
<select class="form-select" aria-label="Select Macchina" style="width: 15rem;">
|
||||
<option value="0" selected>-- Selezionare Impianto --</option>
|
||||
@if (ListMacchine == null || ListMacchine.Count == 0)
|
||||
{
|
||||
<b>loading...</b>
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in ListMacchine)
|
||||
{
|
||||
<option value="@item.IdxMacchina">@item.CodMacchina | @item.Descrizione</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="px-1">
|
||||
<div class="input-group" title="Filtro Articolo">
|
||||
<span class="input-group-text"><i class="fa-solid fa-box"></i></span>
|
||||
<input class="form-control" style="width: 4rem;" placeholder="*" title="Ricerca Articolo" @bind="@SearchVal" />
|
||||
<select class="form-select" aria-label="Select Articolo" style="width: 25rem;">
|
||||
<option value="*" selected>-- Selezionare Articolo --</option>
|
||||
@if (ListArticoli == null || ListArticoli.Count == 0)
|
||||
{
|
||||
<b>loading...</b>
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in ListArticoli)
|
||||
{
|
||||
<option value="@item.CodArticolo">@item.CodArticolo | @item.DescArticolo</option>
|
||||
}
|
||||
<option disabled>...totale @TotalCount rec</option>
|
||||
}
|
||||
</select>
|
||||
<button class="btn btn-primary" @onclick="LoadMore" title="Show more"><b>+10</b</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> *@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (ListArticoli != null)
|
||||
@@ -85,4 +32,15 @@
|
||||
@code {
|
||||
[Parameter]
|
||||
public List<AnagArticoli>? ListArticoli { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public int SearchMinChar { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> E_FiltSearchUpd { get; set; }
|
||||
|
||||
protected async Task RepSearchUpd(string newSearch)
|
||||
{
|
||||
await E_FiltSearchUpd.InvokeAsync(newSearch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,11 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
|
||||
// aggiunto x gestione chiamate WebAPI
|
||||
builder.Services.AddScoped(sp =>
|
||||
new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
|
||||
});
|
||||
|
||||
await builder.Build().RunAsync();
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
@page "/tc-history"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<MP_TAB.Client.Pages.TCHistory ListArticoli="@ListArticoli"></MP_TAB.Client.Pages.TCHistory>
|
||||
|
||||
|
||||
|
||||
|
||||
<MP_TAB.Client.Pages.TCHistory SearchMinChar="@SrcMinChar" E_FiltSearchUpd="DoSearchUpd" ListArticoli="@SearchArticoli"></MP_TAB.Client.Pages.TCHistory>
|
||||
|
||||
@@ -27,8 +27,6 @@ namespace MP_TAB.Components.Pages
|
||||
|
||||
protected string azienda { get; set; } = "*";
|
||||
|
||||
protected List<AnagArticoli>? ListArticoli { get; set; } = null;
|
||||
|
||||
protected List<Macchine>? ListMacchine { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
@@ -39,28 +37,25 @@ namespace MP_TAB.Components.Pages
|
||||
[Inject]
|
||||
protected OprFiltData MDataService { get; set; } = null!;
|
||||
|
||||
protected int num2Displ { get; set; } = 10;
|
||||
protected int NumRec { get; set; } = 100000;
|
||||
protected List<AnagArticoli>? SearchArticoli { get; set; } = null;
|
||||
protected List<AnagArticoli> SearchArticoli { get; set; } = new List<AnagArticoli>();
|
||||
protected string SearchVal { get; set; } = "";
|
||||
protected int SrcMinChar { get; set; } = 3;
|
||||
protected int TotalCount { get; set; } = 0;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected void LoadMore()
|
||||
protected async Task DoSearchUpd(string newSearch)
|
||||
{
|
||||
ListArticoli = null;
|
||||
// await Task.Delay(1);
|
||||
num2Displ += 10;
|
||||
num2Displ = num2Displ < TotalCount ? num2Displ : TotalCount;
|
||||
ListArticoli = SearchArticoli?.Take(num2Displ).ToList();
|
||||
SearchVal = newSearch;
|
||||
await ReloadFiltData();
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await ReloadAllData();
|
||||
//await ReloadAllData();
|
||||
}
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
@@ -72,20 +67,23 @@ namespace MP_TAB.Components.Pages
|
||||
protected async Task ReloadAllData()
|
||||
{
|
||||
await ReloadFiltData();
|
||||
TotalCount = SearchArticoli.Count;
|
||||
ListArticoli = SearchArticoli.Take(num2Displ).ToList();
|
||||
TotalCount = SearchArticoli != null ? SearchArticoli.Count : 0;
|
||||
}
|
||||
|
||||
protected async Task ReloadFiltData()
|
||||
{
|
||||
SearchArticoli = await MDataService.ArticoliGetSearch(NumRec, azienda, SearchVal);
|
||||
// ricarica SOLO SE ho almeno un filtro valido...
|
||||
if (!string.IsNullOrEmpty(SearchVal))
|
||||
{
|
||||
SearchArticoli = await MDataService.ArticoliGetSearch(NumRec, azienda, SearchVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
SearchArticoli = new List<AnagArticoli>();
|
||||
}
|
||||
ListMacchine = await MDataService.MacchineByMatrOper(MatrOpr);
|
||||
}
|
||||
|
||||
protected async void UpdatedFilt()
|
||||
{
|
||||
await ReloadFiltData();
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.Data.DatabaseModels;
|
||||
using MP.Data.Services;
|
||||
using NLog;
|
||||
using NLog.Fluent;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace MP_TAB.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ListSelectController : ControllerBase
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public ListSelectController(IConfiguration configuration, OprFiltData DataService)
|
||||
{
|
||||
Log.Info("Starting ListSelectController");
|
||||
_configuration = configuration;
|
||||
FiltDataServ = DataService;
|
||||
Log.Info("Avviato ListSelectController");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
// GET: api/ListSelect
|
||||
[HttpGet]
|
||||
public string Get()
|
||||
{
|
||||
return "OK";
|
||||
}
|
||||
|
||||
[HttpGet("GetArticoli")]
|
||||
public async Task<List<AnagArticoli>> GetArticoli(string SearchArt, string Azienda = "*", int NumRec = 100000)
|
||||
{
|
||||
List<AnagArticoli> answ = new List<AnagArticoli>();
|
||||
await Task.Delay(1);
|
||||
try
|
||||
{
|
||||
answ = await FiltDataServ.ArticoliGetSearch(NumRec, Azienda, SearchArt);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in GetArticoli | SearchArt: {SearchArt} | Azienda: {Azienda} | NumRec: {NumRec}{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private OprFiltData FiltDataServ { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using MP_TAB.Components;
|
||||
using MP.Data.Services;
|
||||
using StackExchange.Redis;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
ConfigurationManager configuration = builder.Configuration;
|
||||
@@ -20,7 +21,12 @@ builder.Services.AddSingleton<OprFiltData>();
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddServerComponents()
|
||||
.AddWebAssemblyComponents();
|
||||
// controller API
|
||||
builder.Services.AddControllers();
|
||||
// HTTP client x accesso a WebAPI
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
// costruisco app
|
||||
var app = builder.Build();
|
||||
|
||||
// aggiunt base URL x routing corretto
|
||||
@@ -47,4 +53,6 @@ app.MapRazorComponents<App>()
|
||||
.AddServerRenderMode()
|
||||
.AddWebAssemblyRenderMode();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"maxAge": "2000"
|
||||
},
|
||||
"OptConf": {
|
||||
"BaseAddr": "https://localhost:7057/MP/TAB2/",
|
||||
"BaseUrl": "/MP/TAB2",
|
||||
"ImgBasePath": "C:\\Steamware\\macchine"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user