124 lines
3.5 KiB
C#
124 lines
3.5 KiB
C#
using EgwCoreLib.Lux.Data.DbModel.Admin;
|
|
using EgwCoreLib.Razor;
|
|
|
|
namespace Lux.UI.Components.Pages
|
|
{
|
|
public partial class Vocabulary
|
|
{
|
|
#region Protected Methods
|
|
|
|
protected override Task OnInitializedAsync()
|
|
{
|
|
return ReloadDataAsync();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool addNew = false;
|
|
private VocabolarioModel? currRec = null;
|
|
private List<VocabolarioModel> FiltVocab = new();
|
|
private List<VocabolarioModel> FullVocab = new();
|
|
private bool isLoading = false;
|
|
private string langDef = "IT";
|
|
private List<LinguaModel> ListLingue = new();
|
|
|
|
private string SearchVal = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string btnResetCss => string.IsNullOrEmpty(SearchVal) ? "btn-secondary" : "btn-primary";
|
|
|
|
[Inject]
|
|
private IVocabolarioService VService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void DoAddNew()
|
|
{
|
|
currRec = new();
|
|
}
|
|
|
|
private void DoCancel()
|
|
{
|
|
currRec = null;
|
|
}
|
|
|
|
private async Task DoSave()
|
|
{
|
|
if (currRec != null)
|
|
{
|
|
// genero 1 rec x ogni LangSel
|
|
var listNew = ListLingue.Select(x => new VocabolarioModel()
|
|
{
|
|
Lingua = x.Lingua,
|
|
Lemma = currRec.Lemma,
|
|
Traduzione = currRec.Traduzione
|
|
}).ToList();
|
|
// salvo
|
|
await VService.UpsertManyAsync(listNew);
|
|
}
|
|
currRec = null;
|
|
//rileggo
|
|
await ReloadDataAsync();
|
|
}
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
isLoading = true;
|
|
ListLingue = await VService.ListLingueAsync();
|
|
FullVocab = await VService.GetAllAsync();
|
|
isLoading = false;
|
|
}
|
|
|
|
private void ResetSearch()
|
|
{
|
|
SearchVal = "";
|
|
}
|
|
|
|
private async Task UpdateRec(VocabolarioModel updRec)
|
|
{
|
|
await VService.UpsertAsync(updRec);
|
|
await ReloadDataAsync();
|
|
}
|
|
/// <summary>
|
|
/// Imposto filtro da richiesta child obj
|
|
/// </summary>
|
|
/// <param name="newSearch"></param>
|
|
/// <returns></returns>
|
|
private async Task DoFilt(string newSearch)
|
|
{
|
|
SearchVal = newSearch;
|
|
}
|
|
private async Task DoCloneLang(string origLang)
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = "Sicuro di voler duplicare il vocabolario della LangSel selezionata?\n" +
|
|
$"Sorgente: {origLang}";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
// dovrebbe chiedere nuova LangSel...
|
|
string destLang = "FR";
|
|
// ora duplica...
|
|
await VService.CloneAsync(origLang, destLang);
|
|
await ReloadDataAsync();
|
|
}
|
|
private BootstrapModal Modal = new();
|
|
private string mTitle = "";
|
|
private string mMessage = "";
|
|
private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND;
|
|
private Dictionary<bool, string> modalOpt = new Dictionary<bool, string>();
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |