diff --git a/WebDoorCreator.Core/Constants.cs b/WebDoorCreator.Core/Constants.cs index 23786fc..5b6f6a8 100644 --- a/WebDoorCreator.Core/Constants.cs +++ b/WebDoorCreator.Core/Constants.cs @@ -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"; + + /// + /// variabili accessorie ulteriori + /// + public const int StatusIdTemplate = 10000; } } diff --git a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs index 8fdd7da..bc41a98 100644 --- a/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs +++ b/WebDoorCreator.Data/Controllers/WebDoorCreatorController.cs @@ -195,6 +195,36 @@ namespace WebDoorCreator.Data.Controllers return fatto; } + /// + /// Getting door data by key + /// + /// + 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; + } + /// /// Adding a new door /// @@ -823,6 +853,31 @@ namespace WebDoorCreator.Data.Controllers return fatto; } + public List OrderGetByCompStatus(int CompanyId, int StatusId) + { + List dbResult = new List(); + 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 OrderGetByCompStatus(int CompanyId, int StatusId) - { - List dbResult = new List(); - 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; - } - /// /// Remove order /// diff --git a/WebDoorCreator.Data/DbModels/DoorOpModel.cs b/WebDoorCreator.Data/DbModels/DoorOpModel.cs index cede43b..271381f 100644 --- a/WebDoorCreator.Data/DbModels/DoorOpModel.cs +++ b/WebDoorCreator.Data/DbModels/DoorOpModel.cs @@ -156,9 +156,10 @@ namespace WebDoorCreator.Data.DbModels /// /// Clone oggetto /// - /// + /// + /// /// - 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, diff --git a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs index f11d5ae..8c3289a 100644 --- a/WebDoorCreator.Data/Services/WebDoorCreatorService.cs +++ b/WebDoorCreator.Data/Services/WebDoorCreatorService.cs @@ -963,6 +963,54 @@ namespace WebDoorCreator.Data.Services return SteamCrypto.DecryptString(encData, Constants.passPhrase); } + /// + /// Clone a copy of the door in the specified order + /// + /// Record id to edit or add + /// Destination order where door must be placed + /// userName for cloning + /// + public async Task DoorCloneToOrder(int doorId, int orderId, string userName) + { + var dbResult = false; + int newDoorId = 0; + var doorOps2Add = new List(); + 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; + } + /// /// CElimina record posta /// @@ -998,6 +1046,47 @@ namespace WebDoorCreator.Data.Services return answ; } + /// + /// Doors key (DoorId) + /// + public async Task 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(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; + } + /// /// Doors list by numRec /// @@ -1094,24 +1183,6 @@ namespace WebDoorCreator.Data.Services return dbResult; } - - /// - /// Clone a copy of the door in the specified order - /// - /// Record id to edit or add - /// Destination order where door must be placed - /// - public async Task 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; - } - /// /// Adding or removing a single door /// @@ -1243,7 +1314,7 @@ namespace WebDoorCreator.Data.Services } /// - /// Create DDF from DoorId + /// Create DDF from doorId /// public async Task DoorOpGetDDF(int DoorId) { @@ -1804,6 +1875,22 @@ namespace WebDoorCreator.Data.Services return dbResult; } + /// + /// Clean REDIS order detail data in cache + /// + /// 0 = all + /// + public async Task 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; + } + /// /// Order (content) cloning /// @@ -1820,20 +1907,43 @@ namespace WebDoorCreator.Data.Services return dbResult; } - /// - /// Clean REDIS order detail data in cache - /// - /// 0 = all - /// - public async Task OrderDetailFlushCache(int OrderId) + public async Task?> OrderGetByCompStatus(int CompanyId, int StatusId) { - RedisValue pattern = new RedisValue($"{Constants.rKeyDoorsByOrder}:*"); - if (OrderId > 0) + string source = "DB"; + + List? dbResult = new List(); + // 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>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + 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(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"OrderGetByCompStatus | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; } public async Task OrderGetByKey(int orderId) @@ -1875,46 +1985,6 @@ namespace WebDoorCreator.Data.Services return dbResult; } - - public async Task?> OrderGetByCompStatus(int CompanyId, int StatusId) - { - string source = "DB"; - - List? dbResult = new List(); - // 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>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - 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(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"OrderGetByCompStatus | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - /// /// Remove order /// @@ -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>?> VocLemmaTEMPGetAll() + + public async Task VocLemmaInsert() { - string source = "DB"; - Dictionary>? dbResult = new Dictionary>(); - // cerco da cache + bool fatto = false; + + List VocLemmas = new List(); + 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> VocLemmaInsertPrepare(string rootPath) @@ -2367,21 +2439,18 @@ namespace WebDoorCreator.Data.Services return VocLemmas; } - - - public async Task VocLemmaInsert() + public async Task>?> VocLemmaTEMPGetAll() { - bool fatto = false; - - List VocLemmas = new List(); - + string source = "DB"; + Dictionary>? dbResult = new Dictionary>(); + // 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 diff --git a/WebDoorCreator.UI/Components/DoorMan/DoorModal.razor b/WebDoorCreator.UI/Components/DoorMan/DoorModal.razor index 1de6e4f..a867088 100644 --- a/WebDoorCreator.UI/Components/DoorMan/DoorModal.razor +++ b/WebDoorCreator.UI/Components/DoorMan/DoorModal.razor @@ -39,6 +39,21 @@ deleteRecord()">Delete door + + @if (SaveOnTemplate) + { + + + doSaveTemplate()">Save as Template + + + + @foreach (var item in OrdersCompList) + { + @item.OrderDescript (@item.OrderExtCode) + } + + } } diff --git a/WebDoorCreator.UI/Components/DoorMan/DoorModal.razor.cs b/WebDoorCreator.UI/Components/DoorMan/DoorModal.razor.cs index bdbff81..06e9a92 100644 --- a/WebDoorCreator.UI/Components/DoorMan/DoorModal.razor.cs +++ b/WebDoorCreator.UI/Components/DoorMan/DoorModal.razor.cs @@ -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 doorOps2Add = new List(); + #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 OrdersCompList { get; set; } = new List(); + [Parameter] - public string userId { get; set; } = ""; + public string UserName { get; set; } = ""; + + #endregion Public Properties + + #region Protected Fields + + protected List doorOps2Add = new List(); + 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 ordListVal { get; set; } = new List(); [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 /// 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 } /// @@ -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 } } + /// + /// Clona la porta selezionata con annesse door operations nel template selezionato... + /// + /// + protected async Task doSaveTemplate() + { + if (!await JSRuntime.InvokeAsync("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>(); 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(); + // 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 } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Components/Order/OrderList.razor.cs b/WebDoorCreator.UI/Components/Order/OrderList.razor.cs index 649d174..2821d5e 100644 --- a/WebDoorCreator.UI/Components/Order/OrderList.razor.cs +++ b/WebDoorCreator.UI/Components/Order/OrderList.razor.cs @@ -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 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 E_SetOrd2Show { get; set; } + public int Height { get; set; } + public OrderStatusViewModel? Ord2Show { get; set; } [Parameter] public EventCallback 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? 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 + + /// + /// Richiesta duplicazione ordine + /// + /// + /// + 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("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("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? ListOrdersStatus = null; + private List? 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? ListOrdersStatus = null; - private List? 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? userClaims + private async Task getDim() { - get => WDCUService.userClaims; + var dimension = await JsRuntime.InvokeAsync("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("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("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"; - } - - /// - /// Richiesta duplicazione ordine - /// - /// - /// - 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("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; } - } } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Pages/OrdersHomePage.razor b/WebDoorCreator.UI/Pages/OrdersHomePage.razor index b46817c..60892cb 100644 --- a/WebDoorCreator.UI/Pages/OrdersHomePage.razor +++ b/WebDoorCreator.UI/Pages/OrdersHomePage.razor @@ -158,7 +158,7 @@ @if (currDoorModal != null && currDoorModal.DoorId != 0) { - + } @if (newOrdReq) { @@ -191,7 +191,6 @@ CloseNewOrd()">Close @if (orderCodExt != "") { - @if (@context.User.IsInRole("SuperAdmin") || @context.User.IsInRole("DcaAdmin") || @context.User.IsInRole("CompAdmin")) { addNewOrder(context.User.Identity?.Name!, true)">Save as TEMPLATE diff --git a/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs b/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs index e4d2e1a..f05db12 100644 --- a/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs +++ b/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs @@ -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", // $"Click here to confirm the account linked with this email.");