MP.TaskMan +MP. STATS
- eliminazione riferimenti codice escluso da compilazione - pulizia codice da componenti non impiegati NON ancora 100% ok pulizia
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EgwCoreLib.Razor" Version="1.5.2409.2607" />
|
||||
<PackageReference Include="EgwCoreLib.Utils" Version="1.5.2409.2607" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.33" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.33" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9">
|
||||
@@ -35,4 +37,10 @@
|
||||
<ProjectReference Include="..\Egw.Core\Egw.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="TaskList.razor">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
<div class="row">
|
||||
<div class="@mainCss">
|
||||
<div class="card shadow">
|
||||
<div class="card-header table-primary p-1">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="px-2">
|
||||
<b class="fs-4">TaskList</b>
|
||||
</div>
|
||||
<div class="px-2">
|
||||
<div class="input-group">
|
||||
@if (TypeSel != MP.TaskMan.Objects.Enums.Task2ExeType.ND)
|
||||
{
|
||||
@if (currRecord == null)
|
||||
{
|
||||
<button class="btn btn-success" @onclick="addNew" title="Add New"><i class="fas fa-plus"></i> Add New</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-secondary" @onclick="doCancel" title="Cancel"><i class="fas fa-undo"></i> Cancel</button>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-outline-secondary">Sel →</button>
|
||||
}
|
||||
<select class="form-select" @bind="@TypeSel">
|
||||
@foreach (var option in Enum.GetValues(typeof(MP.TaskMan.Objects.Enums.Task2ExeType)))
|
||||
{
|
||||
<option value="@option">
|
||||
@option
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<TaskEdit CurrRecord="@currRecord" EC_update="forceUpdate"></TaskEdit>
|
||||
</div>
|
||||
<div class="card-body py-0 px-1">
|
||||
@if (isLoading)
|
||||
{
|
||||
<ProgressDisplay DisplaySize="ProgressDisplay.ModalSize.Medium" ExpTimeMSec="@expTimeMsec" CurrVal="@currVal" NextVal="@nextVal" MaxVal="@MaxVal" Title="Task Processing" RefreshInterval="200"></ProgressDisplay>
|
||||
<LoadingData Title="Elaborazione..." DisplayMode="LoadingData.SpinMode.BounceLine" DisplaySize="LoadingData.CtrlSize.Large"></LoadingData>
|
||||
}
|
||||
else if (ListRecords == null)
|
||||
{
|
||||
<LoadingData></LoadingData>
|
||||
}
|
||||
else if (totalCount == 0)
|
||||
{
|
||||
<div class="alert alert-warning text-center display-4">Nessun record trovato</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<button class="btn btn-sm btn-info" @onclick="doReset" title="Reset"><i class="fas fa-sync"></i></button>
|
||||
</th>
|
||||
<th>Ord</th>
|
||||
<th>Task</th>
|
||||
<th>Tipo</th>
|
||||
@if (detRecord == null)
|
||||
{
|
||||
<th>Command</th>
|
||||
}
|
||||
<th>Sched.</th>
|
||||
@if (detRecord == null)
|
||||
{
|
||||
<th class="text-end">Last</th>
|
||||
<th class="text-end">Next</th>
|
||||
<th class="text-end">Result</th>
|
||||
<th>
|
||||
<button class="btn btn-sm btn-danger me-1" @onclick="forceAll" title="Force All"><i class="fas fa-play"></i></button>
|
||||
</th>
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var record in ListRecords)
|
||||
{
|
||||
<tr class="@checkSelect(@record.TaskId)">
|
||||
<td class="text-nowrap">
|
||||
<button class="btn btn-sm btn-info" @onclick="()=>doSelect(record)" title="Select"><i class="fas fa-search"></i></button>
|
||||
@if (detRecord == null)
|
||||
{
|
||||
@if (currRecord == null)
|
||||
{
|
||||
<button class="btn btn-sm btn-primary ms-1" @onclick="()=>doEdit(record)" title="Edit"><i class="fas fa-pencil-alt"></i></button>
|
||||
<button class="btn btn-sm btn-success" @onclick="()=>doClone(record)" title="Clona"><i class="fas fa-magic"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-secondary ms-1" @onclick="()=>doCancel()" title="Cancel"><i class="fas fa-undo"></i></button>
|
||||
}
|
||||
}
|
||||
</td>
|
||||
<td class="text-nowrap">
|
||||
@if (detRecord == null)
|
||||
{
|
||||
@if (record.Ordinal == minOrdinal)
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-secondary mx-1" disabled title="Cannot Move"><i class="fas fa-caret-up"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-primary mx-1" @onclick="()=>doMove(record, true)" title="Move Up"><i class="fas fa-caret-up"></i></button>
|
||||
}
|
||||
}
|
||||
@record.Ordinal
|
||||
@if (detRecord == null)
|
||||
{
|
||||
@if (record.Ordinal == maxOrdinal)
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-secondary mx-1" disabled title="Cannot Move"><i class="fas fa-caret-down"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-primary mx-1" @onclick="()=>doMove(record, false)" title="Move Down"><i class="fas fa-caret-down"></i></button>
|
||||
}
|
||||
}
|
||||
</td>
|
||||
<td class="text-nowrap">
|
||||
<div>@record.Name</div>
|
||||
<div class="small text-truncate">@record.Descript</div>
|
||||
</td>
|
||||
<td>
|
||||
@record.TType
|
||||
</td>
|
||||
@if (detRecord == null)
|
||||
{
|
||||
<td class="small text-truncate text-break">
|
||||
<div title="@record.Command">@TextReduce(record.Command, 32)</div>
|
||||
<div class="small text-break" title="@record.Args">@TextReduce(record.Args, 40)</div>
|
||||
</td>
|
||||
}
|
||||
<td>@record.Freq × @record.Cad</td>
|
||||
@if (detRecord == null)
|
||||
{
|
||||
<td class="text-end text-nowrap">
|
||||
<div>@($"{record.DtLastExec:yyyy-MM-dd}")</div>
|
||||
<div class="small">@($"{record.DtLastExec:ddd HH:mm:ss}")</div>
|
||||
</td>
|
||||
<td class="text-end text-nowrap">
|
||||
<div>@($"{record.DtNextExec:yyyy-MM-dd}")</div>
|
||||
<div class="small">@($"{record.DtNextExec:ddd HH:mm:ss}")</div>
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<b>@($"{record.LastDuration:N3}")</b> <sub>sec</sub> <button class="btn btn-sm @btnCss(record)" @onclick="() => ToggleDetail(record)" title="Ultima esecuzione"><i class="far @iconCss(record)"></i></button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-sm @btnRunCss(record.DtNextExec) me-1" @onclick="()=>doRun(record)" title="Run Now"><i class="fas fa-play"></i></button>
|
||||
</td>
|
||||
}
|
||||
</tr>
|
||||
@if (DetailTaskId != null && DetailTaskId.TaskId == record.TaskId)
|
||||
{
|
||||
<tr>
|
||||
<td colspan="10">
|
||||
<div class="d-flex justify-content-end">
|
||||
<div class="p-1 small alert @alCss(record)">
|
||||
<pre>@record.LastResult</pre>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="card-footer py-1">
|
||||
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" exportEnabled="false" exportRequested="ExportCsv" fileName="@fileName" totalCount="totalCount" showLoading="isLoading" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@if (detRecord != null && !isLoading)
|
||||
{
|
||||
<div class="col-6">
|
||||
<TaskExeList CurrRecord="@detRecord"></TaskExeList>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,363 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MP.TaskMan.Models;
|
||||
using MP.TaskMan.Services;
|
||||
using static MP.TaskMan.Objects.Enums;
|
||||
|
||||
namespace MP.TaskMan
|
||||
{
|
||||
public partial class TaskList : ComponentBase
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public string checkSelect(int TaskId)
|
||||
{
|
||||
string answ = "";
|
||||
if (currRecord != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
answ = (currRecord.TaskId == TaskId) ? "table-info" : "";
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
else if (detRecord != null)
|
||||
{
|
||||
answ = (detRecord.TaskId == TaskId) ? "table-info" : "";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected string fileName = "TaskList.csv";
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
[Inject]
|
||||
protected IJSRuntime JSRuntime { get; set; } = null!;
|
||||
|
||||
protected string mainCss
|
||||
{
|
||||
get => detRecord == null ? "col-12" : "col-6";
|
||||
}
|
||||
|
||||
protected int maxOrdinal { get; set; } = 999;
|
||||
protected int minOrdinal { get; set; } = 0;
|
||||
protected int totalCount { get; set; } = 0;
|
||||
|
||||
[Inject]
|
||||
protected TaskService TService { get; set; } = null!;
|
||||
|
||||
protected Task2ExeType TypeSel
|
||||
{
|
||||
get => typeSel;
|
||||
set
|
||||
{
|
||||
if (typeSel != value)
|
||||
{
|
||||
typeSel = value;
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
await ReloadData();
|
||||
});
|
||||
pUpd.Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected async Task addNew()
|
||||
{
|
||||
currRecord = new TaskListModel()
|
||||
{
|
||||
Name = "Nuovo Task",
|
||||
TType = TypeSel,
|
||||
Descript = "Descrizione Task",
|
||||
DtLastExec = DateTime.Today,
|
||||
DtNextExec = DateTime.Today.AddDays(1)
|
||||
};
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gestione display avanzamento step
|
||||
/// </summary>
|
||||
/// <param name="currStep"></param>
|
||||
protected async Task advStep(int currStep)
|
||||
{
|
||||
currVal = currStep;
|
||||
nextVal = currVal + 1;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
protected string alCss(TaskListModel TaskRec)
|
||||
{
|
||||
return TaskRec.LastIsError ? "alert-danger" : "alert-success";
|
||||
}
|
||||
|
||||
protected string btnCss(TaskListModel TaskRec)
|
||||
{
|
||||
string answ = DetailTaskId != null && DetailTaskId.TaskId == TaskRec.TaskId ? "btn-" : "btn-outline-";
|
||||
answ += TaskRec.LastIsError ? "danger" : "success";
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected async Task doCancel()
|
||||
{
|
||||
currRecord = null;
|
||||
detRecord = null;
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task doClone(TaskListModel selRec)
|
||||
{
|
||||
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler duplicare il record selezionato?"))
|
||||
return;
|
||||
currRecord = new TaskListModel()
|
||||
{
|
||||
Args = selRec.Args,
|
||||
Name = $"Copia di {selRec.Name}",
|
||||
Cad = selRec.Cad,
|
||||
Command = selRec.Command,
|
||||
Descript = $"Copia di {selRec.Descript}",
|
||||
DtNextExec = DateTime.Today.AddDays(1),
|
||||
DtLastExec = DateTime.Today.AddYears(-10),
|
||||
Freq = selRec.Freq,
|
||||
LastDuration = 0,
|
||||
LastIsError = false,
|
||||
LastResult = "",
|
||||
TType = selRec.TType,
|
||||
Ordinal = SearchRecords.Count + 1,
|
||||
};
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task doEdit(TaskListModel selRec)
|
||||
{
|
||||
currRecord = selRec;
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task doMove(TaskListModel currRec, bool goUp)
|
||||
{
|
||||
await TService.TaskListMove(currRec, goUp);
|
||||
detRecord = null;
|
||||
currRecord = null;
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task doReset()
|
||||
{
|
||||
detRecord = null;
|
||||
currRecord = null;
|
||||
await TService.FlushCache();
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task doRun(TaskListModel selRec)
|
||||
{
|
||||
// SE non è ancora scaduto chiedo conferma
|
||||
if (selRec.DtNextExec > DateTime.Now)
|
||||
{
|
||||
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi esecuzione forzata task non scaduto?{Environment.NewLine}[{selRec.TaskId}]: {selRec.Name} - {selRec.Descript}{Environment.NewLine}Prossima schedulazione: {selRec.DtNextExec:yyyy-MM-dd HH:mm:ss}"))
|
||||
return;
|
||||
}
|
||||
|
||||
// imposto tempo atteso esecuzione da ultimo...
|
||||
isLoading = true;
|
||||
MaxVal = 4;
|
||||
int currStep = 0;
|
||||
await advStep(currStep);
|
||||
expTimeMsec = (int)(1000 * selRec.LastDuration) / 4;
|
||||
detRecord = null;
|
||||
await advStep(currStep++);
|
||||
await Task.Delay(100);
|
||||
await advStep(currStep++);
|
||||
// chiama esecuzione task
|
||||
var result = await TService.ExecuteTask(selRec, false);
|
||||
await advStep(currStep++);
|
||||
isLoading = false;
|
||||
await Task.Delay(100);
|
||||
await advStep(currStep++);
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task doSelect(TaskListModel selRec)
|
||||
{
|
||||
detRecord = null;
|
||||
currRecord = null;
|
||||
DetailTaskId = null;
|
||||
isLoading = true;
|
||||
detRecord = selRec;
|
||||
await ReloadData();
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
protected async Task forceAll()
|
||||
{
|
||||
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi esecuzione forzata di tutti i task?"))
|
||||
return;
|
||||
|
||||
isLoading = true;
|
||||
detRecord = null;
|
||||
await Task.Delay(100);
|
||||
foreach (var taskRec in SearchRecords)
|
||||
{
|
||||
var result = await TService.ExecuteTask(taskRec, false);
|
||||
}
|
||||
isLoading = false;
|
||||
await Task.Delay(100);
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task ForceReload(int newNum)
|
||||
{
|
||||
numRecord = newNum;
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task ForceReloadPage(int newNum)
|
||||
{
|
||||
currPage = newNum;
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task forceUpdate(bool doForce)
|
||||
{
|
||||
currRecord = null;
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected string iconCss(TaskListModel TaskRec)
|
||||
{
|
||||
return TaskRec.LastIsError ? "fa-thumbs-down" : "fa-thumbs-up";
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
isLoading = true;
|
||||
MaxVal = 2;
|
||||
clearFile();
|
||||
await advStep(1);
|
||||
numRecord = 10;
|
||||
await ReloadData();
|
||||
await advStep(2);
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
protected void ResetData()
|
||||
{
|
||||
clearFile();
|
||||
TService.rollBackEdit(currRecord);
|
||||
currRecord = null;
|
||||
}
|
||||
|
||||
protected double righDiv(double num, double den)
|
||||
{
|
||||
if (den == 0)
|
||||
{
|
||||
den = 1;
|
||||
}
|
||||
double answ = num / den;
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected string TextReduce(string textOriginal, int maxChar)
|
||||
{
|
||||
string answ = textOriginal;
|
||||
if (answ.Length > maxChar)
|
||||
{
|
||||
answ = $"{textOriginal.Substring(0, maxChar / 2)} ... {textOriginal.Substring(answ.Length - maxChar / 2)}";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected void ToggleDetail(TaskListModel TaskRec)
|
||||
{
|
||||
if (DetailTaskId == null)
|
||||
{
|
||||
DetailTaskId = TaskRec;
|
||||
}
|
||||
else
|
||||
{
|
||||
DetailTaskId = (DetailTaskId.TaskId == TaskRec.TaskId) ? null : TaskRec;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private double currVal = 0;
|
||||
private TaskListModel? DetailTaskId = null;
|
||||
private List<TaskListModel> ListRecords = new List<TaskListModel>();
|
||||
private int MaxVal = 10;
|
||||
private double nextVal = 0;
|
||||
private List<TaskListModel> SearchRecords = new List<TaskListModel>();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private int currPage { get; set; } = 1;
|
||||
private TaskListModel? currRecord { get; set; } = null;
|
||||
private TaskListModel? detRecord { get; set; } = null;
|
||||
private int expTimeMsec { get; set; } = 30000;
|
||||
|
||||
private string fullPath
|
||||
{
|
||||
get => $"{Directory.GetCurrentDirectory()}\\temp\\{fileName}";
|
||||
}
|
||||
|
||||
private bool isLoading { get; set; } = false;
|
||||
private int numRecord { get; set; } = 10;
|
||||
private string SearchVal { get; set; } = "";
|
||||
private Task2ExeType typeSel { get; set; } = Task2ExeType.ND;
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string btnRunCss(DateTime dtNextExe)
|
||||
{
|
||||
DateTime adesso = DateTime.Now;
|
||||
string answ = dtNextExe < adesso ? "btn-success" : "btn-warning";
|
||||
return answ;
|
||||
}
|
||||
|
||||
private async void clearFile()
|
||||
{
|
||||
await Task.Run(() => File.Delete(fullPath));
|
||||
}
|
||||
|
||||
private async Task ExportCsv()
|
||||
{
|
||||
isLoading = true;
|
||||
// salvo davvero!
|
||||
await Egw.Core.Utils.SaveToCsv(SearchRecords, fullPath, ';');
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private async Task ReloadData()
|
||||
{
|
||||
SearchRecords = await TService.TaskListAll(TypeSel, SearchVal);
|
||||
totalCount = SearchRecords.Count;
|
||||
var firstRec = SearchRecords.OrderBy(x => x.Ordinal).FirstOrDefault();
|
||||
minOrdinal = firstRec != null ? firstRec.Ordinal : 0;
|
||||
var lastRec = SearchRecords.OrderByDescending(x => x.Ordinal).FirstOrDefault();
|
||||
maxOrdinal = lastRec != null ? lastRec.Ordinal : 9999;
|
||||
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using MP.TaskMan.Models
|
||||
@using MP.TaskMan.Models
|
||||
@using EgwCoreLib.Razor
|
||||
@using EgwCoreLib.Utils
|
||||
Reference in New Issue
Block a user