Files
webwindowconfigurator/WebWindowComplex/Compo/EditSplitDimensions.razor.cs
T
2026-08-20 16:30:29 +02:00

209 lines
5.9 KiB
C#

using Microsoft.AspNetCore.Components;
using WebWindowComplex.Models;
namespace WebWindowComplex.Compo
{
public partial class EditSplitDimensions
{
#region Public Properties
/// <summary>
/// Split dimension corrente
/// </summary>
[Parameter]
public SplitDimension CurrRec { get; set; } = null!;
/// <summary>
/// Nome dello split dimension corrente
/// </summary>
[Parameter]
public string Name { get; set; } = null!;
/// <summary>
/// Indice dello split dimension
/// </summary>
[Parameter]
public int Index { get; set; } = -1;
/// <summary>
/// Indice dello split dimension
/// </summary>
[Parameter]
public int TotElem { get; set; } = -1;
/// <summary>
/// Livello di accesso (utente base)
/// </summary>
[CascadingParameter(Name = "User")]
public bool BaseUser { get; set; } = false!;
/// <summary>
/// Vocabolario con traduzione lingua corrente
/// </summary>
[CascadingParameter(Name = "Vocabulary")]
public Dictionary<string, string> Vocabulary { get; set; } = null!;
[Parameter]
public EventCallback<DataUpdateSplitDimension> EC_Update { get; set; }
#endregion Public Properties
#region Protected Properties
protected override void OnParametersSet()
{
SplitDict = Vocabulary.Where(x => x.Key.Contains("CWSplitDim_")).ToDictionary(x => x.Key, y => y.Value);
}
#endregion Protected Properties
#region Private Fields
private Dictionary<string, string> SplitDict = new();
#endregion Private Fields
#region Private Properties
/// <summary>
/// Metodo per aggiornare la dimensione
/// </summary>
private double CurrVal
{
get => Math.Round(CurrRec.dDimension, CssDecimals());
set
{
if (CurrRec.dDimension != value)
{
CurrRec.dDimension = (double)Math.Round((decimal)value, CssDecimals());
var args = new DataUpdateSplitDimension()
{
currSplit = CurrRec,
index = Index
};
_ = EC_Update.InvokeAsync(args);
}
}
}
/// <summary>
/// Metodo per aggiornare il tipo della dimensione
/// </summary>
private int CurrType
{
get => CurrRec.SelMeasureTypeIndex;
set
{
if (CurrRec.SelMeasureTypeIndex != value)
{
CurrRec.SelMeasureTypeIndex = value;
var args = new DataUpdateSplitDimension()
{
currSplit = CurrRec,
index=Index,
noSvg = true
};
_ = EC_Update.InvokeAsync(args);
}
}
}
#endregion Private Properties
/// <summary>
/// Metodo per avere il numero di decimali da usare nella form-input
/// </summary>
/// <returns></returns>
public int CssDecimals()
{
switch (CurrRec.MeasureType)
{
case Json.WindowConst.MeasureTypes.ABSOLUTE:
{
return 2;
}
case Json.WindowConst.MeasureTypes.PROPORTIONAL:
{
return 0;
}
case Json.WindowConst.MeasureTypes.PERCENTAGE:
{
return 1;
}
}
return 0;
}
/// <summary>
/// Metodo per avere il lo step da usare nella form-input
/// </summary>
/// <returns></returns>
public double CssStepNumber()
{
switch (CurrRec.MeasureType)
{
case Json.WindowConst.MeasureTypes.ABSOLUTE:
{
return 0.5;
}
case Json.WindowConst.MeasureTypes.PROPORTIONAL:
{
return 1;
}
case Json.WindowConst.MeasureTypes.PERCENTAGE:
{
return 0.5;
}
}
return 0;
}
/// <summary>
/// Metodo per path immagine delle dimensioni
/// </summary>
/// <returns></returns>
private string GetImageDimensionPath()
{
string nameFile = Name;
if (Index == 0)
{
nameFile = nameFile + "1";
}
else if (Index == TotElem - 1)
{
nameFile = nameFile + "3";
}
else
{
nameFile = nameFile + "2";
}
return $"_content/Egw.Lux.WebWindowComplex/icone/split/dimension/{nameFile}.svg";
}
/// <summary>
/// Metodo per traduzione in lingua corrente
/// </summary>
/// <param name="lemma"></param>
/// <returns></returns>
private string Traduci(string lemma)
{
string ans = lemma;
if (SplitDict != null && SplitDict.ContainsKey(lemma))
{
ans = SplitDict.GetValueOrDefault(lemma) ?? "";
}
return ans;
}
}
/// <summary>
/// Classe per aggiornare split dimension
/// </summary>
public class DataUpdateSplitDimension
{
public SplitDimension currSplit { get; set; } = null!;
public int index { get; set; } = -1;
public bool noSvg { get; set; } = false;
}
}