using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using WebDoorCreator.Data.DbModels; using WebDoorCreator.Data.Services; using WebDoorCreator.UI.Data; namespace WebDoorCreator.UI.Components.TemplateMan { public partial class TemplModal { public int currOrderId { get; set; } = 56; [Parameter] public EventCallback E_DoorClose { get; set; } [Parameter] public int OrderId { get; set; } = 0; [Parameter] public string userId { get; set; } = ""; [Inject] protected IConfiguration config { get; set; } = null!; protected WebDoorCreator.Data.DDF.Converter currDdfConv { get; set; } = null!; protected int currUserComp { get => WDUService.userCurrComp; } protected string currUserRole { get => WDUService.userRole; } protected List? DoorsList { get; set; } = null; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; protected List ordListVal { get; set; } = new List(); [Inject] protected QueueDataService QDataServ { get; set; } = null!; protected List? TemplateListbyComp { get; set; } = null; protected List? TemplateListGen { get; set; } = null; protected string UserName { get => WDUService.userId; } [Inject] protected WebDoorCreatorService WDService { get; set; } = null!; [Inject] protected WDCUserService WDUService { get; set; } = null!; protected string activeTemplCss(int OrdId) { string answ = ""; if (OrdId == currOrderId) { answ = "color: #2980B9; background-color: rgba(41, 128, 185, 0.2)"; } else { answ = "color: #000; background-color: transparent"; } return answ; } protected async Task closeModal() { await Task.Delay(1); await E_DoorClose.InvokeAsync(false); } /// /// Clona la porta selezionata con annesse door operations /// /// protected async Task doClone(DoorModel CurrDoor) { var newDoorId = await WDService.DoorCloneToOrder(CurrDoor.DoorId, CurrDoor.DoorExtCode, CurrDoor.DoorDescript, OrderId, UserName, true); if (newDoorId > 0) { await RequestRefreshSvg(newDoorId); await closeModal(); } } protected override async Task OnInitializedAsync() { await Task.Delay(1); string vers = config.GetValue("ConfDDF:VersNumber"); bool remDoorOp = config.GetValue("ConfDDF:RemoveDoorOps"); var headRows = config.GetSection("ConfDDF:Header").Get>(); var footRows = config.GetSection("ConfDDF:Footer").Get>(); currDdfConv = new WebDoorCreator.Data.DDF.Converter(vers, remDoorOp, headRows, footRows); } /// /// Path del servizio di recupero SVG delle porte /// /// /// protected string DoorSvgUrl(int doorId) { return $"api/DoorImage/GetImage.svg?DoorId={doorId}"; } protected override async Task OnParametersSetAsync() { await Task.Delay(1); await ReloadData(); } protected async Task ReloadData() { if (currOrderId != -1) { var SearchRecords = await WDService.DoorGetByOrderId(currOrderId); if (currUserRole == "SuperAdmin") { TemplateListGen = await WDService.OrderStatusGetFilt(0, Core.Constants.StatusIdTemplate, DateTime.Today.AddYears(-100), DateTime.Today.AddYears(100)); } else { TemplateListGen = await WDService.OrderStatusGetFilt(1, Core.Constants.StatusIdTemplate, DateTime.Today.AddYears(-100), DateTime.Today.AddYears(100)); } if (currUserComp > 0) { TemplateListbyComp = await WDService.OrderStatusGetFilt(currUserComp, Core.Constants.StatusIdTemplate, DateTime.Today.AddYears(-100), DateTime.Today.AddYears(100)); } if (SearchRecords != null) { DoorsList = SearchRecords .ToList(); if (DoorsList != null) { var currOrder = DoorsList.FirstOrDefault(); if (currOrder?.OrderNav != null) { //orderStatus = currOrder.OrderNav.Status; } } } } } /// /// Effettua salvataggio record e generazione DDF /// /// protected async Task RequestRefreshSvg(int newDoorId) { List? listOpAll = await WDService.DoorOpGetByDoorId(newDoorId); if (listOpAll != null) { List listOp = listOpAll.Where(x => x.userConfirm != "" && x.DtConfirm != null).ToList(); if (listOp != null) { // chiamo metodo x avewre DDF serializzato //var list2Ord = ; var CurrentCompoOrder = await WDService.ListValuesGetAll("*", "Hardware"); if (CurrentCompoOrder != null) { foreach (var item in CurrentCompoOrder.OrderBy(x => x.Ordinal).ToList()) { ordListVal.Add(item.TableName); } } 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 int currVers = await QDataServ.SendCalcReq(newDoorId, currDdf); } } } protected async Task setCurrTempl(int OrdId) { currOrderId = OrdId; await ReloadData(); } /// /// Prepara il dictionary dei testi da riportare nell'oggetto ordine /// /// /// protected Dictionary textDictSetup(DoorModel door) { Dictionary answ = new Dictionary(); answ.Add("Door ID:", $"{door.DoorId}"); answ.Add($"{door.DoorExtCode} {door.DoorDescript}", ""); answ.Add("Unit Price:", $"{door.UnitCost:C2}"); return answ; } } }