From 57e8ea08ba086af39ea13498063f418f68ca357d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 3 Apr 2024 11:08:21 +0200 Subject: [PATCH] Fix ordinamento --- MP.Data/Controllers/MpStatsController.cs | 61 +++++++++++++++++++++++- MP.Data/DatabaseModels/TaskListModel.cs | 5 ++ MP.Stats/Components/TaskEdit.razor | 45 ++++++++++++++--- MP.Stats/Components/TaskEdit.razor.cs | 4 +- MP.Stats/Data/MpStatsService.cs | 14 ++++++ MP.Stats/MP.Stats.csproj | 4 +- MP.Stats/Pages/TaskScheduler.razor | 22 ++++++++- MP.Stats/Pages/TaskScheduler.razor.cs | 22 ++++++++- MP.Stats/Program.cs | 2 +- MP.Stats/Resources/ChangeLog.html | 2 +- MP.Stats/Resources/VersNum.txt | 2 +- MP.Stats/Resources/manifest.xml | 2 +- MP.Stats/appsettings.Production.json | 9 ++-- MP.Stats/appsettings.json | 3 +- 14 files changed, 172 insertions(+), 25 deletions(-) diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs index a0c625ff..14138d01 100644 --- a/MP.Data/Controllers/MpStatsController.cs +++ b/MP.Data/Controllers/MpStatsController.cs @@ -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; } + /// + /// Update ordinamento task + /// + /// Record da spostare x priorità + /// + 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 diff --git a/MP.Data/DatabaseModels/TaskListModel.cs b/MP.Data/DatabaseModels/TaskListModel.cs index c551fa6c..1b36175a 100644 --- a/MP.Data/DatabaseModels/TaskListModel.cs +++ b/MP.Data/DatabaseModels/TaskListModel.cs @@ -18,6 +18,11 @@ namespace MP.Data.DatabaseModels [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int TaskId { get; set; } = 0; + /// + /// Ordinale x esecuzione + /// + public int Ordinal { get; set; } = 0; + /// /// Nome Task /// diff --git a/MP.Stats/Components/TaskEdit.razor b/MP.Stats/Components/TaskEdit.razor index 2504bed7..19d84aa3 100644 --- a/MP.Stats/Components/TaskEdit.razor +++ b/MP.Stats/Components/TaskEdit.razor @@ -21,13 +21,13 @@ -
+
-
+ @*
-
+
*@
-
+
-
+
-
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
diff --git a/MP.Stats/Components/TaskEdit.razor.cs b/MP.Stats/Components/TaskEdit.razor.cs index 21d75d2d..aa518899 100644 --- a/MP.Stats/Components/TaskEdit.razor.cs +++ b/MP.Stats/Components/TaskEdit.razor.cs @@ -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); diff --git a/MP.Stats/Data/MpStatsService.cs b/MP.Stats/Data/MpStatsService.cs index 4d2f4f11..c6b3ccc0 100644 --- a/MP.Stats/Data/MpStatsService.cs +++ b/MP.Stats/Data/MpStatsService.cs @@ -654,6 +654,20 @@ namespace MP.Stats.Data return await Task.FromResult(dbResult); } + + /// + /// Update ordinamento task + /// + /// Record da spostare x priorità + /// + public async Task 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 diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index e7535cb1..42dc4420 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,8 +4,8 @@ net6.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 6.16.2404.0309 - 6.16.2404.0309 + 6.16.2404.0311 + 6.16.2404.0311 diff --git a/MP.Stats/Pages/TaskScheduler.razor b/MP.Stats/Pages/TaskScheduler.razor index 22e6d441..ae3e8fa0 100644 --- a/MP.Stats/Pages/TaskScheduler.razor +++ b/MP.Stats/Pages/TaskScheduler.razor @@ -55,7 +55,7 @@ - # + Ord Task Tipo Command @@ -86,7 +86,25 @@ } - @record.TaskId + + @if (record.Ordinal == minOrdinal) + { + + } + else + { + + } + @record.Ordinal + @if (record.Ordinal == maxOrdinal) + { + + } + else + { + + } +
@record.Name
@record.Descript
diff --git a/MP.Stats/Pages/TaskScheduler.razor.cs b/MP.Stats/Pages/TaskScheduler.razor.cs index 45c35e3a..1fe4e398 100644 --- a/MP.Stats/Pages/TaskScheduler.razor.cs +++ b/MP.Stats/Pages/TaskScheduler.razor.cs @@ -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("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("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(); } diff --git a/MP.Stats/Program.cs b/MP.Stats/Program.cs index 0922ce22..cf9c5b1a 100644 --- a/MP.Stats/Program.cs +++ b/MP.Stats/Program.cs @@ -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(); diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 6ef61bf4..2b9ffd5f 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 6.16.2404.0309

+

Versione: 6.16.2404.0311


Note di rilascio:
    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index 5ba9d076..7d08573a 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2404.0309 +6.16.2404.0311 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index 9f6a0068..5414356a 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2404.0309 + 6.16.2404.0311 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false diff --git a/MP.Stats/appsettings.Production.json b/MP.Stats/appsettings.Production.json index d11e6522..7a46be05 100644 --- a/MP.Stats/appsettings.Production.json +++ b/MP.Stats/appsettings.Production.json @@ -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;" + } } \ No newline at end of file diff --git a/MP.Stats/appsettings.json b/MP.Stats/appsettings.json index 0c2e0de4..6e1fcc91 100644 --- a/MP.Stats/appsettings.json +++ b/MP.Stats/appsettings.json @@ -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;" },