Files
2024-04-19 09:32:05 +02:00

130 lines
4.5 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.CodeAnalysis.VisualBasic.Syntax;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.Data.Services;
namespace WebDoorCreator.UI.Components.FilesMan
{
public partial class VocRefresh
{
[Inject]
protected WebDoorCreatorService WDCService { get; set; } = null!;
[Parameter]
public string lang { get; set; } = "";
protected Dictionary<string, Dictionary<string, string>>? vocLemmas { get; set; } = null;
protected Dictionary<string, string> vocLemmas2Dict { get; set; } = new Dictionary<string, string>();
protected Dictionary<string, Dictionary<string, string>>? vocLemmasTEMP { get; set; } = null;
protected Dictionary<string, string> vocLemmasTEMP2Dict { get; set; } = new Dictionary<string, string>();
protected bool showList { get; set; } = true;//false;
protected bool isLoading { get; set; } = false;
protected async override Task OnParametersSetAsync()
{
var rawVoc = await WDCService.VocLemmaGetAll();
if (rawVoc != null)
{
vocLemmas = rawVoc.Where(x => x.Key == lang).ToDictionary(x => x.Key, x => x.Value);
if (vocLemmas != null)
{
foreach (var kvp in vocLemmas)
{
foreach (var item in kvp.Value)
{
vocLemmas2Dict.Add(item.Key, item.Value);
}
}
}
}
}
#if false
var s = dmp.diff_main(vocLemmas2Dict["11"], newText.Value);
dmp.diff_cleanupSemantic(s);
foreach (var diffes in s)
{
if (diffes.operation == Operation.DELETE)
{
diff.Add(diffes);
}
}
#endif
Dictionary<string, Dictionary<string, string>> listVocLemmaTemp = new Dictionary<string, Dictionary<string, string>>();
protected async Task refreshVoc()
{
isLoading = true;
vocLemmasTEMP = null;
await Task.Delay(1);
list2Mod = await WDCService.VocLemmaInsertPrepare(@$"{defaultPath}");
if (list2Mod != null)
{
listVocLemmaTemp = await WDCService.VocLemmaTEMPGetAll();
if (listVocLemmaTemp != null)
{
vocLemmasTEMP = listVocLemmaTemp.Where(x => x.Key == lang).ToDictionary(x => x.Key, x => x.Value);
if (vocLemmasTEMP != null)
{
foreach (var kvp in vocLemmasTEMP)
{
foreach (var item in kvp.Value)
{
vocLemmasTEMP2Dict.Add(item.Key, item.Value);
}
}
}
}
}
isLoading = false;
showList = true;
}
List<VocabularyTempModel> list2Mod = new List<VocabularyTempModel>();
protected string result { get; set; } = "Not Done";
protected async Task saveVoc()
{
var done = await WDCService.VocLemmaInsert();
if (done)
{
result = "Done";
vocLemmas2Dict.Clear();
vocLemmasTEMP2Dict.Clear();
}
}
protected bool isReady2Save(string lemma)
{
bool isConf = false;
var tempModTerm = Task.Run(async () => await WDCService.VocLemmaFindByKeys(lang, lemma)).Result;
if (tempModTerm != null)
{
isConf = tempModTerm.IsConfSave;
}
return isConf;
}
protected string setBtnClass(bool isCon)
{
string answ = "btn-secondary";
if (isCon)
{
answ = "btn-success";
}
return answ;
}
protected async Task setConf(string lemma)
{
var tempModTerm = await WDCService.VocLemmaFindByKeys(lang, lemma);
if (tempModTerm != null)
{
var done = await WDCService.VocLemmaSetConf(tempModTerm.Lingua, tempModTerm.Lemma, !tempModTerm.IsConfSave);
}
}
protected string defaultPath { get; set; } = "";
}
}