Files
2023-06-06 10:12:27 +02:00

208 lines
7.1 KiB
C#

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<bool> 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<DoorModel>? DoorsList { get; set; } = null;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
protected List<string> ordListVal { get; set; } = new List<string>();
[Inject]
protected QueueDataService QDataServ { get; set; } = null!;
protected List<OrderStatusViewModel>? TemplateListbyComp { get; set; } = null;
protected List<OrderStatusViewModel>? 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);
}
/// <summary>
/// Clona la porta selezionata con annesse door operations
/// </summary>
/// <returns></returns>
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<string>("ConfDDF:VersNumber");
bool remDoorOp = config.GetValue<bool>("ConfDDF:RemoveDoorOps");
var headRows = config.GetSection("ConfDDF:Header").Get<List<string>>();
var footRows = config.GetSection("ConfDDF:Footer").Get<List<string>>();
currDdfConv = new WebDoorCreator.Data.DDF.Converter(vers, remDoorOp, headRows, footRows);
}
/// <summary>
/// Path del servizio di recupero SVG delle porte
/// </summary>
/// <param name="doorId"></param>
/// <returns></returns>
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;
}
}
}
}
}
/// <summary>
/// Effettua salvataggio record e generazione DDF
/// </summary>
/// <returns></returns>
protected async Task RequestRefreshSvg(int newDoorId)
{
List<DoorOpModel>? listOpAll = await WDService.DoorOpGetByDoorId(newDoorId);
if (listOpAll != null)
{
List<DoorOpModel> 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();
}
/// <summary>
/// Prepara il dictionary dei testi da riportare nell'oggetto ordine
/// </summary>
/// <param name="door"></param>
/// <returns></returns>
protected Dictionary<string, string> textDictSetup(DoorModel door)
{
Dictionary<string, string> answ = new Dictionary<string, string>();
answ.Add("Door ID:", $"{door.DoorId}");
answ.Add($"{door.DoorExtCode} {door.DoorDescript}", "");
answ.Add("Unit Price:", $"{door.UnitCost:C2}");
return answ;
}
}
}