228 lines
6.8 KiB
C#
228 lines
6.8 KiB
C#
using EgwCoreLib.Razor;
|
|
using Microsoft.AspNetCore.SignalR.Protocol;
|
|
|
|
namespace Lux.UI.Components.Compo.Templates
|
|
{
|
|
public partial class TemplateList
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Ricerca libera da parent
|
|
/// </summary>
|
|
[Parameter]
|
|
public string CurrSearchVal { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Callback invocato al select
|
|
/// </summary>
|
|
[Parameter]
|
|
public EventCallback<TemplateModel?> EC_Selected { get; set; }
|
|
|
|
[Parameter]
|
|
public TemplateModel? SelRecord { get; set; } = null;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<TemplateModel> AllRecords = new List<TemplateModel>();
|
|
|
|
private EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS CurrEnvir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
|
|
|
|
private int currPage = 1;
|
|
|
|
private Enums.ItemSourceType CurrSourceType = Enums.ItemSourceType.Jwd;
|
|
|
|
private TemplateModel? EditRecord = null;
|
|
|
|
private bool isLoading = false;
|
|
|
|
private List<TemplateModel> ListFilt = new List<TemplateModel>();
|
|
|
|
private List<TemplateModel> ListRecords = new List<TemplateModel>();
|
|
|
|
private int numRecord = 10;
|
|
private int totalCount = 0;
|
|
|
|
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 Fields
|
|
|
|
#region Private Properties
|
|
|
|
/// <summary>
|
|
/// Servizi di accesso ai dati iniettati dal framework.
|
|
/// </summary>
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private ITemplateService TService { get; set; } = default!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private string CheckSelect(TemplateModel curRec)
|
|
{
|
|
string answ = "";
|
|
if (SelRecord != null)
|
|
{
|
|
answ = curRec.TemplateID == SelRecord.TemplateID ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private void DoAdd()
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
EditRecord = new TemplateModel()
|
|
{
|
|
Name = $"New Template {adesso.Year}",
|
|
Description = $"Nuovo Template {adesso:ddd yyyy.MM.dd HH:mm:ss}",
|
|
Envir = CurrEnvir,
|
|
SourceType = CurrSourceType
|
|
};
|
|
}
|
|
|
|
private async Task DoClone(TemplateModel rec2clone)
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = $"Confermi di voler duplicare interamente il Gruppo Template selezionato?\n" +
|
|
$"Env: {rec2clone.Envir} | {rec2clone.Name}\n " +
|
|
$"{rec2clone.Description}\n " +
|
|
$"Articoli: {rec2clone.NumItems}";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
// clona intero template + tutte le righe...
|
|
rec2clone.Name += " - clone";
|
|
rec2clone.Description += $" - cloned {DateTime.Now:yyyy.MM.dd HH:mm:ss}";
|
|
await TService.CloneAsync(rec2clone);
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
|
|
private void DoClose()
|
|
{
|
|
SelRecord = null;
|
|
EditRecord = null;
|
|
}
|
|
|
|
private async Task DoDelete(TemplateModel curRec)
|
|
{
|
|
mTitle = "Eliminazione";
|
|
mMessage = $"Confermi di voler eliminare il Gruppo Template selezionato?\n" +
|
|
$"Env: {curRec.Envir} | {curRec.Name}\n " +
|
|
$"{curRec.Description}\n " +
|
|
$"Articoli: {curRec.NumItems}";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
// elimina intero template (anche le sue righe)
|
|
await TService.DeleteAsync(curRec);
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
|
|
private async Task DoEdit(TemplateModel curRec)
|
|
{
|
|
SelRecord = null;
|
|
await EC_Selected.InvokeAsync(null);
|
|
EditRecord = curRec;
|
|
}
|
|
|
|
private async Task DoReset()
|
|
{
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
await EC_Selected.InvokeAsync(null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva record ed avanza compilazione
|
|
/// </summary>
|
|
/// <param name="updRec"></param>
|
|
/// <returns></returns>
|
|
private async Task DoSave(TemplateModel updRec)
|
|
{
|
|
// salvo record
|
|
await TService.UpsertAsync(updRec);
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
|
|
private Task DoSelect(TemplateModel curRec)
|
|
{
|
|
SelRecord = curRec;
|
|
return EC_Selected.InvokeAsync(curRec);
|
|
}
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
AllRecords = await TService.GetAllAsync();
|
|
}
|
|
|
|
private void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
private void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
private void UpdateTable()
|
|
{
|
|
//ListFilt.Clear();
|
|
ListFilt = AllRecords;
|
|
if (!string.IsNullOrEmpty(CurrSearchVal))
|
|
{
|
|
ListFilt = AllRecords
|
|
.Where(x => x.Name.Contains(CurrSearchVal, StringComparison.InvariantCultureIgnoreCase) || x.Description.Contains(CurrSearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
totalCount = ListFilt.Count;
|
|
// gestione paginazione
|
|
ListRecords = ListFilt
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |