Fix selezione key in cascata

This commit is contained in:
Samuele Locatelli
2024-02-02 11:31:24 +01:00
parent abd4f94279
commit f54e5702c2
22 changed files with 210 additions and 149 deletions
+58 -23
View File
@@ -31,29 +31,11 @@ namespace MagMan.Core.Services
public event Action EA_SearchUpdated = null!;
public event Action EA_ShowSearch = null!;
public event Action EA_CustomerSel = null!;
public event Action EA_KeySel = null!;
public event Action<bool> EA_ShowCustomers = null!;
#endregion Public Events
#if false
public SelectData DetailFilter
{
get => _detailFilter;
set
{
if (_detailFilter != value)
{
_detailFilter = value;
if (EA_FilterUpdated != null)
{
EA_FilterUpdated?.Invoke();
}
}
}
}
public SelectOrderData Order_Filter { get; set; } = SelectOrderData.Init(5, 30);
#endif
#region Public Properties
@@ -114,7 +96,23 @@ namespace MagMan.Core.Services
}
}
}
}
}
public int KeyNum
{
get => _keyNum;
set
{
if (_keyNum != value)
{
_keyNum = value;
if (EA_KeySel != null)
{
EA_KeySel?.Invoke();
}
}
}
}
public string SelOrderCode { get; set; } = "";
public string SelPlantId { get; set; } = "0";
@@ -145,6 +143,23 @@ namespace MagMan.Core.Services
}
}
public bool ShowCustomers
{
get => _showCustomers;
set
{
if (_showCustomers != value)
{
_showCustomers = value;
if (EA_ShowCustomers != null)
{
EA_ShowCustomers?.Invoke(value);
}
}
}
}
/// <summary>
/// Cliente selezionato (da browser data cache)
/// </summary>
@@ -157,9 +172,27 @@ namespace MagMan.Core.Services
/// <summary>
/// Imposta Cliente selezionato (browser data cache)
/// </summary>
public async Task ClientIdSet(int machSel)
public async Task ClientIdSet(int newVal)
{
await localStore.SetItemAsync("ClientID", machSel);
await localStore.SetItemAsync("ClientID", newVal);
}
/// <summary>
/// KeyNum da cliente selezionato (da browser data cache)
/// </summary>
public async Task<int> KeyNumGet()
{
var answ = await localStore.GetItemAsync<int>("KeyNum");
return answ;
}
/// <summary>
/// Imposta KeyNum da cliente selezionato (browser data cache)
/// </summary>
public async Task KeyNumSet(int newVal)
{
await localStore.SetItemAsync("KeyNum", newVal);
}
#endregion Public Properties
@@ -503,7 +536,9 @@ namespace MagMan.Core.Services
private string _pageName = "";
private string _searchVal = "";
private int _customerID = -1;
private int _keyNum = -1;
private bool _showSearch = false;
private bool _showCustomers = true;
private Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
+2 -2
View File
@@ -24,10 +24,10 @@ namespace MagMan.Data.Tenant
#region Public Methods
public static async Task<bool> migrateDbMain()
public static async Task<bool> migrateDbMain(string connString)
{
bool answ = false;
using (MagManContext dbCtx = new MagManContext())
using (MagManContext dbCtx = new MagManContext(connString))
{
await dbCtx.Database.MigrateAsync();
answ = true;
+2 -2
View File
@@ -36,10 +36,10 @@ namespace MagMan.Data.Tenant
return $"server={server};port=3306;database={dbName};uid={DATABASE_USER};pwd={DATABASE_PWD};sslmode=None";
}
public static bool ExecMigrationMain()
public static bool ExecMigrationMain(string connString)
{
// esecuzione migrazione
var migrateTask = Task.Run(async () => await DbAdmin.migrateDbMain());
var migrateTask = Task.Run(async () => await DbAdmin.migrateDbMain(connString));
migrateTask.Wait();
return migrateTask.Result;
}
+4 -2
View File
@@ -71,7 +71,9 @@ namespace MagMan.Data.Tenant
if (!optionsBuilder.IsConfigured)
{
#if DEBUG
connString = "Server=localhost;port=3306;database=MagMan_000470;uid=MagMan_DbUser;pwd=viad@nte16!;sslmode=None;";
#if false
connString = "Server=localhost;port=3306;database=MagMan_000470;uid=MagMan_DbUser;pwd=viad@nte16!;sslmode=None;";
#endif
#endif
var serverVersion = ServerVersion.AutoDetect(connString);
optionsBuilder.UseMySql(connString, serverVersion);
@@ -92,7 +94,7 @@ namespace MagMan.Data.Tenant
});
modelBuilder.Entity<AliasModel>()
.HasKey(c => new { c.Family, c.ValueOriginal});
.HasKey(c => new { c.Family, c.ValueOriginal });
modelBuilder.Seed();
+1 -1
View File
@@ -1077,7 +1077,7 @@ namespace MagMan.Data.Tenant.Services
// verifico eventuale creazione/migrazione...
DbConfig.InitDb(DbServerAddr, nKey);
// verifico se serve applicazione migrazioni
DbConfig.ExecMigrationMain();
DbConfig.ExecMigrationMain(answ);
// aggiungo a LUT
ConnStringLUT.Add(nKey, answ);
}
+16 -4
View File
@@ -4,10 +4,22 @@
<option value="0">--- Selezionare Cliente ---</option>
@if (CustomersList != null)
{
@foreach (var item in CustomersList)
{
<option value="@item.CustomerID">@item.Name [@item.CustomerID]</option>
}
<AuthorizeView Roles="SuperAdmin, Admin">
<Authorized>
@foreach (var item in CustomersList)
{
<option value="@item.CustomerID">@item.Name [@item.CustomerID/@item.MainKey]</option>
}
</Authorized>
</AuthorizeView>
<AuthorizeView Roles="User">
<Authorized>
@foreach (var item in CustomersList)
{
<option value="@item.CustomerID">@item.Name [@item.CustomerID]</option>
}
</Authorized>
</AuthorizeView>
}
</select>
</div>
+62 -1
View File
@@ -2,6 +2,7 @@ using MagMan.Core.Services;
using MagMan.Data.Admin.DbModels;
using MagMan.Data.Admin.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
namespace MagMan.UI.Components
{
@@ -21,12 +22,26 @@ namespace MagMan.UI.Components
{
customerID = value;
InvokeAsync(() => AppMService.ClientIdSet(value));
// gestione KeyNum
if (CustomersList != null)
{
var currRec = CustomersList.Find(x => x.CustomerID == customerID);
if (currRec != null)
{
int mKeyNum = currRec.MainKey;
InvokeAsync(() => AppMService.KeyNumSet(mKeyNum));
AppMService.KeyNum = mKeyNum;
}
}
AppMService.CustomerID = value;
InvokeAsync(StateHasChanged);
}
}
}
[Inject]
protected MTAdminService MTService { get; set; } = null!;
@@ -49,11 +64,30 @@ namespace MagMan.UI.Components
protected async Task ReloadData()
{
CustomersList = await MTService.CustomerGetAll();
await GetClaimsData();
var rawList = await MTService.CustomerGetAll();
// se ho un plantId valido --> altrimenti non abilitato
if (ClaimCustomerId == 0)
{
CustomersList = rawList;
}
else if (ClaimCustomerId > 0)
{
CustomersList = rawList.Where(x => x.CustomerID == ClaimCustomerId).ToList();
}
else
{
CustomersList = new List<CustomerModel>();
}
}
#endregion Protected Methods
/// <summary>
/// Valore CustomerID filtrato da claim
/// </summary>
protected int ClaimCustomerId = -1;
#region Private Fields
private int customerID = -1;
@@ -61,5 +95,32 @@ namespace MagMan.UI.Components
private List<CustomerModel>? CustomersList = null;
#endregion Private Fields
[Inject]
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } = null!;
/// <summary>
/// Recupero Claims dell'utente...
///
/// https://docs.microsoft.com/it-it/aspnet/core/blazor/security/?view=aspnetcore-6.0
/// </summary>
/// <returns></returns>
private async Task GetClaimsData()
{
// recupero auth
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
// se autenticato --> controllo i claims
if (user.Identity!=null && user.Identity.IsAuthenticated)
{
// cerco il claim PlantId...
var custClaim = user.FindFirst(c => c.Type == "CustomerID")?.Value;
int.TryParse(custClaim, out ClaimCustomerId);
}
else
{
ClaimCustomerId = -1;
}
}
}
}
+6 -7
View File
@@ -12,12 +12,11 @@
<SearchMod></SearchMod>
</div>
}
<div class="w-50">
<AuthorizeView Roles="SuperAdmin, Admin">
<Authorized>
<CmpSelCliente></CmpSelCliente>
</Authorized>
</AuthorizeView>
</div>
@if (ShowCustomers)
{
<div class="w-50">
<CmpSelCliente></CmpSelCliente>
</div>
}
</div>
</div>
+2
View File
@@ -53,6 +53,8 @@ namespace MagMan.UI.Components
private bool ShowSearch { get; set; } = false;
[CascadingParameter(Name = "ShowCustomers")]
private bool ShowCustomers { get; set; } = true;
#endregion Private Properties
}
+4 -3
View File
@@ -48,12 +48,13 @@ namespace MagMan.UI.Components
dbOk = Data.Admin.DbConfig.CheckCustDb(currRec.MainKey);
}
// se ok --> migration...
if (dbOk || true)
if (dbOk)
{
string dbServerAddr = Configuration["DbConfig:Server"];
Data.Tenant.DbConfig.InitDb(dbServerAddr, currRec.MainKey);
//Data.Tenant.DbConfig.InitDb(dbServerAddr, currRec.MainKey);
string connStr = Data.Tenant.DbConfig.CustomerConnString(dbServerAddr, currRec.MainKey);
// verifico se serve applicazione migrazioni
Data.Tenant.DbConfig.ExecMigrationMain();
Data.Tenant.DbConfig.ExecMigrationMain(connStr);
}
// aggiorno comunque status DB...
currRec.HasDb = dbOk;
@@ -1,89 +0,0 @@
@* @using MagMan.Data
@using MagMan.UI.Data
@using MagMan.UI.Components *@
@* @inject GWMSDataService DataService *@
@inject MessageService AppMService
@inject IJSRuntime JSRuntime
@if (!DbAllOk)
{
<div class="row">
<div class="col-3 text-right">
<h3>DB Init</h3>
</div>
@if (!DbUserOk)
{
<div class="col-3">
<button id="btnReset" class="btn btn-danger btn-block" @onclick="initDb">
<i class="fas fa-database"></i> Init Main DB
</button>
</div>
}
else if (!DbIdentity)
{
<div class="col-3">
<button id="btnReset" class="btn btn-warning btn-block" @onclick="initIdent">
<i class="fas fa-user-shield"></i> Init Ident DB
</button>
</div>
}
</div>
}
@code {
[Parameter]
public EventCallback<int> evRefresh { get; set; }
[Parameter]
public EventCallback<int> evProcessing { get; set; }
protected async Task initDb()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler effettuare inizializzazione/migrazione DB?"))
return;
reportProcess();
await MagMan.Data.Tenant.DbAdmin.migrateDbMain();
await ReloadData();
reportChange();
}
protected async Task initIdent()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler effettuare inizializzazione/migrazione servizi Identity?"))
return;
reportProcess();
await MagMan.Data.Admin.DbAdmin.MigrateDbIdentity();
await ReloadData();
reportChange();
}
protected bool DbUserOk { get; set; } = false;
protected bool DbIdentity { get; set; } = false;
protected bool DbAllOk { get; set; } = false;
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
protected async Task ReloadData()
{
var resultIden = await Health.Checks.DbIdentity(MagMan.Data.Admin.DbConfig.DATABASE_NAME);
DbIdentity = (resultIden.Status == Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus.Healthy);
DbAllOk = (DbIdentity);
}
private void reportChange()
{
evRefresh.InvokeAsync(1);
}
private void reportProcess()
{
evProcessing.InvokeAsync(1);
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.2402.0209</Version>
<Version>1.0.2402.0211</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
+2 -1
View File
@@ -37,8 +37,9 @@ namespace MagMan.UI.Pages
protected override void OnInitialized()
{
AppMService.ShowSearch = false;
AppMService.ShowCustomers = false;
AppMService.PageName = "Admin Area";
AppMService.PageIcon = "fa-solid fa-house pr-2";
AppMService.PageIcon = "fa-solid fa-building pr-2";
AppMService.EA_CustomerSel += AppMService_EA_CustomerSel;
CustomerID = AppMService.CustomerID;
}
+14 -1
View File
@@ -5,10 +5,23 @@ namespace MagMan.UI.Pages
{
public partial class Index
{
#region Protected Properties
[Inject]
protected MessageService AppMService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override void OnInitialized()
{
AppMService.ShowSearch = false;
AppMService.ShowCustomers = false;
AppMService.PageName = "Home";
AppMService.PageIcon = "fa-solid fa-home pr-2";
}
#endregion Protected Methods
}
}
+1
View File
@@ -33,6 +33,7 @@ namespace MagMan.UI.Pages
protected override async Task OnInitializedAsync()
{
AppMService.ShowSearch = true;
AppMService.ShowCustomers = true;
AppMService.PageName = "Progetti";
AppMService.PageIcon = "fa-solid fa-chart-gantt pr-2";
AppMService.EA_CustomerSel += AppMService_EA_CustomerSel;
+16 -3
View File
@@ -16,6 +16,7 @@ namespace MagMan.UI.Pages
public void Dispose()
{
AppMService.EA_CustomerSel -= AppMService_EA_CustomerSel;
AppMService.EA_KeySel -= AppMService_EA_KeySel;
}
#endregion Public Methods
@@ -46,10 +47,13 @@ namespace MagMan.UI.Pages
protected override async Task OnInitializedAsync()
{
AppMService.ShowSearch = true;
AppMService.ShowCustomers = true;
AppMService.PageName = "Magazzino";
AppMService.PageIcon = "fa-solid fa-warehouse pr-2";
AppMService.EA_CustomerSel += AppMService_EA_CustomerSel;
AppMService.EA_KeySel += AppMService_EA_KeySel;
CustomerID = AppMService.CustomerID;
nKey = AppMService.KeyNum;
// rileggo dati
await ReloadData();
}
@@ -69,7 +73,9 @@ namespace MagMan.UI.Pages
#region Private Fields
private int KeyNum = 0;
private MaterialModel? MaterialSel = null;
private RawItemModel? RawItemSel = null;
#endregion Private Fields
@@ -77,6 +83,7 @@ namespace MagMan.UI.Pages
#region Private Properties
private int CustomerID { get; set; } = 0;
private bool isLoading { get; set; } = false;
#endregion Private Properties
@@ -86,15 +93,21 @@ namespace MagMan.UI.Pages
private async void AppMService_EA_CustomerSel()
{
CustomerID = AppMService.CustomerID;
await Task.Delay(10);
await ReloadData();
//await Task.Delay(1);
await InvokeAsync(StateHasChanged);
}
private async void AppMService_EA_KeySel()
{
nKey = AppMService.KeyNum;
//await Task.Delay(1);
await InvokeAsync(StateHasChanged);
}
private async Task ReloadData()
{
isLoading = true;
nKey = await MTService.MainKeyByCustomer(CustomerID);
await Task.Delay(50);
isLoading = false;
}
+2
View File
@@ -9,9 +9,11 @@
<div class="main mr-1 w-100">
<CascadingValue Name="ShowSearch" Value=@ShowSearch>
<CascadingValue Name="ShowCustomers" Value=@ShowCustomers>
<div class="top-row">
<CmpTop></CmpTop>
</div>
</CascadingValue>
</CascadingValue>
@* <article class="content px-4"> *@
<article class="content pt-1 pt-lg-2 mb-5 px-0 px-lg-1">
+13 -5
View File
@@ -9,8 +9,8 @@ namespace MagMan.UI.Shared
public void Dispose()
{
MessageService.EA_ShowSearch -= OnShowSearch;
MessageService.EA_ShowSearch -= OnHideSearch;
AppMService.EA_ShowSearch -= OnShowSearch;
AppMService.EA_ShowSearch -= OnHideSearch;
}
public void OnHideSearch()
@@ -36,7 +36,7 @@ namespace MagMan.UI.Shared
#region Protected Properties
[Inject]
protected MessageService MessageService { get; set; } = null!;
protected MessageService AppMService { get; set; } = null!;
protected bool navLarge { get; set; } = true;
protected string sideClass { get; set; } = "sidebar";
@@ -47,8 +47,14 @@ namespace MagMan.UI.Shared
protected override void OnInitialized()
{
MessageService.EA_ShowSearch += OnShowSearch;
MessageService.EA_HideSearch += OnHideSearch;
AppMService.EA_ShowSearch += OnShowSearch;
AppMService.EA_HideSearch += OnHideSearch;
AppMService.EA_ShowCustomers += AppMService_EA_ShowCustomers;
}
private void AppMService_EA_ShowCustomers(bool obj)
{
ShowCustomers = obj;
}
protected void UpdateNavDisplay()
@@ -63,6 +69,8 @@ namespace MagMan.UI.Shared
private bool ShowSearch { get; set; } = false;
private bool ShowCustomers { get; set; } = false;
#endregion Private Properties
}
}
+1 -1
View File
@@ -7,7 +7,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Redis": "localhost:6379",
"Redis": "localhost:6379,DefaultDatabase=14,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false",
"UserIdentityDbContextConnection": "Server=localhost;port=3306;database=MagMan_Dev;user=MagMan;pwd=MagMan_secret_pwd;sslmode=None;",
"AuthConnection": "Server=localhost;port=3306;database=MagMan_Dev;user=MagMan;pwd=MagMan_secret_pwd;sslmode=None;",
"DefaultConnection": "Server=localhost;port=3306;database=MagMan_Dev;user=MagMan;pwd=MagMan_secret_pwd;sslmode=None;",
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>MagMan - Wood Warehouse Management System</i>
<h4>Versione: 1.0.2402.0209</h4>
<h4>Versione: 1.0.2402.0211</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.0.2402.0209
1.0.2402.0211
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.0.2402.0209</version>
<version>1.0.2402.0211</version>
<url>http://nexus.steamware.net/repository/SWS/MagMan/stable/0/MagMan.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/MagMan/stable/0/ChangeLog.html</changelog>
<mandatory>false</mandatory>