This commit is contained in:
zaccaria.majid
2023-06-01 12:22:23 +02:00
9 changed files with 578 additions and 345 deletions
+5
View File
@@ -57,5 +57,10 @@ namespace WebDoorCreator.Core
public const string rKeyVocLemma = $"{redisBaseAddr}:Cache:VocLemma";
public const string rKeyVocLemmaTEMP = $"{redisBaseAddr}:Cache:VocLemmaTEMP";
public const string rKeyLanguage = $"{redisBaseAddr}:Cache:Languages";
/// <summary>
/// variabili accessorie ulteriori
/// </summary>
public const int StatusIdTemplate = 10000;
}
}
@@ -195,6 +195,36 @@ namespace WebDoorCreator.Data.Controllers
return fatto;
}
/// <summary>
/// Getting door data by key
/// </summary>
/// <returns></returns>
public DoorModel? DoorGetByKey(int doorId)
{
DoorModel? dbResult = new DoorModel();
// retrieving data from db
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
{
try
{
// extracting entire set
dbResult = localDbCtx
.DbSetDoor
.Where(x => x.DoorId == doorId)
.Include(o => o.OrderNav)
.Include(t => t.TypeNav)
.OrderBy(x => x.DoorId)
.AsNoTracking()
.FirstOrDefault();
}
catch (Exception exc)
{
Log.Error($"Error in DoorGetByKey:{Environment.NewLine}{exc}");
}
}
return dbResult;
}
/// <summary>
/// Adding a new door
/// </summary>
@@ -823,6 +853,31 @@ namespace WebDoorCreator.Data.Controllers
return fatto;
}
public List<OrderModel> OrderGetByCompStatus(int CompanyId, int StatusId)
{
List<OrderModel> dbResult = new List<OrderModel>();
using (var dbCtx = new WDCDataContext(_configuration))
{
try
{
var rawData = dbCtx
.DbSetOrders
.Where(x => x.CompanyId == CompanyId && x.Status == StatusId)
.AsNoTracking()
.ToList();
if (rawData != null)
{
dbResult = rawData;
}
}
catch (Exception exc)
{
Log.Error($"Error in OrderGetByCompStatus:{Environment.NewLine}{exc}");
}
}
return dbResult;
}
public OrderModel OrderGetByKey(int orderId)
{
OrderModel dbResult = new OrderModel();
@@ -848,31 +903,6 @@ namespace WebDoorCreator.Data.Controllers
return dbResult;
}
public List<OrderModel> OrderGetByCompStatus(int CompanyId, int StatusId)
{
List<OrderModel> dbResult = new List<OrderModel>();
using (var dbCtx = new WDCDataContext(_configuration))
{
try
{
var rawData = dbCtx
.DbSetOrders
.Where(x => x.CompanyId == CompanyId && x.Status==StatusId)
.AsNoTracking()
.ToList();
if (rawData != null)
{
dbResult = rawData;
}
}
catch (Exception exc)
{
Log.Error($"Error in OrderGetByCompStatus:{Environment.NewLine}{exc}");
}
}
return dbResult;
}
/// <summary>
/// Remove order
/// </summary>
+7 -6
View File
@@ -156,9 +156,10 @@ namespace WebDoorCreator.Data.DbModels
/// <summary>
/// Clone oggetto
/// </summary>
/// <param name="userId"></param>
/// <param name="userName"></param>
/// <param name="doorId"></param>
/// <returns></returns>
public DoorOpModel ObjClone(string userId, int doorId)
public DoorOpModel ObjClone(string userName, int doorId)
{
DoorOpModel answ = new DoorOpModel();
DateTime adesso = DateTime.Now;
@@ -168,8 +169,8 @@ namespace WebDoorCreator.Data.DbModels
{
DateIns = adesso,
DateMod = adesso,
UserIdIns = userId,
UserIdMod = userId,
UserIdIns = userName,
UserIdMod = userName,
ObjectId = ObjectId,
DoorId = DoorId,
JsoncConfigVal = JsoncConfigVal,
@@ -184,8 +185,8 @@ namespace WebDoorCreator.Data.DbModels
{
DateIns = adesso,
DateMod = adesso,
UserIdIns = userId,
UserIdMod = userId,
UserIdIns = userName,
UserIdMod = userName,
ObjectId = ObjectId,
DoorId = doorId,
JsoncConfigVal = JsoncConfigVal,
@@ -963,6 +963,54 @@ namespace WebDoorCreator.Data.Services
return SteamCrypto.DecryptString(encData, Constants.passPhrase);
}
/// <summary>
/// Clone a copy of the door in the specified order
/// </summary>
/// <param name="doorId">Record id to edit or add</param>
/// <param name="orderId">Destination order where door must be placed</param>
/// <param name="userName">userName for cloning</param>
/// <returns></returns>
public async Task<bool> DoorCloneToOrder(int doorId, int orderId, string userName)
{
var dbResult = false;
int newDoorId = 0;
var doorOps2Add = new List<DoorOpModel>();
var CurrDoor = await DoorGetByKey(doorId);
var DoorOpsList = await DoorOpGetByDoorId(doorId);
if (DoorOpsList != null)
{
var doorOps2Clone = DoorOpsList?.Where(x => x.DoorId == doorId).ToList();
var door2Clone = CurrDoor;
if (door2Clone != null)
{
var doorToAdd = door2Clone.ObjClone(userName);
// imposto ordine per la porta...
doorToAdd.OrderId = orderId;
// salvo!
newDoorId = await DoorInsert(doorToAdd);
if (newDoorId != 0 && doorOps2Clone != null)
{
foreach (var item in doorOps2Clone)
{
var doorOp2Add = item.ObjClone(userName, newDoorId);
doorOps2Add.Add(doorOp2Add);
}
// salvo!
dbResult = await DoorOpInsert(newDoorId, doorOps2Add);
}
}
}
// await dbController.DoorModQty(NewQty, doorId, isAdd); svuoto cache
await DoorFlushCache(doorId);
await DoorOpFlushCache(doorId);
await OrderDetailFlushCache(orderId);
await OrdersFlushCache();
return dbResult;
}
/// <summary>
/// CElimina record posta
/// </summary>
@@ -998,6 +1046,47 @@ namespace WebDoorCreator.Data.Services
return answ;
}
/// <summary>
/// Doors key (DoorId)
/// </summary>
public async Task<DoorModel?> DoorGetByKey(int doorId)
{
string source = "DB";
DoorModel? dbResult = new DoorModel();
// cerco da cache
string currKey = $"{Constants.rKeyDoor}:Single:{doorId}";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<DoorModel>(rawData);
if (tempResult == null)
{
dbResult = new DoorModel();
}
else
{
dbResult = tempResult;
}
}
else
{
dbResult = dbController.DoorGetByKey(doorId);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (dbResult == null)
{
dbResult = new DoorModel();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"DoorGetByKey | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
/// <summary>
/// Doors list by numRec
/// </summary>
@@ -1094,24 +1183,6 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
/// <summary>
/// Clone a copy of the door in the specified order
/// </summary>
/// <param name="DoorId">Record id to edit or add</param>
/// <param name="OrderId">Destination order where door must be placed</param>
/// <returns></returns>
public async Task<bool> DoorCloneToOrder(int DoorId, int OrderId)
{
var dbResult = false;// await dbController.DoorModQty(NewQty, DoorId, isAdd);
// svuoto cache
await DoorFlushCache(DoorId);
await DoorOpFlushCache(DoorId);
await OrderDetailFlushCache(OrderId);
await OrdersFlushCache();
return dbResult;
}
/// <summary>
/// Adding or removing a single door
/// </summary>
@@ -1243,7 +1314,7 @@ namespace WebDoorCreator.Data.Services
}
/// <summary>
/// Create DDF from DoorId
/// Create DDF from doorId
/// </summary>
public async Task<string> DoorOpGetDDF(int DoorId)
{
@@ -1804,6 +1875,22 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
/// <summary>
/// Clean REDIS order detail data in cache
/// </summary>
/// <param name="OrderId">0 = all</param>
/// <returns></returns>
public async Task<bool> OrderDetailFlushCache(int OrderId)
{
RedisValue pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:*");
if (OrderId > 0)
{
pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:{OrderId}");
}
bool answ = await ExecFlushRedisPattern(pattern);
return answ;
}
/// <summary>
/// Order (content) cloning
/// </summary>
@@ -1820,20 +1907,43 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
/// <summary>
/// Clean REDIS order detail data in cache
/// </summary>
/// <param name="OrderId">0 = all</param>
/// <returns></returns>
public async Task<bool> OrderDetailFlushCache(int OrderId)
public async Task<List<OrderModel>?> OrderGetByCompStatus(int CompanyId, int StatusId)
{
RedisValue pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:*");
if (OrderId > 0)
string source = "DB";
List<OrderModel>? dbResult = new List<OrderModel>();
// cerco da cache
string currKey = $"{Constants.rKeyOrderByComp}:{CompanyId}:{StatusId}"; ;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:{OrderId}");
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<OrderModel>>(rawData);
if (tempResult == null)
{
dbResult = new List<OrderModel>();
}
else
{
dbResult = tempResult;
}
}
bool answ = await ExecFlushRedisPattern(pattern);
return answ;
else
{
dbResult = dbController.OrderGetByCompStatus(CompanyId, StatusId);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (dbResult == null)
{
dbResult = new List<OrderModel>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"OrderGetByCompStatus | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task<OrderModel?> OrderGetByKey(int orderId)
@@ -1875,46 +1985,6 @@ namespace WebDoorCreator.Data.Services
return dbResult;
}
public async Task<List<OrderModel>?> OrderGetByCompStatus(int CompanyId, int StatusId)
{
string source = "DB";
List<OrderModel>? dbResult = new List<OrderModel>();
// cerco da cache
string currKey = $"{Constants.rKeyOrderByComp}:{CompanyId}:{StatusId}"; ;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<OrderModel>>(rawData);
if (tempResult == null)
{
dbResult = new List<OrderModel>();
}
else
{
dbResult = tempResult;
}
}
else
{
dbResult = dbController.OrderGetByCompStatus(CompanyId, StatusId);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
}
if (dbResult == null)
{
dbResult = new List<OrderModel>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"OrderGetByCompStatus | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
/// <summary>
/// Remove order
/// </summary>
@@ -1994,7 +2064,7 @@ namespace WebDoorCreator.Data.Services
{
var dbResult = await dbController.OrderUpdate(orderId, newStatus);
// elimino cache redis...
//bool answ = await DoorFlushCache(currRec.DoorId);
//bool answ = await DoorFlushCache(currRec.doorId);
// elimino cache redis dati ordine...
bool answ = await FlushRedisCache();
return dbResult;
@@ -2307,18 +2377,20 @@ namespace WebDoorCreator.Data.Services
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task<Dictionary<string, Dictionary<string, string>>?> VocLemmaTEMPGetAll()
public async Task<bool> VocLemmaInsert()
{
string source = "DB";
Dictionary<string, Dictionary<string, string>>? dbResult = new Dictionary<string, Dictionary<string, string>>();
// cerco da cache
bool fatto = false;
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = dbController.VocLemmaTEMPGetAll();
fatto = await dbController.VocLemmaInsert();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
return fatto;
}
public async Task<List<VocabularyTempModel>> VocLemmaInsertPrepare(string rootPath)
@@ -2367,21 +2439,18 @@ namespace WebDoorCreator.Data.Services
return VocLemmas;
}
public async Task<bool> VocLemmaInsert()
public async Task<Dictionary<string, Dictionary<string, string>>?> VocLemmaTEMPGetAll()
{
bool fatto = false;
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
string source = "DB";
Dictionary<string, Dictionary<string, string>>? dbResult = new Dictionary<string, Dictionary<string, string>>();
// cerco da cache
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
fatto = await dbController.VocLemmaInsert();
dbResult = dbController.VocLemmaTEMPGetAll();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
return fatto;
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
#endregion Public Methods
@@ -39,6 +39,21 @@
<button class="btn btn-danger w-100" type="button" @onclick="()=>deleteRecord()">Delete door</button>
</div>
</div>
@if (SaveOnTemplate)
{
<div class="pt-5 pb-1">
<div class="input-group mb-3">
<button class="btn btn-success w-100" type="button" @onclick="()=>doSaveTemplate()">Save as Template</button>
</div>
</div>
<select @bind="OrderIdTplSel" class="form-select form-select-sm">
@foreach (var item in OrdersCompList)
{
<option value="@item.OrderId">@item.OrderDescript (@item.OrderExtCode)</option>
}
</select>
}
}
</div>
@@ -3,15 +3,15 @@ using Microsoft.JSInterop;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.Data.DTO;
using WebDoorCreator.Data.Services;
using WebDoorCreator.UI.Data;
namespace WebDoorCreator.UI.Components.DoorMan
{
public partial class DoorModal
{
protected List<DoorOpModel> doorOps2Add = new List<DoorOpModel>();
#region Public Properties
public DoorModel CurrDoor { get; set; } = new DoorModel();
public DoorModel CurrDoorClone { get; set; } = new DoorModel();
[Parameter]
@@ -28,8 +28,22 @@ namespace WebDoorCreator.UI.Components.DoorMan
[Parameter]
public int OrderId { get; set; } = 0;
public List<OrderModel> OrdersCompList { get; set; } = new List<OrderModel>();
[Parameter]
public string userId { get; set; } = "";
public string UserName { get; set; } = "";
#endregion Public Properties
#region Protected Fields
protected List<DoorOpModel> doorOps2Add = new List<DoorOpModel>();
protected bool SaveOnTemplate = false;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected IConfiguration config { get; set; } = null!;
@@ -52,13 +66,32 @@ namespace WebDoorCreator.UI.Components.DoorMan
protected int newDoorId { get; set; } = 0;
protected int OrderIdTplSel { get; set; } = 0;
protected List<string> ordListVal { get; set; } = new List<string>();
[Inject]
protected QueueDataService QDataServ { get; set; } = null!;
protected int userCurrCompany
{
get => WDCUService.userCurrComp;
}
protected string userRole
{
get => WDCUService.userRole;
}
[Inject]
protected WDCUserService WDCUService { get; set; } = null!;
[Inject]
protected WebDoorCreatorService WDService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected async Task addOrRemoveOneDoorNumber(bool isAdd)
{
//var door = new DoorModel();
@@ -112,6 +145,14 @@ namespace WebDoorCreator.UI.Components.DoorMan
/// <returns></returns>
protected async Task doClone()
{
var cloned = await WDService.DoorCloneToOrder(CurrDoor.DoorId, CurrDoor.OrderId, UserName);
if (cloned)
{
await doSave();
await closeModal();
}
#if false
var DoorOpsList = await WDService.DoorOpGetByDoorId(CurrDoorId);
if (DoorOpsList != null)
{
@@ -142,6 +183,7 @@ namespace WebDoorCreator.UI.Components.DoorMan
}
}
}
#endif
}
/// <summary>
@@ -170,8 +212,8 @@ namespace WebDoorCreator.UI.Components.DoorMan
listOp = listOp.OrderBy(d => ordListVal.IndexOf(d.ObjectId)).ToList();
string currDdf = currDdfConv.GetSerialized(listOp);
// FIXME TODO: si potrebbe eliminare in futuro che va su REDIS
// versione corrente del DDF generato
// FIXME TODO: si potrebbe eliminare in futuro che va su REDIS versione corrente
// del DDF generato
int currVers = await QDataServ.SendCalcReq(newDoorId, currDdf);
if (currVers > 0)
@@ -182,6 +224,24 @@ namespace WebDoorCreator.UI.Components.DoorMan
}
}
/// <summary>
/// Clona la porta selezionata con annesse door operations nel template selezionato...
/// </summary>
/// <returns></returns>
protected async Task doSaveTemplate()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Are you sure? this operation will copy current door to selected template order?"))
return;
// prendo ord templ dest...
var cloned = await WDService.DoorCloneToOrder(CurrDoor.DoorId, OrderIdTplSel, UserName);
if (cloned)
{
await doSave();
await closeModal();
}
}
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
@@ -191,6 +251,7 @@ namespace WebDoorCreator.UI.Components.DoorMan
var footRows = config.GetSection("ConfDDF:Footer").Get<List<string>>();
currDdfConv = new WebDoorCreator.Data.DDF.Converter(vers, remDoorOp, headRows, footRows);
}
protected override async Task OnParametersSetAsync()
{
await Task.Delay(1);
@@ -199,6 +260,7 @@ namespace WebDoorCreator.UI.Components.DoorMan
protected async Task ReloadData()
{
SaveOnTemplate = false;
var SearchRecords = await WDService.DoorGetByOrderId(OrderId);
if (SearchRecords != null)
{
@@ -214,6 +276,40 @@ namespace WebDoorCreator.UI.Components.DoorMan
}
}
CurrDoorClone = CurrDoor.ObjClone("");
OrdersCompList = new List<OrderModel>();
// carico template ordini DCA (CompId=1)
var genTplOrders = await WDService.OrderGetByCompStatus(1, Core.Constants.StatusIdTemplate);
if (genTplOrders != null)
{
OrdersCompList.AddRange(genTplOrders);
}
// calcolo (se possibile) elenco template della company specifica
if (CurrDoor != null)
{
if (CurrDoor.OrderNav != null)
{
// verifico la company dall'ordine
int compId = CurrDoor.OrderNav.CompanyId;
// se ho template permetto SaveOnTemplate...
var compTplOrders = await WDService.OrderGetByCompStatus(compId, Core.Constants.StatusIdTemplate);
if (compTplOrders != null)
{
OrdersCompList.AddRange(compTplOrders);
}
}
}
// verifica funzionalità SaveOnTemplate... in primis da ruolo
if (userRole.Contains("Admin"))
{
SaveOnTemplate = true;
}
// se non ha ruolo proseguo...
else
{
SaveOnTemplate = OrdersCompList.Count > 0;
}
}
#endregion Protected Methods
}
}
@@ -2,9 +2,7 @@ using Blazored.LocalStorage;
using EgwCoreLib.Razor;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.JSInterop;
using System.Security.Policy;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.Data.Services;
using WebDoorCreator.UI.Data;
@@ -14,6 +12,11 @@ namespace WebDoorCreator.UI.Components.Order
{
public partial class OrderList
{
#region Public Properties
[Parameter]
public OrderSelectFilter actFilter { get; set; } = new OrderSelectFilter();
[Parameter]
public bool B_doorChaged { get; set; }
@@ -23,35 +26,240 @@ namespace WebDoorCreator.UI.Components.Order
[Parameter]
public EventCallback<int> E_OrdReqClone { get; set; }
public int Height { get; set; }
[Parameter]
public int UserCurrCompany { get; set; }
#region Protected Properties
private bool sortAsc = true;
private string sortField = "";
[Parameter]
public OrderSelectFilter actFilter { get; set; } = new OrderSelectFilter();
[Parameter]
public EventCallback<OrderStatusViewModel> E_SetOrd2Show { get; set; }
public int Height { get; set; }
public OrderStatusViewModel? Ord2Show { get; set; }
[Parameter]
public EventCallback<int> updateRecordCount { get; set; }
[Parameter]
public int UserCurrCompany { get; set; }
public int Width { get; set; }
#endregion Public Properties
#region Public Classes
public class WindowDimension
{
#region Public Properties
public int Height { get; set; }
public int Width { get; set; }
#endregion Public Properties
}
#endregion Public Classes
#region Protected Fields
protected Core.Enum.orderTypeEnum orderType = Core.Enum.orderTypeEnum.none;
#endregion Protected Fields
#region Protected Properties
protected OrderStatusViewModel? currOrder { get; set; } = null;
protected string currUser { get; set; } = "";
protected bool isModRole { get; set; } = false;
[Inject]
protected IJSRuntime JsRuntime { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
protected bool ordByCode { get; set; } = false;
protected bool ordByDate { get; set; } = false;
protected int screenX { get; set; } = 0;
protected int screenY { get; set; } = 0;
protected List<string>? userClaims
{
get => WDCUService.userClaims;
}
protected int userCurrCompany
{
get => WDCUService.userCurrComp;
}
protected string userRole
{
get => WDCUService.userRole;
}
[Inject]
protected WDCUserService WDCUService { get; set; } = null!;
[Inject]
protected WebDoorCreatorService WDService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Richiesta duplicazione ordine
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
protected async Task cloneAndShow(int orderId)
{
await Task.Delay(1);
await E_OrdReqClone.InvokeAsync(orderId);
}
protected async Task deleteRecord(OrderStatusViewModel currRec)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Order Deletion requested: are you sure to remove {currRec.OrderExtCode}?"))
return;
await Task.Delay(1);
var done = await WDService.OrderRem(currRec.OrderId);
await WDService.OrdersFlushCache();
await ReloadData();
}
protected string getOrderStatusLabel(int orderStat)
{
string answ = "";
if (ListValuesAll != null)
{
var currOrdStat = ListValuesAll.Where(x => int.Parse(x.Value) == orderStat).FirstOrDefault();
if (currOrdStat != null)
{
answ = currOrdStat.Label;
}
}
return answ;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var localOrdId = await localStorage.GetItemAsync<int>("OrderId");
if (localOrdId != 0)
{
await setOrd2Show(localOrdId);
}
}
}
protected override async Task OnParametersSetAsync()
{
await ReloadData();
}
protected async Task orderByCode()
{
ordByCode = !ordByCode;
if (ordByDate)
{
orderType = orderTypeEnum.CodeAscending;
}
else
{
orderType = orderTypeEnum.CodeDescending;
}
await ReloadData();
}
protected async Task orderByDate()
{
ordByDate = !ordByDate;
if (ordByDate)
{
orderType = orderTypeEnum.DateAscending;
}
else
{
orderType = orderTypeEnum.DateDescending;
}
await ReloadData();
}
protected string reportUrl(int orderId)
{
return $"api/Report/GetOrderReport?OrderId={orderId}&Format=PDF";
}
protected async Task setOrd2Show(int orderId)
{
await Task.Delay(1);
if (ListOrdersStatus != null)
{
var chosenOrd = ListOrdersStatus.Where(x => x.OrderId == orderId).FirstOrDefault();
if (chosenOrd != null)
{
Ord2Show = chosenOrd;
await localStorage.SetItemAsync("OrderId", orderId);
await E_SetOrd2Show.InvokeAsync(chosenOrd);
}
}
}
protected string setPgColor(int progress)
{
string answ = "";
if (progress == 1)
{
answ = "#D35400";
}
else if (progress == 2)
{
answ = "#F1C40F";
}
else if (progress == 3)
{
answ = "#2980B9";
}
else if (progress == 4)
{
answ = "#8E44AD";
}
else if (progress == 5)
{
answ = "#27AE60";
}
return answ;
}
protected async Task SortRequested(Sorter.SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private List<OrderStatusViewModel>? ListOrdersStatus = null;
private List<ListValuesModel>? ListValuesAll = null;
private bool sortAsc = true;
private string sortField = "";
#endregion Private Fields
#region Private Properties
private int _totalCount { get; set; } = 0;
private int currPage
@@ -72,6 +280,9 @@ namespace WebDoorCreator.UI.Components.Order
set => actFilter.DateTo = value;
}
[Inject]
private ILocalStorageService localStorage { get; set; } = null!;
private int numRecord
{
get => actFilter.NumRec;
@@ -103,127 +314,21 @@ namespace WebDoorCreator.UI.Components.Order
}
}
protected async Task SortRequested(Sorter.SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
await ReloadData();
}
#endregion Protected Properties
#region Protected Methods
protected override async Task OnParametersSetAsync()
{
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private List<OrderStatusViewModel>? ListOrdersStatus = null;
private List<ListValuesModel>? ListValuesAll = null;
#endregion Private Fields
#endregion Private Properties
#region Private Methods
protected Core.Enum.orderTypeEnum orderType = Core.Enum.orderTypeEnum.none;
protected OrderStatusViewModel? currOrder { get; set; } = null;
protected bool isModRole { get; set; } = false;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
protected bool ordByCode { get; set; } = false;
protected bool ordByDate { get; set; } = false;
protected List<string>? userClaims
private async Task getDim()
{
get => WDCUService.userClaims;
var dimension = await JsRuntime.InvokeAsync<WindowDimension>("getWindowDimensions");
Height = dimension.Height;
Width = dimension.Width;
}
protected int userCurrCompany
private void getElementCoords(MouseEventArgs e)
{
get => WDCUService.userCurrComp;
}
protected string userRole
{
get => WDCUService.userRole;
}
[Inject]
protected WDCUserService WDCUService { get; set; } = null!;
protected async Task deleteRecord(OrderStatusViewModel currRec)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Order Deletion requested: are you sure to remove {currRec.OrderExtCode}?"))
return;
await Task.Delay(1);
var done = await WDService.OrderRem(currRec.OrderId);
await WDService.OrdersFlushCache();
await ReloadData();
}
protected async Task orderByCode()
{
ordByCode = !ordByCode;
if (ordByDate)
{
orderType = orderTypeEnum.CodeAscending;
}
else
{
orderType = orderTypeEnum.CodeDescending;
}
await ReloadData();
}
protected async Task orderByDate()
{
ordByDate = !ordByDate;
if (ordByDate)
{
orderType = orderTypeEnum.DateAscending;
}
else
{
orderType = orderTypeEnum.DateDescending;
}
await ReloadData();
}
protected string setPgColor(int progress)
{
string answ = "";
if (progress == 1)
{
answ = "#D35400";
}
else if (progress == 2)
{
answ = "#F1C40F";
}
else if (progress == 3)
{
answ = "#2980B9";
}
else if (progress == 4)
{
answ = "#8E44AD";
}
else if (progress == 5)
{
answ = "#27AE60";
}
return answ;
screenX = (int)(e.ClientX);
screenY = (int)(e.ClientY);
}
private async Task ReloadData()
@@ -287,94 +392,7 @@ namespace WebDoorCreator.UI.Components.Order
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
}
#endregion Private Methods
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var localOrdId = await localStorage.GetItemAsync<int>("OrderId");
if (localOrdId != 0)
{
await setOrd2Show(localOrdId);
}
}
}
public int Width { get; set; }
[Inject]
protected IJSRuntime JsRuntime { get; set; } = null!;
protected int screenX { get; set; } = 0;
protected int screenY { get; set; } = 0;
protected string getOrderStatusLabel(int orderStat)
{
string answ = "";
if (ListValuesAll != null)
{
var currOrdStat = ListValuesAll.Where(x => int.Parse(x.Value) == orderStat).FirstOrDefault();
if (currOrdStat != null)
{
answ = currOrdStat.Label;
}
}
return answ;
}
protected string reportUrl(int orderId)
{
return $"api/Report/GetOrderReport?OrderId={orderId}&Format=PDF";
}
/// <summary>
/// Richiesta duplicazione ordine
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
protected async Task cloneAndShow(int orderId)
{
await Task.Delay(1);
await E_OrdReqClone.InvokeAsync(orderId);
}
protected async Task setOrd2Show(int orderId)
{
await Task.Delay(1);
if (ListOrdersStatus != null)
{
var chosenOrd = ListOrdersStatus.Where(x => x.OrderId == orderId).FirstOrDefault();
if (chosenOrd != null)
{
Ord2Show = chosenOrd;
await localStorage.SetItemAsync("OrderId", orderId);
await E_SetOrd2Show.InvokeAsync(chosenOrd);
}
}
}
[Inject]
private ILocalStorageService localStorage { get; set; } = null!;
private async Task getDim()
{
var dimension = await JsRuntime.InvokeAsync<WindowDimension>("getWindowDimensions");
Height = dimension.Height;
Width = dimension.Width;
}
private void getElementCoords(MouseEventArgs e)
{
screenX = (int)(e.ClientX);
screenY = (int)(e.ClientY);
}
public class WindowDimension
{
public int Height { get; set; }
public int Width { get; set; }
}
}
}
+1 -2
View File
@@ -158,7 +158,7 @@
@if (currDoorModal != null && currDoorModal.DoorId != 0)
{
<DoorModal userId="@userId" E_DoorClose="@SetCurrDoorModal" OrderId="@currDoorModal.OrderId" CurrDoorId="@currDoorModal.DoorId"></DoorModal>
<DoorModal UserName="@userId" E_DoorClose="@SetCurrDoorModal" OrderId="@currDoorModal.OrderId" CurrDoorId="@currDoorModal.DoorId"></DoorModal>
}
@if (newOrdReq)
{
@@ -191,7 +191,6 @@
<button type="button" class="btn btn-secondary" @onclick="() => CloseNewOrd()">Close</button>
@if (orderCodExt != "")
{
@if (@context.User.IsInRole("SuperAdmin") || @context.User.IsInRole("DcaAdmin") || @context.User.IsInRole("CompAdmin"))
{
<button type="button" class="btn btn-primary" @onclick="()=>addNewOrder(context.User.Identity?.Name!, true)">Save as TEMPLATE</button>
+1 -1
View File
@@ -200,7 +200,7 @@ namespace WebDoorCreator.UI.Pages
// var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
// code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
// var callbackUrl = $"/Account/ConfirmEmail?userId{user.Id}&code{code}&returnUrl=~/";
// var callbackUrl = $"/Account/ConfirmEmail?UserName{user.Id}&code{code}&returnUrl=~/";
// await _emailSender.SendEmailAsync(email, "Web Door Creator: Please confirm your email account",
// $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>Click here</a> to confirm the account linked with this email.");