using Microsoft.AspNetCore.Components;
using WebWindowComplex.Models;
namespace WebWindowComplex.Compo
{
public partial class EditSplitDimensions
{
#region Public Properties
///
/// Split dimension corrente
///
[Parameter]
public SplitDimension CurrRec { get; set; } = null!;
///
/// Nome dello split dimension corrente
///
[Parameter]
public string Name { get; set; } = null!;
///
/// Indice dello split dimension
///
[Parameter]
public int Index { get; set; } = -1;
///
/// Indice dello split dimension
///
[Parameter]
public int TotElem { get; set; } = -1;
///
/// Livello di accesso (utente base)
///
[CascadingParameter(Name = "User")]
public bool BaseUser { get; set; } = false!;
///
/// Vocabolario con traduzione lingua corrente
///
[CascadingParameter(Name = "Vocabulary")]
public Dictionary Vocabulary { get; set; } = null!;
[Parameter]
public EventCallback 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 SplitDict = new();
#endregion Private Fields
#region Private Properties
///
/// Metodo per aggiornare la dimensione
///
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);
}
}
}
///
/// Metodo per aggiornare il tipo della dimensione
///
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
///
/// Metodo per avere il numero di decimali da usare nella form-input
///
///
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;
}
///
/// Metodo per avere il lo step da usare nella form-input
///
///
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;
}
///
/// Metodo per path immagine delle dimensioni
///
///
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";
}
///
/// Metodo per traduzione in lingua corrente
///
///
///
private string Traduci(string lemma)
{
string ans = lemma;
if (SplitDict != null && SplitDict.ContainsKey(lemma))
{
ans = SplitDict.GetValueOrDefault(lemma) ?? "";
}
return ans;
}
}
///
/// Classe per aggiornare split dimension
///
public class DataUpdateSplitDimension
{
public SplitDimension currSplit { get; set; } = null!;
public int index { get; set; } = -1;
public bool noSvg { get; set; } = false;
}
}