190 lines
5.3 KiB
C#
190 lines
5.3 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Newtonsoft.Json;
|
|
using WebDoorCreator.Data.DbModels;
|
|
using WebDoorCreator.UI.Data;
|
|
|
|
namespace WebDoorCreator.UI.Components.Hardware
|
|
{
|
|
public partial class HwSingleInstance
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public DoorOpModel DoorOpInst { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public string HwCode { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public string Lingua { get; set; } = "EN";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void setupCurrValues()
|
|
{
|
|
//currVal = new Dictionary<string, string>();
|
|
if (!string.IsNullOrEmpty(DoorOpInst.JsoncActVal))
|
|
{
|
|
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, string>>(DoorOpInst.JsoncActVal!);
|
|
if (deserialized != null)
|
|
{
|
|
currVal = deserialized;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setupGraphicParams()
|
|
{
|
|
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(DoorOpInst.JsoncConfigVal!);
|
|
if (deserialized != null)
|
|
{
|
|
graphicParams = deserialized;
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
//public Dictionary<string, Dictionary<string, List<string>>> getGraphicParams()
|
|
//{
|
|
// var deserialized = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, List<string>>>>(DoorOpInst.JsoncConfigVal!);
|
|
// if (deserialized != null)
|
|
// {
|
|
// graphicParams = deserialized;
|
|
// }
|
|
// return graphicParams;
|
|
//}
|
|
protected string _folderName
|
|
{
|
|
get => currVal != null ? currVal["folder"] : "";
|
|
set => currVal["folder"] = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Array dati
|
|
/// </summary>
|
|
protected Dictionary<string, string> currVal { get; set; } = null!;
|
|
|
|
protected string folderName
|
|
{
|
|
get => _folderName;
|
|
set
|
|
{
|
|
if (_folderName != value)
|
|
{
|
|
_folderName = value;
|
|
var pUpd = Task.Run(async () => await ReloadData(false));
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string templateName
|
|
{
|
|
get => currVal != null ? currVal["template"] : "";
|
|
set => currVal["template"] = value;
|
|
}
|
|
|
|
protected Dictionary<string, List<string>> graphicParams { get; set; } = null!;
|
|
protected List<ListValuesModel>? listValuesFiles { get; set; } = null!;
|
|
|
|
protected List<ListValuesModel>? listValuesFname { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected WebDoorCreatorService WDCService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected WDCVocabularyService WDVService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected bool isCombo(string pKey)
|
|
{
|
|
bool answ = false;
|
|
if (graphicParams.ContainsKey(pKey))
|
|
{
|
|
answ = graphicParams[pKey].Count > 1;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected List<string> comboSet(string pKey)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
if (graphicParams.ContainsKey(pKey))
|
|
{
|
|
answ = graphicParams[pKey].ToList();
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
|
|
protected async Task doSave()
|
|
{
|
|
// ri-serializzo i graphics parameters...
|
|
string serVal = JsonConvert.SerializeObject(currVal);
|
|
DoorOpInst.JsoncActVal = serVal;
|
|
// salvo!
|
|
await WDCService.DoorOpUpdate(DoorOpInst);
|
|
}
|
|
|
|
protected async Task doCancel()
|
|
{
|
|
await FullReloadData(true);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await FullReloadData(true);
|
|
}
|
|
|
|
protected string translate(string lemma)
|
|
{
|
|
string answ = "";
|
|
|
|
answ = WDVService.Traduci(Lingua, lemma);
|
|
|
|
return answ;
|
|
}
|
|
|
|
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
private async Task FullReloadData(bool isFirst)
|
|
{
|
|
setupCurrValues();
|
|
setupGraphicParams();
|
|
await ReloadData(isFirst);
|
|
}
|
|
private async Task ReloadData(bool isFirst)
|
|
{
|
|
var tempListVal = await WDCService.ListValuesGetAll(HwCode, "Folder");
|
|
if (tempListVal != null)
|
|
{
|
|
listValuesFname = tempListVal;
|
|
if (listValuesFname != null)
|
|
{
|
|
if (isFirst)
|
|
{
|
|
folderName = listValuesFname.FirstOrDefault()?.Label!;
|
|
}
|
|
var tempListFiles = await WDCService.ListValuesGetAll(HwCode, "Template");
|
|
|
|
if (tempListFiles != null)
|
|
{
|
|
listValuesFiles = tempListFiles.Where(x => x.Value.Contains(folderName)).ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |