d740267d06
- aggiunti controlli su alcuni campi
325 lines
9.5 KiB
C#
325 lines
9.5 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Newtonsoft.Json;
|
|
using System.Reflection.Metadata;
|
|
using WebWindowConfigurator.DTO;
|
|
using WebWindowConfigurator.Json;
|
|
using static WebWindowConfigurator.Json.WindowConst;
|
|
|
|
namespace WebWindowConfigurator
|
|
{
|
|
public partial class WebWindowMaker : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public string CssSvg { get; set; } = "responsive-svg";
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_OnClose { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<TemplateSelectDTO> EC_OnSelectedTemplate { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<Dictionary<string,string>> EC_OnUpdate { get; set; }
|
|
|
|
[Parameter]
|
|
public Template IN_SelTemplate
|
|
{
|
|
get => m_SelTemplate;
|
|
set
|
|
{
|
|
// Se non ho ancora selezionato template oppure se cambio template di selezione
|
|
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<JsonWindow>(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<Fill>();
|
|
m_SashList = new List<Sash>();
|
|
m_SplitList = new List<Split>();
|
|
// popolo le liste Fill, Sash e Split
|
|
CreateWindowsList(m_CurrWindow.AreaList[0]);
|
|
m_SelSVG = m_SelTemplate.SVG;
|
|
}
|
|
// serve per quando aumentano/diminuiscono quantità Sash e Split (bisogna ricalcolare le liste)
|
|
if (m_CurrWindow != null)
|
|
{
|
|
m_FillList = new List<Fill>();
|
|
m_SashList = new List<Sash>();
|
|
m_SplitList = new List<Split>();
|
|
CreateWindowsList(m_CurrWindow.AreaList[0]);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public List<TemplateSelectDTO> IN_TemplateDTOList { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public string LiveSVG
|
|
{
|
|
get => m_SelSVG;
|
|
set => m_SelSVG = value;
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
if (m_CurrWindow != null)
|
|
{
|
|
m_CurrWindow.OnPreview -= M_CurrWindow_OnPreview;
|
|
m_CurrWindow = null;
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Enums
|
|
|
|
protected enum CompileStep
|
|
{
|
|
Template = 0,
|
|
Frame = 1,
|
|
Split,
|
|
Sash,
|
|
Fill
|
|
}
|
|
|
|
#endregion Protected Enums
|
|
|
|
#region Protected Properties
|
|
|
|
protected Frame FrameWindow
|
|
{
|
|
get => m_Frame;
|
|
set => m_Frame = value;
|
|
}
|
|
|
|
protected string m_SelSVG { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Componente SVG da mostrare
|
|
/// </summary>
|
|
protected MarkupString outSvg
|
|
{
|
|
get
|
|
{
|
|
// aggiunta gestione classe svg per posizionamento con costraints
|
|
var newSvg = LiveSVG.Replace("<svg", $"<svg class=\"{CssSvg}\"");
|
|
return (MarkupString)newSvg;
|
|
}
|
|
}
|
|
|
|
protected List<Sash> SashList
|
|
{
|
|
get => m_SashList;
|
|
}
|
|
protected List<Split> SplitList
|
|
{
|
|
get => m_SplitList;
|
|
}
|
|
|
|
protected List<Fill> FillList
|
|
{
|
|
get => m_FillList;
|
|
}
|
|
|
|
protected TemplateSelectDTO? SelTemplateDTO { get; set; } = null;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Metodo per la scelta della maniglia univoca
|
|
/// </summary>
|
|
/// <param name="sashDim"></param>
|
|
/// <returns></returns>
|
|
protected async Task changeHandle(SashDimension sashDim)
|
|
{
|
|
foreach (SashDimension item in SashList[0].SashList)
|
|
{
|
|
if (item.Equals(sashDim))
|
|
{
|
|
item.bHasHandle = true;
|
|
}
|
|
else
|
|
{
|
|
item.bHasHandle = false;
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
// Ancora da fare...
|
|
protected async Task DoClose()
|
|
{
|
|
await EC_OnClose.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anteprima SVG
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task DoPreviewSvg()
|
|
{
|
|
if (m_CurrWindow != null)
|
|
{
|
|
var CurrJwd = JsonConvert.SerializeObject(m_CurrWindow.Serialize(), Formatting.Indented);
|
|
Dictionary<string, string> Args = new Dictionary<string, string>();
|
|
Args.Add("Jwd", CurrJwd);
|
|
Args.Add("Mode", 1.ToString());
|
|
await EC_OnUpdate.InvokeAsync(Args);
|
|
}
|
|
}
|
|
|
|
// Ancora da fare..
|
|
protected async Task DoSave()
|
|
{
|
|
//manca salvataggio JWD
|
|
await EC_OnClose.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione del template
|
|
/// </summary>
|
|
/// <param name="newSel"> template selezionato</param>
|
|
protected async void DoSelect(TemplateSelectDTO newSel)
|
|
{
|
|
SelTemplateDTO = newSel;
|
|
//DoSelectAndPreview(CompileStep.Frame);
|
|
await EC_OnSelectedTemplate.InvokeAsync(newSel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo per cambiare step e aggiornare preview svg
|
|
/// </summary>
|
|
/// <param name="newStep"> step successivo</param>
|
|
protected async void NextStepAndPreview(CompileStep newStep)
|
|
{
|
|
currStep = newStep;
|
|
await DoPreviewSvg();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo per identificare oggetti nella Window e popolare le liste Fill, Sash e Split
|
|
/// </summary>
|
|
/// <param name="node"></param>
|
|
protected void CreateWindowsList(Area node)
|
|
{
|
|
if (node != null)
|
|
{
|
|
switch (node.AreaType)
|
|
{
|
|
case AreaTypes.FRAME:
|
|
{
|
|
FrameWindow = (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)
|
|
{
|
|
CreateWindowsList(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private CompileStep currStep = CompileStep.Template;
|
|
|
|
private Frame m_Frame;
|
|
|
|
private List<Sash> m_SashList = new List<Sash>();
|
|
|
|
private List<Split> m_SplitList = new List<Split>();
|
|
|
|
private List<Fill> m_FillList = new List<Fill>();
|
|
|
|
private enum positionJoints
|
|
{
|
|
BL=0,
|
|
BR=1,
|
|
TR,
|
|
TL
|
|
}
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private Window? m_CurrWindow { get; set; } = null;
|
|
|
|
private Template m_SelTemplate { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Metodo per andare allo step successivo
|
|
/// </summary>
|
|
/// <param name="newStep"> step successivo</param>
|
|
private void AdvStep(CompileStep newStep)
|
|
{
|
|
currStep = newStep;
|
|
}
|
|
|
|
private void M_CurrWindow_OnPreview(object? sender, OnPreviewEventArgs e)
|
|
{
|
|
Dictionary<string, string> Args = new Dictionary<string, string>();
|
|
Args.Add("Jwd", e.sJwd);
|
|
Args.Add("Mode", 1.ToString());
|
|
EC_OnUpdate.InvokeAsync(Args);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calcola il css del tab selezionato
|
|
/// </summary>
|
|
/// <param name="testStep"></param>
|
|
/// <returns></returns>
|
|
private string tabNavCss(CompileStep testStep)
|
|
{
|
|
return testStep.Equals(currStep) ? "nav-link active fw-bold" : "nav-link text-secondary";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calcola larghezza colonna da mostrare
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string mainCss()
|
|
{
|
|
return currStep == CompileStep.Template ? "col-12" : "col-6";
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |