using Egw.Window.Data;
using Microsoft.AspNetCore.Components;
using WebWindowComplex.Models;
namespace WebWindowComplex.Compo
{
public partial class CardFrame
{
#region Public Properties
///
/// Evento per tornare nella pagine Tree
///
[Parameter]
public EventCallback EC_ReqClose { get; set; }
///
/// Evento per richiedere reset dizionari
///
[Parameter]
public EventCallback EC_ReqResetDict { get; set; }
///
/// Evento per richiedere opzioni hardware
///
[Parameter]
public EventCallback EC_ReqOptionHw { get; set; }
///
/// Evento per richiesta calcolo preview
///
[Parameter]
public EventCallback EC_UpdateFrame { get; set; }
///
/// Evento per richiesta profili degli Element
///
[Parameter]
public EventCallback EC_ReqElement { get; set; }
///
/// Evento per richiesta traduzione
///
[Parameter]
public EventCallback> EC_ReqTraduzione { get; set; }
///
/// Frame corrente
///
[CascadingParameter(Name = "CurrFrameWindow")]
public Frame CurrFrameWindow { get; set; } = null!;
///
/// Lista di sash
///
[CascadingParameter(Name = "SashGroupList")]
public List SashGroupList { get; set; } = null!;
///
/// Lista di split
///
[CascadingParameter(Name = "SplitList")]
public List SplitList { get; set; } = null!;
///
/// Livello di accesso (utente base)
///
[CascadingParameter(Name = "User")]
public bool User { get; set; } = false!;
///
/// Evento per richiesta profili degli Element
///
[Parameter]
public Dictionary Vocabulary { get; set; }
#endregion Public Properties
protected override async Task OnInitializedAsync()
{
if (Vocabulary == null || Vocabulary.Count == 0)
{
List tradList = new List() { "ConfWind_Frame", "ConfWind_Shape", "ConfWind_Dimension", "ConfWind_Threshold", "ConfWind_Tipology", "ConfWind_BottomRail", "ConfWind_Quantity", "ConfWind_Joints", "ConfWind_Element" };
await EC_ReqTraduzione.InvokeAsync(tradList);
}
}
#region Protected Properties
private string GetImageFrameShapePath(string fileName) => $"_content/Egw.Lux.WebWindowComplex/icone/frame/shape/{fileName}.svg";
private string GetImageJointShapePath(string fileName) => $"_content/Egw.Lux.WebWindowComplex/icone/joint/shape/All/{fileName}.svg";
///
/// Metodo per selezionare shape
///
protected int SelShapeIndex
{
get => CurrFrameWindow.SelShapeIndex;
//set
//{
// if (CurrFrameWindow.SelShapeIndex != value)
// {
// CurrFrameWindow.SelShapeIndex = value;
// // richiesta reset dict shape, profili element e hw option
// _ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDictShape });
// _ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
// _ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetHwOpt });
// foreach (var s in SashGroupList)
// {
// s.SelHardwareFromId = "000000";
// }
// var args = new DataUpdateFrame()
// {
// currFrame = CurrFrameWindow,
// svgNoHw = true
// };
// _ = EC_ReqElement.InvokeAsync(CurrFrameWindow);
// _ = EC_UpdateFrame.InvokeAsync(args);
// }
//}
}
///
/// Metodo per selezionare threshold
///
protected int SelThreshold
{
get => CurrFrameWindow.SelThresholdFromType;
set
{
if (CurrFrameWindow.SelThresholdFromType != value)
{
Threshold? threshold = CurrFrameWindow.ThresholdList.Where(x => x.Type.Equals(value)).FirstOrDefault();
string valueName = "";
if (threshold != null)
valueName = threshold.Name;
if (SashGroupList.Count > 0 || (SashGroupList.Count == 0 && !valueName.Equals("Threshold")))
{
CurrFrameWindow.SelThresholdFromType = value;
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = false
};
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
_ = EC_ReqElement.InvokeAsync(CurrFrameWindow);
_ = EC_UpdateFrame.InvokeAsync(args);
}
}
}
}
///
/// Selezione quantità bottom rail
///
protected int FrameBottomRailQty
{
get => CurrFrameWindow.BottomRailQty;
set
{
if (CurrFrameWindow.BottomRailQty != value)
{
CurrFrameWindow.BottomRailQty = value;
if (CurrFrameWindow.BottomRailQty > 0)
CurrFrameWindow.SetBottomRail(true);
else
CurrFrameWindow.SetBottomRail(false);
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = false
};
_ = EC_UpdateFrame.InvokeAsync(args);
}
}
}
#endregion Protected Properties
#region Private Methods
///
/// Metodo per selezione shape frame
///
///
///
protected async Task SelShapeFrame(int newShapeIndex)
{
if (CurrFrameWindow.SelShapeIndex != newShapeIndex)
{
CurrFrameWindow.SelShapeIndex = newShapeIndex;
// richiesta reset dict shape, profili element e hw option
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDictShape });
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetHwOpt });
foreach (var s in SashGroupList)
{
s.SelHardwareFromId = "000000";
}
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = true
};
await EC_ReqElement.InvokeAsync(CurrFrameWindow);
await EC_UpdateFrame.InvokeAsync(args);
}
}
///
/// Metodo per aggiungere sash nel frame
///
///
private async Task AddSash()
{
CurrFrameWindow.AddFirstSash();
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDictShape });
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = true,
reqShape = true
};
await EC_ReqElement.InvokeAsync(CurrFrameWindow);
await EC_UpdateFrame.InvokeAsync(args);
}
///
/// Metodo per aggiungere split nel frame
///
///
private async Task AddSplit()
{
CurrFrameWindow.AddSplit();
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = true
};
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDictShape });
if (SashGroupList.Count > 0)
await EC_ReqOptionHw.InvokeAsync(CurrFrameWindow);
await EC_ReqElement.InvokeAsync(CurrFrameWindow);
await EC_UpdateFrame.InvokeAsync(args);
}
///
/// Metodo per aggiungere inglesina nel frame
///
///
private async Task AddInglesina()
{
CurrFrameWindow.AddInglesina();
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = true
};
await EC_ReqElement.InvokeAsync(CurrFrameWindow);
await EC_UpdateFrame.InvokeAsync(args);
}
///
/// Metodo per cambiare tutti i joint
///
///
///
private Task ChangeAllJoints(Json.WindowConst.Joints JointType)
{
for (int i = 0; i < CurrFrameWindow.JointList.Count; i++)
{
if ((CurrFrameWindow.Shape is Json.WindowConst.Shapes.ARC || CurrFrameWindow.Shape is Json.WindowConst.Shapes.ARC_FULL ||
CurrFrameWindow.Shape is Json.WindowConst.Shapes.DOUBLEARC || CurrFrameWindow.Shape is Json.WindowConst.Shapes.THREECENTERARC) &&
(i == 2 || i == CurrFrameWindow.JointList.Count - 1))
CurrFrameWindow.JointList.ElementAt(i).SelJointType = Json.WindowConst.Joints.ANGLED;
else
CurrFrameWindow.JointList.ElementAt(i).SelJointType = JointType;
}
var args = new DataUpdateFrame() { currFrame = CurrFrameWindow, svgNoHw = false };
return EC_UpdateFrame.InvokeAsync(args);
}
///
/// Sollevo evento per tornare alla pagina Tree
///
private void ReqClose()
{
_ = EC_ReqClose.InvokeAsync(true);
}
///
/// Aggiornamento dimensione editata
///
/// Dimensione aggiornata
///
private async Task UpdateDim(FrameDimension updRec)
{
// cerco il record
var currRec = CurrFrameWindow.DimensionList.FirstOrDefault(x => x.ParentFrame == updRec.ParentFrame && x.nIndex == updRec.nIndex);
// lo aggiorno
if (updRec != null)
{
currRec = updRec;
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = true
};
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDictShape });
await EC_ReqElement.InvokeAsync(CurrFrameWindow);
await EC_UpdateFrame.InvokeAsync(args);
}
}
///
/// Aggiornamento joint
///
///
///
private async Task UpdateJoint(Joint updRec)
{
// cerco il record
var currRec = CurrFrameWindow.JointList.FirstOrDefault(x => x.ParentArea == updRec.ParentArea && x.nIndex == updRec.nIndex);
// lo aggiorno
if (updRec != null)
{
currRec = updRec;
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = false
};
await EC_UpdateFrame.InvokeAsync(args);
}
}
///
/// Aggiornamento element
///
///
///
private async Task UpdateElement(ElementDimension updRec)
{
// cerco il record
var currRec = CurrFrameWindow.ElementDimensionList.FirstOrDefault(x => x.ParentArea == updRec.ParentArea && x.nIndex == updRec.nIndex);
// lo aggiorno
if (updRec != null)
{
currRec = updRec;
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = true
};
await EC_UpdateFrame.InvokeAsync(args);
}
}
///
/// Aggiornamento Frame
///
///
private async Task UpdateFrame(DataBottomRail updRec)
{
// lo aggiorno
if (updRec.frame != null)
{
CurrFrameWindow = updRec.frame;
var args = new DataUpdateFrame()
{
currFrame = CurrFrameWindow,
svgNoHw = true
};
await EC_UpdateFrame.InvokeAsync(args);
}
}
private void ChangeAll()
{
ForceChangeAll = !ForceChangeAll;
}
private bool ForceChangeAll = false;
private bool SashNotInBottom()
{
bool ans = false;
if (CurrFrameWindow.AreaList[0] is Fill ||
(CurrFrameWindow.AreaList[0] is Split && CurrFrameWindow.AreaList[0].AreaList[0].AreaList[0] is Fill))
ans = true;
return ans;
}
///
/// Metodo per la visualizzazione dei pulsanti shape
///
///
///
private string ButtonShapeCss(int index)
{
string ans = "";
if (SelShapeIndex == index)
ans = "active";
return ans;
}
///
/// Metodo per la visualizzazione dei pulsanti joint
///
///
///
private string ButtonJointCss(Json.WindowConst.Joints type)
{
foreach (var item in CurrFrameWindow.JointList)
{
if (!item.SelJointType.Equals(type))
return "";
}
return "active";
}
private string EditDimensionCss()
{
if (CurrFrameWindow.DimensionList.Count % 2 == 0)
return "col-md-12 col-lg-6";
else
return "col-md-12 col-lg-4";
}
private string Traduci(string lemma)
{
string ans = "";
if (Vocabulary != null && Vocabulary.ContainsKey(lemma))
{
ans = Vocabulary.GetValueOrDefault(lemma) ?? "";
}
else
{
ans = lemma;
}
return ans;
}
#endregion Private Methods
}
///
/// Classe per raggruppare oggetti che servono per aggiornare frame
///
public class DataUpdateFrame
{
#region Public Properties
public Frame currFrame { get; set; } = null!;
public bool svgNoHw { get; set; } = false;
public int groupIdDelete { get; set; } = -1;
public bool reqShape { get; set; } = false;
#endregion Public Properties
}
}