Files
webwindowconfigurator/WebWindowComplex/Compo/CardTree.razor.cs
T
2026-04-23 16:48:37 +02:00

399 lines
13 KiB
C#

using Microsoft.AspNetCore.Components;
using WebWindowComplex.Models;
using static WebWindowComplex.LayoutConst;
namespace WebWindowComplex.Compo
{
public partial class CardTree
{
/// <summary>
/// Lista oggetti ItemTable
/// </summary>
[Parameter]
public List<ItemTable> ItemTableList { get; set; } = null!;
/// <summary>
/// Numero massimo di colonne
/// </summary>
[Parameter]
public int maxCol { get; set; } = 0;
/// <summary>
/// Dizionario con elementi che possono collassare
/// </summary>
[Parameter]
public Dictionary<int, bool> RowCollapsedDict { get; set; } = new Dictionary<int, bool>();
/// <summary>
/// Dizionario con numero di figli per elementi che possono collassare
/// </summary>
[Parameter]
public Dictionary<int, int> ChildDict { get; set; } = new Dictionary<int, int>();
/// <summary>
/// Lista di sash
/// </summary>
[Parameter]
public List<Sash> SashGroupList { get; set; } = null!;
/// <summary>
/// Lista di split
/// </summary>
[Parameter]
public List<Split> SplitList { get; set; } = null!;
/// <summary>
/// Lista di splitted
/// </summary>
[Parameter]
public List<Splitted> SplittedList { get; set; } = null!;
/// <summary>
/// Lista di fill
/// </summary>
[Parameter]
public List<Fill> FillList { get; set; } = null!;
/// <summary>
/// Lista di sash
/// </summary>
[Parameter]
public Frame FrameWindow { get; set; } = null!;
/// <summary>
/// Evento richiesta prossimo step
/// </summary>
[Parameter]
public EventCallback<DataNextStep> EC_NextStep { get; set; }
/// <summary>
/// Evento richiesta prossimo step
/// </summary>
[Parameter]
public EventCallback<DataNextStep> EC_Remove { get; set; }
/// <summary>
/// Evento aggiornamento dizionari per collasso righe
/// </summary>
[Parameter]
public EventCallback<Dictionary<int, bool>> EC_Collapsed { get; set; }
/// <summary>
/// Evento per richiedere reset dizionari
/// </summary>
[Parameter]
public EventCallback<DataUpdateRes> EC_ReqResetDict { get; set; }
/// <summary>
/// Evento per richiedere opzioni hardware
/// </summary>
[Parameter]
public EventCallback<Frame> EC_ReqOptionHw { get; set; }
/// <summary>
/// Evento per richiesta profili degli Element
/// </summary>
[Parameter]
public EventCallback<Frame> EC_ReqElement { get; set; }
/// <summary>
/// Evento per richiesta calcolo preview
/// </summary>
[Parameter]
public EventCallback<DataUpdateFrame> EC_UpdateFrame { get; set; }
/// <summary>
/// Evento per aggiungere Sash
/// </summary>
[Parameter]
public EventCallback<Splitted> EC_UpdateSplitted { get; set; }
protected override void OnParametersSet()
{
for(int i = 0; i < FillList.Count; i++)
{
isOpenFill.Add(false);
}
}
/// <summary>
/// Metodo per richiesta prossimo step
/// </summary>
/// <returns></returns>
private Task RaiseNextStep(CompileStep cs, int indexStep)
{
var Args = new DataNextStep
{
currCompileStep = cs,
index = indexStep,
};
return EC_NextStep.InvokeAsync(Args);
}
/// <summary>
/// Metodo per aprire/chiudere sottorighe
/// </summary>
/// <returns></returns>
private Task ChangeCollapsed(int row)
{
RowCollapsedDict[row] = RowCollapsedDict[row] ? false : true;
return EC_Collapsed.InvokeAsync(RowCollapsedDict);
}
private string hwIcon(int row)
{
return RowCollapsedDict[row] ? "fa-solid fa-chevron-down" : "fa-solid fa-chevron-up";
}
/// <summary>
/// Metodo per rimuovere area (sash group o split)
/// </summary>
/// <param name="cs"></param>
/// <param name="indexStep"></param>
/// <returns></returns>
private Task Remove(CompileStep cs, int indexStep)
{
var Args = new DataNextStep
{
currCompileStep = cs,
index = indexStep,
};
return EC_Remove.InvokeAsync(Args);
}
/// <summary>
/// Chiamata per aggiungere sash al frame
/// </summary>
/// <returns></returns>
private async Task RaiseAddSash()
{
FrameWindow.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 = FrameWindow,
svgNoHw = true,
reqShape = true
};
await EC_ReqElement.InvokeAsync(FrameWindow);
await EC_UpdateFrame.InvokeAsync(args);
}
/// <summary>
/// Chiamata per aggiungere split al frame
/// </summary>
/// <returns></returns>
private async Task RaiseAddSplit()
{
FrameWindow.AddSplit();
Split s = (Split)FrameWindow.AreaList[0];
foreach(var item in s.AreaList)
{
if (item.AreaList.FirstOrDefault() is Fill)
isOpenFill.Add(false);
}
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
var args = new DataUpdateFrame()
{
currFrame = FrameWindow,
svgNoHw = true
};
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDictShape });
if (SashGroupList.Count > 0)
await EC_ReqOptionHw.InvokeAsync(FrameWindow);
await EC_ReqElement.InvokeAsync(FrameWindow);
await EC_UpdateFrame.InvokeAsync(args);
}
/// <summary>
/// Chiamata per aggiungere sash in un fill
/// </summary>
/// <param name="currIndexFill"> indice del fill </param>
/// <returns></returns>
private Task AddSashIntoFill(int currIndexFill)
{
Splitted? currSplitted = SplittedList.Where(x => x.AreaList.First().Equals(FillList[currIndexFill])).FirstOrDefault();
if (currSplitted != null)
currSplitted.AddFirstSash();
return EC_UpdateSplitted.InvokeAsync(currSplitted);
}
/// <summary>
/// Chiamata per aggiungere inglesina in un fill
/// </summary>
/// <param name="currIndexFill"> indice del fill </param>
/// <returns></returns>
private Task AddInglesinaIntoFill(int currIndexFill)
{
Splitted? currSplitted;
Frame? currFrame;
if (FillList.ElementAt(currIndexFill).ParentArea is Splitted)
{
currSplitted = (Splitted)FillList.ElementAt(currIndexFill).ParentArea;
currSplitted.AddInglesina();
return EC_UpdateSplitted.InvokeAsync(currSplitted);
}
else if(FillList.ElementAt(currIndexFill).ParentArea is Frame)
{
currFrame = (Frame)FillList.ElementAt(currIndexFill).ParentArea;
currFrame.AddInglesina();
DataUpdateFrame args = new DataUpdateFrame()
{
currFrame = currFrame
};
return EC_UpdateFrame.InvokeAsync(args);
}
return null;
}
/// <summary>
/// Chiamata per copiare sash in fill
/// </summary>
/// <param name="indexCurrSash"> indice della sash da copiare </param>
/// <param name="currIndexFill"> indice del fill </param>
/// <returns></returns>
private Task CopySashIntoFill(int indexCurrSash, int currIndexFill)
{
Splitted? currSplitted = SplittedList.Where(x => x.AreaList.First().Equals(FillList[currIndexFill])).FirstOrDefault();
if (currSplitted != null)
{
currSplitted.AreaList.RemoveAll(i => i != null);
Area a = SashGroupList[indexCurrSash].Copy(currSplitted);
a.SetParentArea(currSplitted);
currSplitted.AreaList.Add(a);
}
return EC_UpdateSplitted.InvokeAsync(currSplitted);
}
/// <summary>
/// Metodo per riempire tabella con contenuto vuoto o con i simboli per rappresentare la struttura
/// </summary>
/// <param name="row"> riga della cella </param>
/// <param name="col"> colonna della cella </param>
/// <returns></returns>
private string FillTable(int row, int col)
{
List<ItemTable> itemSameCol = new List<ItemTable>();
for (int k = 0; k < row; k++)
{
if (ItemTableList[k].Col == col + 1)
{
itemSameCol.Add(ItemTableList[k]);
}
continue;
}
int numItemNextCol = 0;
for (int k = 0; k < row; k++)
{
if (ItemTableList[k].Row <= row && ItemTableList[k].Col == col + 2)
{
numItemNextCol++;
}
continue;
}
if (itemSameCol.Count > 1)
{
for (int i = 0; i <= itemSameCol.Count - 2; i++)
{
if (itemSameCol[i].NumChild > 0)
numItemNextCol = numItemNextCol - itemSameCol[i].NumChild;
}
}
if (itemSameCol.Count > 0)
{
// Sono alla riga successiva di un elemento e nella stessa colonna
if (itemSameCol.Last().Row == row)
{
// se ha un solo figlio
if (itemSameCol.Last().NumChild == 1)
{
return "└";
}
else if (itemSameCol.Last().NumChild == 0)
{
return " ";
}
else
{
return "├";
}
}
// Non sono alla riga successiva
else
{
// se ha un solo figlio
if (itemSameCol.Last().NumChild == 1)
{
return " ";
}
else if (col + 2 <= maxCol && ItemTableList[row].Col == col + 2)
{
if (numItemNextCol < itemSameCol.Last().NumChild && numItemNextCol != (itemSameCol.Last().NumChild - 1))
{
return "├";
}
return "└";
}
else if (numItemNextCol < itemSameCol.Last().NumChild)
{
return "│";
}
else
{
return " ";
}
}
}
else
{
return " ";
}
}
private bool HideRow(int row, int col)
{
List<ItemTable> itemSameCol = new List<ItemTable>();
for (int k = 0; k < row; k++)
{
if (ItemTableList[k].Col == col + 1)
{
itemSameCol.Add(ItemTableList[k]);
}
continue;
}
if(itemSameCol.Count > 0)
{
ItemTable? firstItem = itemSameCol.FirstOrDefault();
if (firstItem != null)
return RowCollapsedDict.GetValueOrDefault(firstItem.Row - 1);
}
return false;
}
private bool isOpenFrame = false;
private void ToggleDropdownFrame()
{
isOpenFrame = !isOpenFrame;
}
private List<bool> isOpenFill = new();
private void ToggleDropdownFill(int currIndexFill)
{
isOpenFill[currIndexFill] = !isOpenFill.ElementAt(currIndexFill);
}
}
/// <summary>
/// Classe per inserire dati per NextStep
/// </summary>
public class DataNextStep
{
public CompileStep currCompileStep { get; set; }
public int index { get; set; }
}
}