Fix ordinamento

This commit is contained in:
Samuele Locatelli
2024-04-03 11:08:21 +02:00
parent 912748e132
commit 57e8ea08ba
14 changed files with 172 additions and 25 deletions
+60 -1
View File
@@ -540,7 +540,7 @@ namespace MP.Data.Controllers
dbResult = dbCtx
.DbSetTaskList
.Where(x => (TType == Task2ExeType.ND || x.TType == TType))
.OrderBy(x => x.TaskId)
.OrderBy(x => x.Ordinal)
.ToList();
}
return dbResult;
@@ -564,6 +564,7 @@ namespace MP.Data.Controllers
.FirstOrDefault();
if (currData != null)
{
currData.Ordinal = rec2upd.Ordinal;
currData.Name = rec2upd.Name;
currData.Descript = rec2upd.Descript;
currData.Command = rec2upd.Command;
@@ -593,6 +594,64 @@ namespace MP.Data.Controllers
return done;
}
/// <summary>
/// Update ordinamento task
/// </summary>
/// <param name="rec2upd">Record da spostare x priorità</param>
/// <returns></returns>
public bool TaskListMove(TaskListModel rec2upd, bool moveUp)
{
bool done = false;
using (var dbCtx = new MoonPro_STATSContext(_configuration))
{
try
{
var currData = dbCtx
.DbSetTaskList
.Where(x => x.TaskId == rec2upd.TaskId)
.FirstOrDefault();
if (currData != null)
{
int actOrdinal = currData.Ordinal;
TaskListModel? otherRec = null;
// cerco, secondo richiesta, precedente o successivo
if (moveUp)
{
otherRec = dbCtx
.DbSetTaskList
.Where(x => x.Ordinal < currData.Ordinal)
.OrderByDescending(x => x.Ordinal)
.FirstOrDefault();
}
else
{
otherRec = dbCtx
.DbSetTaskList
.Where(x => x.Ordinal > currData.Ordinal)
.OrderBy(x => x.Ordinal)
.FirstOrDefault();
}
// inverto ordinale SE ho record
if (otherRec != null)
{
currData.Ordinal = otherRec.Ordinal;
otherRec.Ordinal = actOrdinal;
dbCtx.Entry(currData).State = EntityState.Modified;
dbCtx.Entry(otherRec).State = EntityState.Modified;
}
}
//salvo
dbCtx.SaveChanges();
done = true;
}
catch (Exception exc)
{
Log.Error($"Eccezione in TaskListUpsert{Environment.NewLine}{exc}");
}
}
return done;
}
#endregion Public Methods
#region Private Fields
+5
View File
@@ -18,6 +18,11 @@ namespace MP.Data.DatabaseModels
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int TaskId { get; set; } = 0;
/// <summary>
/// Ordinale x esecuzione
/// </summary>
public int Ordinal { get; set; } = 0;
/// <summary>
/// Nome Task
/// </summary>
+39 -6
View File
@@ -21,13 +21,13 @@
<label class="small">Tipo Task</label>
</div>
</div>
<div class="col-md-5">
<div class="col-md-8">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Descript">
<label class="small">Descrizione Task</label>
</div>
</div>
<div class="col-md-2">
@* <div class="col-md-2">
<div class="form-floating">
<select class="form-select" @bind="@CurrRecord.Freq">
@foreach (var option in Enum.GetValues(typeof(MP.Data.Objects.Enums.TaskFreqType)))
@@ -45,22 +45,55 @@
<input type="number" class="form-control" @bind="@CurrRecord.Cad">
<label class="small">Cadenza</label>
</div>
</div>
</div> *@
</div>
<div class="row g-1">
<div class="col-md-3">
<div class="col-md-4">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Command">
<label class="small">Comando</label>
</div>
</div>
<div class="col-md-6">
<div class="col-md-8">
<div class="form-floating">
<input type="text" class="form-control" @bind="@CurrRecord.Args">
<label class="small">Parametri</label>
</div>
</div>
<div class="col-md-3 pt-2">
</div>
<div class="row g-1">
<div class="col-md-3">
<div class="form-floating">
<input type="number" class="form-control" @bind="@CurrRecord.Ordinal">
<label class="small">Ordine Esecuzione</label>
</div>
</div>
<div class="col-md-3">
<div class="form-floating">
<input type="datetime-local" class="form-control" @bind="@CurrRecord.DtNextExec">
<label class="small">Prossima Esecuzione</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<select class="form-select" @bind="@CurrRecord.Freq">
@foreach (var option in Enum.GetValues(typeof(MP.Data.Objects.Enums.TaskFreqType)))
{
<option value="@option">
@option
</option>
}
</select>
<label class="small">Frequenza</label>
</div>
</div>
<div class="col-md-2">
<div class="form-floating">
<input type="number" class="form-control" @bind="@CurrRecord.Cad">
<label class="small">Cadenza</label>
</div>
</div>
<div class="col-md-2 pt-2">
<button class="btn btn-lg w-100 btn-success" @onclick="()=>doSave()" title="Save"><i class="far fa-save"></i> Save</button>
</div>
</div>
+2 -2
View File
@@ -38,8 +38,8 @@ namespace MP.Stats.Components
await Task.Delay(1);
if (CurrRecord != null)
{
var nextDt = StatService.CalcNextExe(CurrRecord);
CurrRecord.DtNextExec = nextDt;
//var nextDt = StatService.CalcNextExe(CurrRecord);
//CurrRecord.DtNextExec = nextDt;
fatto = await StatService.TaskListUpsert(CurrRecord);
}
await EC_update.InvokeAsync(fatto);
+14
View File
@@ -654,6 +654,20 @@ namespace MP.Stats.Data
return await Task.FromResult(dbResult);
}
/// <summary>
/// Update ordinamento task
/// </summary>
/// <param name="rec2upd">Record da spostare x priorità</param>
/// <returns></returns>
public async Task<bool> TaskListMove(TaskListModel rec2upd, bool moveUp)
{
bool dbResult = dbController.TaskListMove(rec2upd, moveUp);
// svuoto cache!
await FlushCache("Task");
return await Task.FromResult(dbResult);
}
#endregion Public Methods
#region Protected Fields
+2 -2
View File
@@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>6.16.2404.0309</Version>
<Version>6.16.2404.0309</Version>
<Version>6.16.2404.0311</Version>
<Version>6.16.2404.0311</Version>
</PropertyGroup>
<ItemGroup>
+20 -2
View File
@@ -55,7 +55,7 @@
<th>
<button class="btn btn-sm btn-info" @onclick="doReset" title="Reset"><i class="fas fa-sync"></i></button>
</th>
<th>#</th>
<th>Ord</th>
<th>Task</th>
<th>Tipo</th>
<th>Command</th>
@@ -86,7 +86,25 @@
<button class="btn btn-sm btn-secondary" @onclick="()=>doCancel()" title="Cancel"><i class="fas fa-undo"></i></button>
}
</td>
<td>@record.TaskId</td>
<td>
@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 (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>
<div>@record.Name</div>
<div class="small">@record.Descript</div>
+20 -2
View File
@@ -78,6 +78,8 @@ namespace MP.Stats.Pages
protected MpStatsService StatService { get; set; }
protected int totalCount { get; set; } = 0;
protected int minOrdinal { get; set; } = 0;
protected int maxOrdinal { get; set; } = 999;
protected Task2ExeType TypeSel
{
@@ -152,8 +154,11 @@ namespace MP.Stats.Pages
protected async Task doRun(TaskListModel selRec)
{
// SE non è ancora scaduto chiedo conferma
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;
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;
@@ -240,6 +245,7 @@ namespace MP.Stats.Pages
protected async Task ResetFilter(SelectData newFilter)
{
clearFile();
detRecord = null;
currRecord = null;
SearchRecords = null;
ListRecords = null;
@@ -269,6 +275,14 @@ namespace MP.Stats.Pages
await ReloadData();
}
protected async Task doMove(TaskListModel currRec, bool goUp)
{
await StatService.TaskListMove(currRec, goUp);
detRecord = null;
currRecord = null;
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
@@ -340,6 +354,10 @@ namespace MP.Stats.Pages
{
SearchRecords = await StatService.TaskListAll(TypeSel, "");
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();
}
+1 -1
View File
@@ -23,7 +23,7 @@ namespace MP.Stats
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
logging.SetMinimumLevel(LogLevel.Information);
//logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
})
.UseNLog();
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 6.16.2404.0309</h4>
<h4>Versione: 6.16.2404.0311</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.16.2404.0309
6.16.2404.0311
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2404.0309</version>
<version>6.16.2404.0311</version>
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+5 -4
View File
@@ -8,8 +8,9 @@
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Server=localhost\\SQLEXPRESS;Database=MoonPro_STATS;Trusted_Connection=True;MultipleActiveResultSets=true",
"MP.Stats": "Server=localhost\\SQLEXPRESS;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;"
}
"ConnectionStrings": {
"Redis": "localhost:6379,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
"DefaultConnection": "Server=localhost\\SQLEXPRESS;Database=MoonPro_STATS;Trusted_Connection=True;MultipleActiveResultSets=true",
"MP.Stats": "Server=localhost\\SQLEXPRESS;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;"
}
}
+1 -2
View File
@@ -8,8 +8,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Redis": "localhost:6379,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
//"Redis": "localhost:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
"Redis": "localhost:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
"DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;MultipleActiveResultSets=true",
"MP.Stats": "Server=SQL2016DEV;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;"
},