Files
webwindowconfigurator/WebWindowComplex/Compo/CardTree.razor.cs
T
Annamaria Sassi ada0fc2ce5 - Gestito salvataggio e chiusura componente con salvataggio jwd
- Correzioni valori nulli
- Aggiunta funzione per calcolare altezza sashGroup
2026-03-03 19:02:42 +01:00

388 lines
13 KiB
C#

using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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>
/// Evento richiesta prossimo step
/// </summary>
[Parameter]
public EventCallback<DataNextStep> EC_NextStep { get; set; }
/// <summary>
/// Evento aggiornamento dizionari per collasso righe
/// </summary>
[Parameter]
public EventCallback<Dictionary<int, bool>> EC_Collapsed { get; set; }
/// <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);
}
//private Dictionary<int, bool> RowCollapsedDict { get; set; } = new Dictionary<int, bool>();
//private Dictionary<int, int> Child { get; set; } = new Dictionary<int, int>();
//protected override void OnAfterRender(bool firstRender)
//{
// if (firstRender)
// {
// foreach (var key in RowCollapsedDict.Keys.ToList())
// {
// RowCollapsedDict[key] = false;
// Child[key] = -1;
// }
// //for (int i = 0; i < ItemTableList.Count; i++)
// //{
// // for (int j = 0; j < maxCol; j++)
// // {
// // if (j + 1 == ItemTableList[i].Col)
// // {
// // TableList.Add(new DataTable
// // {
// // item = ItemTableList[i],
// // row = i,
// // col = j,
// // hidden = false
// // });
// // }
// // else
// // {
// // FillTable(i, j);
// // }
// // }
// //}
// }
//}
//protected override void OnParametersSet()
//{
// RowCollapsedDict.Clear();
// Child.Clear();
// foreach (var item in ItemTableList)
// {
// if(item.NumChild > 4)
// {
// RowCollapsedDict.Add(item.Row, false);
// Child.Add(item.Row, item.NumChild);
// }
// }
//}
/// <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";
}
//private async Task Remove(CompileStep cs, int indexStep)
//{
// var Args = new DataNextStep
// {
// currCompileStep = cs,
// index = indexStep,
// };
// await EC_NextStep.InvokeAsync(Args);
//}
/// <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 void 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)
// {
// TableList.Add(new DataTable
// {
// symbol = "└",
// row = row,
// col = col,
// hidden = false
// });
// }
// else if (itemSameCol.Last().NumChild == 0)
// {
// TableList.Add(new DataTable
// {
// symbol = " ",
// row = row,
// col = col,
// hidden = false
// });
// }
// else
// {
// TableList.Add(new DataTable
// {
// symbol = "├",
// row = row,
// col = col,
// hidden = false
// });
// }
// }
// // Non sono alla riga successiva
// else
// {
// // se ha un solo figlio
// if (itemSameCol.Last().NumChild == 1)
// {
// TableList.Add(new DataTable
// {
// symbol = " ",
// row = row,
// col = col,
// hidden = false
// });
// }
// else if (col + 2 <= maxCol && ItemTableList[row].Col == col + 2)
// {
// if (numItemNextCol < itemSameCol.Last().NumChild && numItemNextCol != (itemSameCol.Last().NumChild - 1))
// {
// TableList.Add(new DataTable
// {
// symbol = "├",
// row = row,
// col = col,
// hidden = false
// });
// }
// TableList.Add(new DataTable
// {
// symbol = "└",
// row = row,
// col = col,
// hidden = false
// });
// }
// else if (numItemNextCol < itemSameCol.Last().NumChild)
// {
// TableList.Add(new DataTable
// {
// symbol = "│",
// row = row,
// col = col,
// hidden = false
// });
// }
// else
// {
// TableList.Add(new DataTable
// {
// symbol = " ",
// row = row,
// col = col,
// hidden = false
// });
// }
// }
// }
// else
// {
// TableList.Add(new DataTable
// {
// symbol = " ",
// row = row,
// col = col,
// hidden = false
// });
// }
// }
//}
}
/// <summary>
/// Classe per inserire dati per NextStep
/// </summary>
public class DataNextStep
{
public CompileStep currCompileStep { get; set; }
public int index { get; set; }
}
}