310 lines
8.0 KiB
C#
310 lines
8.0 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.MONO.Core;
|
|
using MP.MONO.Data;
|
|
using MP.MONO.Data.DbModels;
|
|
|
|
namespace MP.MONO.UI.Components
|
|
{
|
|
public partial class MaintTaskPending
|
|
{
|
|
#region Public Fields
|
|
|
|
public string dir = "";
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Abilita modalità compatta (solo x home)
|
|
/// </summary>
|
|
[Parameter]
|
|
public bool compMode { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Gestione evento x cambio modalità (pending/schedulati
|
|
/// </summary>
|
|
[Parameter]
|
|
public EventCallback<bool> reqChangeMode { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
protected string bodyCss
|
|
{
|
|
get => compMode ? "p-1" : "";
|
|
}
|
|
|
|
protected string currMode
|
|
{
|
|
get => doSetup ? "Pending" : "Scheduled";
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
//private readonly IWebHostEnvironment _HostEnvironment;
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
//dir = _HostEnvironment.WebRootPath;
|
|
await ReloadData();
|
|
MaintPendingRefreshVetoMin = Configuration.GetValue<int>("OptPar:MaintPendingRefreshVetoMin");
|
|
PercLim = Configuration.GetValue<int>("OptPar:MaintLimitPerc");
|
|
MMDataService.maintPipe.EA_NewMessage += MaintPipe_EA_NewMessage;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private int _MaxRecord = 1000;
|
|
|
|
private bool doSetup = true;
|
|
private DateTime LastUpdate = DateTime.Now.AddHours(-12);
|
|
|
|
private List<PendingMaintModel>? ListRecords = null;
|
|
|
|
// FARE!!! filtro macchina
|
|
private int MachineId = 1;
|
|
|
|
private int MaintPendingRefreshVetoMin = 10;
|
|
|
|
/// <summary>
|
|
/// Valore limite (in %) per permettere di chiudere un intervento
|
|
/// </summary>
|
|
private int PercLim = 50;
|
|
|
|
/// <summary>
|
|
/// Valore limite (in %) per indicare come rosso una scadenza
|
|
/// </summary>
|
|
private int redLim = 10;
|
|
|
|
private List<PendingMaintModel>? SearchRecords = null;
|
|
|
|
/// <summary>
|
|
/// Valore limite (in %) per indicare come giallo una scadenza
|
|
/// </summary>
|
|
private int yelLim = 20;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _currPage { get; set; } = 1;
|
|
|
|
private int _limitDayPeriod { get; set; } = 7;
|
|
|
|
private int _numRecord { get; set; } = 10;
|
|
|
|
private int currPage
|
|
{
|
|
get => _currPage;
|
|
set
|
|
{
|
|
if (_currPage != value)
|
|
{
|
|
_currPage = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private int currSMTaskId { get; set; } = 0;
|
|
|
|
private DateTime execDate { get; set; } = TimeUtils.DateRounded(DateTime.Now, 5, true);
|
|
|
|
private string execName { get; set; } = "";
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int LimitDayPeriod
|
|
{
|
|
get => _limitDayPeriod;
|
|
set
|
|
{
|
|
if (_limitDayPeriod != value)
|
|
{
|
|
_limitDayPeriod = value;
|
|
currPage = 1;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private int MaxRecord
|
|
{
|
|
get
|
|
{
|
|
return _MaxRecord;
|
|
}
|
|
set
|
|
{
|
|
if (_MaxRecord != value)
|
|
{
|
|
_MaxRecord = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private int maxRemainHour
|
|
{
|
|
get => LimitDayPeriod * 24;
|
|
}
|
|
|
|
private string modalShow
|
|
{
|
|
get => showTaskConf ? "show" : "hide";
|
|
}
|
|
|
|
private int numRecord
|
|
{
|
|
get => _numRecord;
|
|
set
|
|
{
|
|
if (_numRecord != value)
|
|
{
|
|
_numRecord = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool showTaskConf { get; set; } = false;
|
|
|
|
private int totalCount
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (SearchRecords != null)
|
|
{
|
|
answ = SearchRecords.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Solleva evento cambio modo (Pending/Scheduled)
|
|
/// </summary>
|
|
private void ChangeMode()
|
|
{
|
|
reqChangeMode.InvokeAsync(true);
|
|
}
|
|
|
|
private async Task ConfirmDone()
|
|
{
|
|
// se ho dataora ed esecutore...
|
|
if (!string.IsNullOrEmpty(execName) && currSMTaskId > 0)
|
|
{
|
|
// salvo!
|
|
bool fatto = await MMDataService.SchedMaintTaskSetDone(MachineId, currSMTaskId, execDate, execName);
|
|
|
|
// rigenero!
|
|
await RegenTask();
|
|
|
|
// nascondo conferma
|
|
ShowConfirm(0);
|
|
}
|
|
}
|
|
|
|
#if false
|
|
string wwwroot = "";
|
|
string file = "";
|
|
#endif
|
|
|
|
private void ForceReload(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
}
|
|
|
|
private void ForceReloadPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
}
|
|
|
|
private async void MaintPipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
// faccio un update al massimo ogni tot minuti (da config)
|
|
if (DateTime.Now.Subtract(LastUpdate).TotalMinutes > MaintPendingRefreshVetoMin)
|
|
{
|
|
LastUpdate = DateTime.Now;
|
|
await ReloadData();
|
|
await InvokeAsync(() =>
|
|
{
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
private string pathFinder(int id)
|
|
{
|
|
//wwwroot = _environment.WebRootPath;
|
|
#if false
|
|
file = Path.Combine(wwwroot, id + ".pdf");
|
|
#endif
|
|
string answ = "";
|
|
string path = "Docs/Maint/" + id + ".pdf";
|
|
if (File.Exists("wwwroot/" + path))
|
|
{
|
|
answ = path;
|
|
}
|
|
else
|
|
{
|
|
path = "Docs/Maint/empty.pdf";
|
|
answ = path;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private async Task RegenTask()
|
|
{
|
|
await MMDataService.SchedMaintTaskCreateMissing(MachineId);
|
|
await ReloadData();
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
ListRecords = null;
|
|
await Task.Delay(1);
|
|
SearchRecords = await MMDataService.SchedMaintTaskGetFilt(MachineId, maxRemainHour, 0, MaxRecord);
|
|
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
|
await Task.Delay(1);
|
|
await Task.Delay(1);
|
|
isLoading = false;
|
|
}
|
|
|
|
private void ShowConfirm(int SMTaskId)
|
|
{
|
|
showTaskConf = !showTaskConf;
|
|
currSMTaskId = SMTaskId;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#if false
|
|
private bool showParams = false;
|
|
|
|
private void toggleShowParams()
|
|
{
|
|
showParams = !showParams;
|
|
}
|
|
#endif
|
|
}
|
|
} |