Files
lux/Lux.UI/Components/Compo/Admin/VocabMan.razor.cs
T
Samuele Locatelli da814bc858 Fix addmissing lemma
2026-06-08 17:35:44 +02:00

153 lines
3.9 KiB
C#

using EgwCoreLib.Lux.Data.DbModel.Admin;
namespace Lux.UI.Components.Compo.Admin
{
public partial class VocabMan
{
#region Public Properties
[Parameter]
public List<VocabolarioModel> AllRecord { get; set; } = null!;
[Parameter]
public EventCallback<string> EC_ReqClone { get; set; }
[Parameter]
public EventCallback<string> EC_ReqFilt { get; set; }
[Parameter]
public EventCallback<string> EC_ReqFixMissing { get; set; }
[Parameter]
public EventCallback<VocabolarioModel> EC_Updated { get; set; }
[Parameter]
public List<LinguaModel> ListLingue { get; set; } = null!;
[Parameter]
public string SearchVal { get; set; } = string.Empty;
[Parameter]
public string SelLingua { get; set; } = "";
#endregion Public Properties
#region Protected Methods
protected override void OnParametersSet()
{
if (AllRecord != null && AllRecord.Count > 0)
{
isLoading = true;
UpdateTable();
}
}
#endregion Protected Methods
#region Private Fields
private int currPage = 1;
private VocabolarioModel? currRec = null;
private VocabolarioModel? editRec = null;
private bool isLoading = false;
private List<VocabolarioModel> ListPaged = new();
private int numRecord = 10;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
private void DoCancel()
{
currRec = null;
editRec = null;
}
private async Task DoClone()
{
if (!string.IsNullOrEmpty(SelLingua))
await EC_ReqClone.InvokeAsync(SelLingua);
}
private void DoEdit(VocabolarioModel selRec)
{
editRec = editRec == null || editRec.Lemma != selRec.Lemma ? selRec : null;
}
private async Task DoFixMissing()
{
if (!string.IsNullOrEmpty(SelLingua))
{
await EC_ReqFixMissing.InvokeAsync(SelLingua);
}
}
private async Task DoSave()
{
await EC_Updated.InvokeAsync(editRec);
editRec = null;
}
private async Task DoSelect(VocabolarioModel selRec)
{
currRec = selRec;
await Task.Delay(1);
await EC_ReqFilt.InvokeAsync(selRec.Lemma);
}
private void FiltLingua()
{
UpdateTable();
}
private void SaveNumRec(int newNum)
{
numRecord = newNum;
currPage = 1;
UpdateTable();
}
private void SavePage(int newNum)
{
currPage = newNum;
UpdateTable();
}
/// <summary>
/// Filtro e paginazione
/// </summary>
private void UpdateTable()
{
ListPaged.Clear();
if (!string.IsNullOrEmpty(SelLingua))
{
var rawList = AllRecord.Where(x => x.Lingua == SelLingua).ToList();
if (!string.IsNullOrEmpty(SearchVal))
{
rawList = rawList.Where(x =>
x.Lemma.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
x.Traduzione.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)
).ToList();
}
totalCount = rawList.Count;
// fix paginazione
ListPaged = rawList
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
isLoading = false;
}
#endregion Private Methods
}
}