Files
mapo-core/MP.Prog/Pages/Archive.razor.cs
T
Samuele E. Locatelli 57c41c7a60 MP-PROG
- fix naming DbModels
2025-03-08 10:48:56 +01:00

714 lines
19 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.FileData;
using MP.FileData.DbModels;
using MP.Prog.Data;
using NLog;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MP.Prog.Pages
{
public partial class Archive : ComponentBase, IDisposable
{
#region Public Properties
public bool DeleteDialogOpen { get; set; }
#endregion Public Properties
#region Public Methods
public string checkSelect(int FileId)
{
string answ = "";
if (currRecord != null)
{
try
{
answ = (currRecord.FileId == FileId) ? "table-info" : "";
}
catch
{ }
}
return answ;
}
public void Dispose()
{
MServ.EA_SearchUpdated -= OnSeachUpdated;
MServ.EA_FilterUpdated -= OnFilterUpdated;
}
public async void OnFilterUpdated()
{
await ReloadData();
}
public void OnSeachUpdated()
{
SearchVal = MServ.SearchVal;
StateHasChanged();
}
#endregion Public Methods
#region Protected Fields
protected string _SearchTag;
protected string defTag = "";
protected int totalCount = 0;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected FileArchDataService FDService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected MessageService MServ { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; }
protected string SearchTag
{
get
{
return _SearchTag;
}
set
{
_SearchTag = value;
// se son > 3 char... debounce...
if (string.IsNullOrEmpty(value))
{
_SearchTag = defTag;
}
if (value.Length >= defTag.Length)
{
var pUpd = Task.Run(async () =>
{
TagList = await FDService.TagGetFilt(SearchTag);
});
pUpd.Wait();
}
isLoading = false;
}
}
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Restituisce size calcolata
/// </summary>
/// <param name="origSize"></param>
/// <returns></returns>
protected string CalcSize(long origSize)
{
return MeasureUtils.SizeSuffix(origSize, 1);
}
/// <summary>
/// Elimina record (non approvato) corrente e riattiva precedente
/// </summary>
/// <returns></returns>
protected async Task DeleteRec(FileModel CurrRec)
{
string delMessage = CurrRec.Rev > 0 ? "Sicuro di voler eliminare il record e riattivare la revisione antecedente? Il file potrebbe risultare modificato." : "Sicuro di voler eliminare il record? Non ci sono altre revisioni e quindi sarà definitivamente eliminato.";
if (!await JSRuntime.InvokeAsync<bool>("confirm", delMessage))
return;
// elimino
await FDService.FileDelete(CurrRec);
// verifico eventuali modifiche del SINGOLO
List<FileModel> FileIdList = new List<FileModel>() { CurrRec };
var numCheck = await FDService.UpdateMachineFilesArchive(CurrRec.IdxMacchina, FileIdList, false, false, "", false);
isLoading = true;
currRecord = null;
await ReloadData();
isLoading = false;
}
protected async Task Edit(FileModel selRecord)
{
if (!selRecord.Active)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler confrontare una revisione vecchia/inattiva del programma??"))
return;
}
// rileggo dal DB il record corrente...
ReqRevDx = 0;
currRecord = FDService.FileGetByKey(selRecord.FileId);
}
/// <summary>
/// forza approvazione utente corrente
/// </summary>
/// <returns></returns>
protected async Task FileSetUserApp(FileModel CurrRec)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler approvare il salvataggio automatico della nuova revisione?"))
return;
await FDService.FileSetUserApp(CurrRec, MServ.UserName);
isLoading = true;
await ReloadData();
isLoading = false;
}
/// <summary>
/// Esegue filtraggio sul Path di ricerca
/// </summary>
/// <param name="searchVal"></param>
/// <returns></returns>
protected async Task FilterPath(string searchVal)
{
SelFileName = searchVal;
OnlyActive = false;
currPage = 1;
await ReloadAllData();
isLoading = false;
}
/// <summary>
/// Elimina il filtro x path file
/// </summary>
/// <returns></returns>
protected async Task FilterPathRemove()
{
await FilterPath("");
OnlyActive = true;
}
/// <summary>
/// Imposta filtro x Tags
/// </summary>
/// <param name="searchVal"></param>
/// <returns></returns>
protected async Task FilterTag(string searchVal)
{
SelTag = searchVal;
currPage = 1;
await ReloadData();
isLoading = false;
}
/// <summary>
/// Imposta filtro x utente
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
protected async Task FilterUserName(string userName)
{
SelUserName = userName;
currPage = 1;
//await ReloadAllData();
await Task.Delay(1);
isLoading = false;
}
/// <summary>
/// Resetta filtro x utente
/// </summary>
/// <returns></returns>
protected async Task FilterUserNameRemove()
{
await FilterUserName("");
}
/// <summary>
/// Esegue comparazione tra dati DB e filesystem (modificati entro numDays)
/// </summary>
/// <param name="numDays"></param>
/// <returns></returns>
protected async Task ForceCheck(int numDays)
{
currRecord = null;
ListRecords = null;
// importante altrimenti NON mostra update UI
await Task.Delay(1);
var numCheck = await FDService.UpdateAllArchive(numDays, false, "", false);
await ReloadAllData();
await Task.Delay(1);
await RefreshDisplayLoading();
}
/// <summary>
/// effettua approvazione di ttute le modifiche visualizzate
/// </summary>
/// <returns></returns>
protected async Task MassAppr()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler procedere approvando una nuova revisione di ogni file modificato visualizzato?"))
return;
//verifico che sia cliccato solo modificati...
if (OnlyMod)
{
foreach (var item in ListRecords)
{
await FDService.FileModApprove(item, MServ.UserName);
}
}
// rileggo!
ResetData();
await ResetFilter();
await Task.Delay(1);
await ReloadData();
isLoading = false;
}
protected override async Task OnInitializedAsync()
{
SearchTag = defTag;
MServ.ShowSearch = true;
MServ.PageName = "Archivio File Programmi";
MServ.PageIcon = "fas fa-folder pr-2";
MServ.EA_SearchUpdated += OnSeachUpdated;
MServ.EA_FilterUpdated += OnFilterUpdated;
await ReloadAllData();
isLoading = false;
}
protected async Task RefreshDisplayLoading()
{
await Task.Delay(1);
isLoading = false;
}
protected async Task ReloadAllData()
{
isLoading = true;
MacList = await FDService.ArchMaccGetAll();
SelIdxMacc = "0";
SearchTag = defTag;
TagList = await FDService.TagGetFilt(SearchTag);
await ReloadData();
}
protected async Task ReloadAsync()
{
isLoading = true;
currRecord = null;
ListRecords = null;
await ReloadData();
isLoading = false;
}
protected async Task ReloadData()
{
isLoading = true;
// importante altrimenti NON mostra update UI
await Task.Delay(1);
totalCount = await FDService.FileCountFilt(MServ.File_Filter);
// valutare recupero info + redis + pagiazione EX POST...
ListRecords = await FDService.FileGetFilt(MServ.File_Filter);
await Task.Delay(1);
}
protected void ResetData()
{
FDService.rollBackEdit(currRecord);
currRecord = null;
}
protected async Task ResetFilter()
{
currRecord = null;
ListRecords = null;
currPage = 1;
MServ.File_Filter = SelectData.Init(5, 10);
MServ.SearchVal = "";
SearchTag = defTag;
await ReloadAllData();
isLoading = false;
}
protected void ResetSearchTag()
{
SearchTag = defTag;
}
protected void ResetTag()
{
SelTag = "";
currPage = 1;
}
protected void Select(FileModel selRecord)
{
// applico filtro da selezione
currRecord = selRecord;
}
/// <summary>
/// imposta revisione richiesta
/// </summary>
/// <param name="reqRev"></param>
protected void SelRev(int reqRev)
{
ReqRevDx = reqRev;
}
/// <summary>
/// Imposta pagina corrente
/// </summary>
/// <param name="newNum"></param>
/// <returns></returns>
protected async Task SetNumPage(int newNum)
{
currPage = newNum;
await ReloadData();
isLoading = false;
}
/// <summary>
/// Imposta num record x pagina
/// </summary>
/// <param name="newNum"></param>
/// <returns></returns>
protected async Task SetRecPage(int newNum)
{
numRecord = newNum;
await ReloadData();
isLoading = false;
}
protected string TextReduce(string textOriginal, int maxChar)
{
string answ = textOriginal;
if (answ.Length > maxChar)
{
answ = $"...{textOriginal.Substring(answ.Length - maxChar)}";
}
return answ;
}
protected async Task UpdateData()
{
currRecord = null;
ListRecords = null;
FDService.ResetController();
await ReloadData();
await Task.Delay(1);
isLoading = false;
}
#endregion Protected Methods
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private FileModel currRecord = null;
private List<FileModel> ListRecords;
private List<ArchMaccModel> MacList;
/// <summary>
/// Revisione richiesta a dx
/// </summary>
private int ReqRevDx = 0;
private List<TagModel> TagList;
#endregion Private Fields
#region Private Properties
private int currPage
{
get
{
return MServ.File_Filter.PageNum;
}
set
{
MServ.File_Filter.PageNum = value;
}
}
private bool isLoading { get; set; } = false;
private string mainCol
{
get => currRecord == null || currRecord.Rev == 0 ? "col-12" : "col-9";
}
private int numRecord
{
get
{
return MServ.File_Filter.PageSize;
}
set
{
MServ.File_Filter.PageSize = value;
}
}
private bool OnlyActive
{
get
{
bool answ = false;
if (MServ.File_Filter != null)
{
answ = MServ.File_Filter.OnlyActive;
}
return answ;
}
set
{
if (!MServ.File_Filter.OnlyActive.Equals(value))
{
MServ.File_Filter.OnlyActive = value;
var pUpd = Task.Run(async () =>
{
await ReloadAsync();
});
pUpd.Wait();
}
}
}
private bool OnlyMod
{
get
{
bool answ = false;
if (MServ.File_Filter != null)
{
answ = MServ.File_Filter.OnlyMod;
}
return answ;
}
set
{
if (!MServ.File_Filter.OnlyMod.Equals(value))
{
MServ.File_Filter.OnlyMod = value;
var pUpd = Task.Run(async () =>
{
await ReloadAsync();
});
pUpd.Wait();
}
}
}
private bool OnlyNoTag
{
get
{
bool answ = false;
if (MServ.File_Filter != null)
{
answ = MServ.File_Filter.OnlyNoTag;
}
return answ;
}
set
{
if (!MServ.File_Filter.OnlyNoTag.Equals(value))
{
MServ.File_Filter.OnlyNoTag = value;
var pUpd = Task.Run(async () =>
{
await ReloadAsync();
});
pUpd.Wait();
}
}
}
private string SearchVal
{
get
{
string answ = "";
if (MServ.File_Filter != null)
{
answ = MServ.File_Filter.SearchVal;
}
return answ;
}
set
{
if (!MServ.File_Filter.SearchVal.Equals(value))
{
MServ.File_Filter.SearchVal = value;
var pUpd = Task.Run(async () =>
{
await ReloadAsync();
});
pUpd.Wait();
}
}
}
private string SelFileName
{
get
{
string answ = "";
if (MServ.File_Filter != null)
{
answ = MServ.File_Filter.FileName;
}
return answ;
}
set
{
if (!MServ.File_Filter.FileName.Equals(value))
{
MServ.File_Filter.FileName = value;
var pUpd = Task.Run(async () =>
{
await ReloadAsync();
});
pUpd.Wait();
}
}
}
private string SelIdxMacc
{
get
{
string answ = "";
if (MServ.File_Filter != null)
{
answ = MServ.File_Filter.IdxMacchina;
}
return answ;
}
set
{
if (!MServ.File_Filter.IdxMacchina.Equals(value))
{
MServ.File_Filter.IdxMacchina = value;
var pUpd = Task.Run(async () =>
{
await ReloadAsync();
});
pUpd.Wait();
}
}
}
private string SelTag
{
get
{
string answ = "";
if (MServ.File_Filter != null)
{
answ = MServ.File_Filter.Tag;
}
return answ;
}
set
{
if (!MServ.File_Filter.Tag.Equals(value))
{
MServ.File_Filter.Tag = value;
var pUpd = Task.Run(async () =>
{
await ReloadAsync();
});
pUpd.Wait();
}
}
}
private string SelUserName
{
get
{
string answ = "";
if (MServ.File_Filter != null)
{
answ = MServ.File_Filter.UserName;
}
return answ;
}
set
{
if (!MServ.File_Filter.UserName.Equals(value))
{
MServ.File_Filter.UserName = value;
var pUpd = Task.Run(async () =>
{
await ReloadAsync();
});
pUpd.Wait();
}
}
}
#endregion Private Properties
#region Private Methods
private string cssActive(bool active)
{
string answ = active ? "text-dark" : "text-secondary textStriked";
return answ;
}
private string cssStatusByCod(FileState currStatus)
{
string answ = "badge";
switch (currStatus)
{
case FileState.Changed:
answ += " text-bg-warning";
break;
case FileState.Missing:
answ += " text-bg-danger";
break;
case FileState.Ok:
answ += " text-bg-success";
break;
case FileState.ND:
default:
answ += " text-bg-light";
break;
}
return answ;
}
private async Task OnDialogClose(bool accepted)
{
DeleteDialogOpen = false;
currPage = 1;
await ReloadAsync();
//StateHasChanged();
}
private void OpenDialog()
{
DeleteDialogOpen = true;
StateHasChanged();
}
#endregion Private Methods
}
}