diff --git a/MP-TAB/MP-TAB.Client/Components/HistTCFilt.razor b/MP-TAB/MP-TAB.Client/Components/HistTCFilt.razor index 119171dc..a1306c70 100644 --- a/MP-TAB/MP-TAB.Client/Components/HistTCFilt.razor +++ b/MP-TAB/MP-TAB.Client/Components/HistTCFilt.razor @@ -1,4 +1,8 @@ - +@using NLog; +@using System.Net.Http +@using System.Net.Http.Json + +@inject HttpClient Http
@@ -9,18 +13,26 @@
- + + @if (ListArticoli == null) + { + + } + else + { + @foreach (var item in ListArticoli) + { + + } + } - +
- @@ -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>(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 E_SearchUpd { get; set; } @@ -124,28 +190,18 @@ [Parameter] public List ListArticoliAll { get; set; } = new List(); - [Parameter] - public EventCallback 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? 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(); - } - } diff --git a/MP-TAB/MP-TAB.Client/Pages/TCHistory.razor b/MP-TAB/MP-TAB.Client/Pages/TCHistory.razor index 29d5b00e..bb9664f0 100644 --- a/MP-TAB/MP-TAB.Client/Pages/TCHistory.razor +++ b/MP-TAB/MP-TAB.Client/Pages/TCHistory.razor @@ -3,61 +3,8 @@
- + - - @* *@ - - - @*
-
-

Storico Tempi Ciclo

-
-
-
-
- - -
-
-
-
- - - -
-
-
-
*@
@if (ListArticoli != null) @@ -85,4 +32,15 @@ @code { [Parameter] public List? ListArticoli { get; set; } + + [Parameter] + public int SearchMinChar { get; set; } + + [Parameter] + public EventCallback E_FiltSearchUpd { get; set; } + + protected async Task RepSearchUpd(string newSearch) + { + await E_FiltSearchUpd.InvokeAsync(newSearch); + } } diff --git a/MP-TAB/MP-TAB.Client/Program.cs b/MP-TAB/MP-TAB.Client/Program.cs index 519269f2..7eeaa159 100644 --- a/MP-TAB/MP-TAB.Client/Program.cs +++ b/MP-TAB/MP-TAB.Client/Program.cs @@ -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(); diff --git a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor index 0a3e0bd8..58c4144b 100644 --- a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor +++ b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor @@ -1,11 +1,4 @@ @page "/tc-history" - - - - - - - - + diff --git a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor.cs b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor.cs index dcdb818f..a0ea8578 100644 --- a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor.cs +++ b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor.cs @@ -27,8 +27,6 @@ namespace MP_TAB.Components.Pages protected string azienda { get; set; } = "*"; - protected List? ListArticoli { get; set; } = null; - protected List? ListMacchine { get; set; } = null; /// @@ -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? SearchArticoli { get; set; } = null; + protected List SearchArticoli { get; set; } = new List(); 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(); + } ListMacchine = await MDataService.MacchineByMatrOper(MatrOpr); } - protected async void UpdatedFilt() - { - await ReloadFiltData(); - } #endregion Protected Methods } diff --git a/MP-TAB/MP-TAB/Controllers/ListSelectController.cs b/MP-TAB/MP-TAB/Controllers/ListSelectController.cs new file mode 100644 index 00000000..7128ed8a --- /dev/null +++ b/MP-TAB/MP-TAB/Controllers/ListSelectController.cs @@ -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> GetArticoli(string SearchArt, string Azienda = "*", int NumRec = 100000) + { + List answ = new List(); + 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 + } +} \ No newline at end of file diff --git a/MP-TAB/MP-TAB/Program.cs b/MP-TAB/MP-TAB/Program.cs index 3a4abb8b..e453684f 100644 --- a/MP-TAB/MP-TAB/Program.cs +++ b/MP-TAB/MP-TAB/Program.cs @@ -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(); 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() .AddServerRenderMode() .AddWebAssemblyRenderMode(); +app.MapControllers(); + app.Run(); diff --git a/MP-TAB/MP-TAB/appsettings.json b/MP-TAB/MP-TAB/appsettings.json index de143ab9..b2c98d8a 100644 --- a/MP-TAB/MP-TAB/appsettings.json +++ b/MP-TAB/MP-TAB/appsettings.json @@ -17,6 +17,7 @@ "maxAge": "2000" }, "OptConf": { + "BaseAddr": "https://localhost:7057/MP/TAB2/", "BaseUrl": "/MP/TAB2", "ImgBasePath": "C:\\Steamware\\macchine" }