b1afa82a91
- GpwDataSrvice - MessageService - ogni dipendenza (aggiunti using, in _import non basta...)
269 lines
7.5 KiB
C#
269 lines
7.5 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.DTO;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace GPW.CORE.WRKLOG.Components.Pages
|
|
{
|
|
/// <summary>
|
|
/// Gestione pagina principale del planner
|
|
///
|
|
/// modale: vedere qui: https://gist.github.com/conficient/ba98d1662c659e170ec16650acea05c8
|
|
/// </summary>
|
|
//[Authorize(Roles = "SuperAdmin, Admin")]
|
|
public partial class ActHistory : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
public int MaxChar { get; set; } = 30;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
UITimer?.Dispose();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected DateTime lastRefresh = DateTime.Now;
|
|
|
|
protected int numRecLast = 100;
|
|
|
|
/// <summary>
|
|
/// Timer per refresh dati
|
|
///
|
|
/// https://stackoverflow.com/questions/63060065/blazor-timer-call-async-api-task-to-update-ui https://www.janduniec.blog/index.php/100/timers-in-blazor/
|
|
/// </summary>
|
|
protected System.Timers.Timer UITimer = new System.Timers.Timer();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected string actionCss
|
|
{
|
|
get => isLoading ? "disabled" : "";
|
|
}
|
|
|
|
[Inject]
|
|
protected MessageService AppMServ { get; set; } = null!;
|
|
|
|
protected RegAttivitaModel? clonedRA
|
|
{
|
|
get
|
|
{
|
|
return AppMServ.clonedRA;
|
|
}
|
|
set
|
|
{
|
|
AppMServ.clonedRA = value;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected GpwDataService DataService { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Dipendente corrente
|
|
/// </summary>
|
|
protected int IdxDipendente
|
|
{
|
|
get
|
|
{
|
|
return AppMServ.IdxDipendente;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected List<AnagFasiModel> ListFasi { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string getItemCss(RegAttivitaModel itemRecord)
|
|
{
|
|
string answ = "";
|
|
if (currRecord != null)
|
|
{
|
|
if (itemRecord.Equals(currRecord))
|
|
{
|
|
answ = "bg-info bg-opacity-25";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ListRecords = null;
|
|
await InvokeAsync(StateHasChanged);
|
|
await Task.Delay(1);
|
|
|
|
await TryReload();
|
|
// avvio un timer infinito x refresh pagina COMUNQUE ogni 60 sec anche non succedesse nulla...
|
|
UITimer = new System.Timers.Timer
|
|
{
|
|
Interval = 1000 * 60,
|
|
AutoReset = true,
|
|
Enabled = true
|
|
};
|
|
UITimer.Elapsed += async (s, ea) => await TryReload();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indico item selezionato
|
|
/// </summary>
|
|
protected async void ReportDeleted()
|
|
{
|
|
isLoading = true;
|
|
currRecord = null;
|
|
await InvokeAsync(ReloadData);
|
|
await Task.Delay(50);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indico item selezionato
|
|
/// </summary>
|
|
protected void ReportSelect(RegAttivitaModel selRecord)
|
|
{
|
|
//selPeriod = false;
|
|
// recupero attivita selezionata in curr record
|
|
currRecord = selRecord;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indico item selezionato
|
|
/// </summary>
|
|
protected async void ReportSelected(RegAttivitaModel selRecord)
|
|
{
|
|
currRecord = selRecord;
|
|
await Task.Delay(1);
|
|
//await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected void ResetClone()
|
|
{
|
|
clonedRA = null;
|
|
}
|
|
|
|
protected async Task SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gestione refresh condizionale
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task TryReload()
|
|
{
|
|
await Task.Delay(1);
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private RegAttivitaModel? currRecord = null;
|
|
private List<RegAttivitaModel>? ListRecords = null;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage { get; set; } = 1;
|
|
private bool isLoading { get; set; } = false;
|
|
private int numRecord { get; set; } = 5;
|
|
|
|
private double periodoClonato
|
|
{
|
|
get
|
|
{
|
|
double answ = 8;
|
|
// se ho record clonato --> uso quello
|
|
if (clonedRA != null)
|
|
{
|
|
answ = clonedRA.Durata.TotalHours;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private string ConvOre(double oreComm)
|
|
{
|
|
TimeSpan tSpan = TimeSpan.FromHours(oreComm);
|
|
return $"{tSpan.Hours}h {tSpan.Minutes}'";
|
|
}
|
|
|
|
private double oreLav(DailyDataDTO DayDTO)
|
|
{
|
|
double answ = 0;
|
|
if (DayDTO != null && DayDTO.TimbrExpl != null && DayDTO.TimbrExpl.HLav != null)
|
|
{
|
|
answ = (double)DayDTO.TimbrExpl.HLav;
|
|
if (DayDTO.DtRif == DateTime.Today)
|
|
{
|
|
if (DayDTO.ListTimbr != null)
|
|
{
|
|
// aggiungo ultima timb fino ad adesso...
|
|
var lastIn = DayDTO.ListTimbr.Where(x => x.Entrata == true).OrderByDescending(x => x.DataOra).FirstOrDefault();
|
|
var lastOut = DayDTO.ListTimbr.Where(x => x.Entrata == false).OrderByDescending(x => x.DataOra).FirstOrDefault();
|
|
// se MANCA timb uscita finale...
|
|
if (lastIn != null)
|
|
{
|
|
if (lastOut == null || lastOut.DataOra < lastIn.DataOra)
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
answ += adesso.Subtract(lastIn.DataOra).TotalHours;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
UITimer.Stop();
|
|
var searcRecords = await DataService.UserLastRec(IdxDipendente, numRecLast);
|
|
ListRecords = searcRecords
|
|
.Skip((currPage - 1) * numRecord)
|
|
.Take(numRecord)
|
|
.ToList();
|
|
lastRefresh = DateTime.Now;
|
|
UITimer.Start();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |