using Microsoft.AspNetCore.Components; using Newtonsoft.Json; using System.Collections.ObjectModel; using System.Reflection.Metadata; using System.Runtime.Intrinsics.X86; using System.Text.Json.Serialization; using WebWindowConfigurator.DTO; using WebWindowConfigurator.Json; using static WebWindowConfigurator.Json.WindowConst; namespace WebWindowConfigurator { public partial class WebWindowMaker : IDisposable { public void Dispose() { if (m_CurrWindow != null) { m_CurrWindow.OnPreview -= M_CurrWindow_OnPreview; m_CurrWindow = null; } } #region Public Properties [Parameter] public string CssSvg { get; set; } = "responsive-svg"; [Parameter] public EventCallback EC_OnClose { get; set; } [Parameter] public EventCallback EC_OnSelectedTemplate { get; set; } [Parameter] public EventCallback EC_OnUpdate { get; set; } public List FillList { get => m_FillList; } [Parameter] public Template IN_SelTemplate { get => m_SelTemplate; set { if (value != null && (m_SelTemplate == null || (m_SelTemplate != null && value.nIndex != m_SelTemplate.nIndex)) && !string.IsNullOrEmpty(value.JWD)) { m_SelTemplate = value; JsonWindow WindowFromJson = JsonConvert.DeserializeObject(m_SelTemplate.JWD, new PolymorphicJsonConverter()) ?? new JsonWindow(""); if (m_CurrWindow != null) { m_CurrWindow.OnPreview -= M_CurrWindow_OnPreview; m_CurrWindow = null; } m_CurrWindow = WindowFromJson.Deserialize(); m_CurrWindow.OnPreview += M_CurrWindow_OnPreview; m_FillList = new List(); m_SashList = new List(); m_SplitList = new List(); SearchInAreaList(m_CurrWindow.AreaList[0]); m_SelSVG = m_SelTemplate.SVG; } if (m_CurrWindow != null) { m_FillList = new List(); m_SashList = new List(); m_SplitList = new List(); SearchInAreaList(m_CurrWindow.AreaList[0]); } } } [Parameter] public List IN_TemplateDTOList { get; set; } = null!; [Parameter] public string LiveSVG { get => m_SelSVG; set => m_SelSVG = value; } public List SashList { get => m_SashList; } public TemplateSelectDTO? SelTemplateDTO { get; set; } = null; public List SplitList { get => m_SplitList; } #endregion Public Properties #region Public Methods public void SearchInAreaList(Area node) { if (node != null) { switch (node.AreaType) { case AreaTypes.FRAME: { m_Frame = (Frame)node; break; } case AreaTypes.SASH: { m_SashList.Add((Sash)node); break; } case AreaTypes.FILL: { m_FillList.Add((Fill)node); break; } case AreaTypes.SPLIT: { m_SplitList.Add((Split)node); break; } } foreach (var item in node.AreaList) { SearchInAreaList(item); } } } #endregion Public Methods #region Protected Enums protected enum CompileStep { Template = 0, Frame = 1, Split, Sash, Fill } #endregion Protected Enums #region Protected Properties protected Frame Frame { get => m_Frame; set => m_Frame = value; } protected string m_SelSVG { get; set; } = ""; /// /// Componente SVG da mostrare /// protected MarkupString outSvg { get { // aggiunta gestione classe svg per posizionamento con costraints var newSvg = LiveSVG.Replace(" m_FillList = new List(); private Frame m_Frame; private List m_SashList = new List(); private List m_SplitList = new List(); #endregion Private Fields #region Private Properties private Window? m_CurrWindow { get; set; } = null; //private Window m_CurrWindow { get; set; } = new Window(); private Template m_SelTemplate { get; set; } = null!; private string mainCss { get => (SelTemplateDTO != null && currStep != CompileStep.Template) ? "col-6" : "col-12"; } #endregion Private Properties #region Private Methods private void AdvStep(CompileStep newStep) { currStep = newStep; } /// /// Calcola il css del tab selezionato /// /// /// private string tabNavCss(CompileStep testStep) { return testStep.Equals(currStep) ? "nav-link active fw-bold" : "nav-link text-secondary"; } #endregion Private Methods } }