From 9d6f692b4d9e6453fe102e71cce3747fa0bd6df5 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 25 Oct 2024 19:18:50 +0200 Subject: [PATCH] Inizio bozza aggiunta progetto gestione TaskMan --- MP-LAND.sln | 8 ++ MP.TaskMan/Component1.razor | 3 + MP.TaskMan/Component1.razor.css | 6 ++ MP.TaskMan/ExampleJsInterop.cs | 37 +++++++ MP.TaskMan/MP.TaskMan.csproj | 39 +++++++ MP.TaskMan/TaskEdit.razor | 101 +++++++++++++++++++ MP.TaskMan/TaskEdit.razor.cs | 44 ++++++++ MP.TaskMan/TaskExeList.razor | 100 ++++++++++++++++++ MP.TaskMan/TaskExeList.razor.cs | 134 +++++++++++++++++++++++++ MP.TaskMan/_Imports.razor | 1 + MP.TaskMan/wwwroot/background.png | Bin 0 -> 378 bytes MP.TaskMan/wwwroot/exampleJsInterop.js | 6 ++ 12 files changed, 479 insertions(+) create mode 100644 MP.TaskMan/Component1.razor create mode 100644 MP.TaskMan/Component1.razor.css create mode 100644 MP.TaskMan/ExampleJsInterop.cs create mode 100644 MP.TaskMan/MP.TaskMan.csproj create mode 100644 MP.TaskMan/TaskEdit.razor create mode 100644 MP.TaskMan/TaskEdit.razor.cs create mode 100644 MP.TaskMan/TaskExeList.razor create mode 100644 MP.TaskMan/TaskExeList.razor.cs create mode 100644 MP.TaskMan/_Imports.razor create mode 100644 MP.TaskMan/wwwroot/background.png create mode 100644 MP.TaskMan/wwwroot/exampleJsInterop.js diff --git a/MP-LAND.sln b/MP-LAND.sln index 2113d66c..c14fcb70 100644 --- a/MP-LAND.sln +++ b/MP-LAND.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Egw.Core", "Egw.Core\Egw.Co EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MP.Data", "MP.Data\MP.Data.csproj", "{EE871AE5-9B5E-493E-8E59-F77234979AD7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.TaskMan", "MP.TaskMan\MP.TaskMan.csproj", "{8BBD39D5-9390-4EBA-979B-954DC8FFC850}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug_LiManDebug|Any CPU = Debug_LiManDebug|Any CPU @@ -42,6 +44,12 @@ Global {EE871AE5-9B5E-493E-8E59-F77234979AD7}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE871AE5-9B5E-493E-8E59-F77234979AD7}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE871AE5-9B5E-493E-8E59-F77234979AD7}.Release|Any CPU.Build.0 = Release|Any CPU + {8BBD39D5-9390-4EBA-979B-954DC8FFC850}.Debug_LiManDebug|Any CPU.ActiveCfg = Debug|Any CPU + {8BBD39D5-9390-4EBA-979B-954DC8FFC850}.Debug_LiManDebug|Any CPU.Build.0 = Debug|Any CPU + {8BBD39D5-9390-4EBA-979B-954DC8FFC850}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8BBD39D5-9390-4EBA-979B-954DC8FFC850}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8BBD39D5-9390-4EBA-979B-954DC8FFC850}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8BBD39D5-9390-4EBA-979B-954DC8FFC850}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MP.TaskMan/Component1.razor b/MP.TaskMan/Component1.razor new file mode 100644 index 00000000..7558f967 --- /dev/null +++ b/MP.TaskMan/Component1.razor @@ -0,0 +1,3 @@ +
+ This component is defined in the MP.TaskMan library. +
diff --git a/MP.TaskMan/Component1.razor.css b/MP.TaskMan/Component1.razor.css new file mode 100644 index 00000000..c6afca40 --- /dev/null +++ b/MP.TaskMan/Component1.razor.css @@ -0,0 +1,6 @@ +.my-component { + border: 2px dashed red; + padding: 1em; + margin: 1em 0; + background-image: url('background.png'); +} diff --git a/MP.TaskMan/ExampleJsInterop.cs b/MP.TaskMan/ExampleJsInterop.cs new file mode 100644 index 00000000..ec45f6e4 --- /dev/null +++ b/MP.TaskMan/ExampleJsInterop.cs @@ -0,0 +1,37 @@ +using Microsoft.JSInterop; + +namespace MP.TaskMan +{ + // This class provides an example of how JavaScript functionality can be wrapped + // in a .NET class for easy consumption. The associated JavaScript module is + // loaded on demand when first needed. + // + // This class can be registered as scoped DI service and then injected into Blazor + // components for use. + + public class ExampleJsInterop : IAsyncDisposable + { + private readonly Lazy> moduleTask; + + public ExampleJsInterop(IJSRuntime jsRuntime) + { + moduleTask = new(() => jsRuntime.InvokeAsync( + "import", "./_content/MP.TaskMan/exampleJsInterop.js").AsTask()); + } + + public async ValueTask Prompt(string message) + { + var module = await moduleTask.Value; + return await module.InvokeAsync("showPrompt", message); + } + + public async ValueTask DisposeAsync() + { + if (moduleTask.IsValueCreated) + { + var module = await moduleTask.Value; + await module.DisposeAsync(); + } + } + } +} diff --git a/MP.TaskMan/MP.TaskMan.csproj b/MP.TaskMan/MP.TaskMan.csproj new file mode 100644 index 00000000..6f2a7fe4 --- /dev/null +++ b/MP.TaskMan/MP.TaskMan.csproj @@ -0,0 +1,39 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MP.TaskMan/TaskEdit.razor b/MP.TaskMan/TaskEdit.razor new file mode 100644 index 00000000..69d6674a --- /dev/null +++ b/MP.TaskMan/TaskEdit.razor @@ -0,0 +1,101 @@ +@if (CurrRecord != null) +{ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ @*
+
+ + +
+
+
+
+ + +
+
*@ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+} + diff --git a/MP.TaskMan/TaskEdit.razor.cs b/MP.TaskMan/TaskEdit.razor.cs new file mode 100644 index 00000000..df68fe96 --- /dev/null +++ b/MP.TaskMan/TaskEdit.razor.cs @@ -0,0 +1,44 @@ +using Microsoft.AspNetCore.Components; + +namespace MP.TaskMan +{ + public partial class TaskEdit + { + #region Public Properties + + [Parameter] + public TaskListModel? CurrRecord { get; set; } = null; + + [Parameter] + public EventCallback EC_update { get; set; } + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected TaskService TService { get; set; } + + #endregion Protected Properties + + #region Protected Methods + + protected async Task doCancel() + { + await EC_update.InvokeAsync(false); + } + + protected async Task doSave() + { + bool fatto = false; + await Task.Delay(1); + if (CurrRecord != null) + { + fatto = await TService.TaskListUpsert(CurrRecord); + } + await EC_update.InvokeAsync(fatto); + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.TaskMan/TaskExeList.razor b/MP.TaskMan/TaskExeList.razor new file mode 100644 index 00000000..99220f54 --- /dev/null +++ b/MP.TaskMan/TaskExeList.razor @@ -0,0 +1,100 @@ + +
+
+
+
+
+ History +
+
+ @if (CurrRecord != null) + { +
@TextReduce(CurrRecord.Command, 40)
+
@TextReduce(CurrRecord.Args, 60)
+ } +
+
+
+
+ +
+
+
+
+
+ @if (ListRecords == null) + { + + } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { +
+
+ + + + + + + + + + + @foreach (var record in ListRecords) + { + + + + + + + + + + } + +
#InizioFineEsito
+ @record.TaskExecId + + @($"{record.DtStart:HH:mm:ss.fff}") +
@($"{record.DtStart:yyyy-MM.dd ddd}")
+
+ @($"{record.DtEnd:HH:mm:ss.fff}") +
@($"{record.DtEnd:yyyy-MM.dd ddd}")
+
+
+
+ @if (@record.IsError) + { + + } + else + { + + } +
+
+ @($"{record.Duration:N3}") sec +
+
+
+
+
@record.Result
+
+
+
+
+ } +
+ +
\ No newline at end of file diff --git a/MP.TaskMan/TaskExeList.razor.cs b/MP.TaskMan/TaskExeList.razor.cs new file mode 100644 index 00000000..dcec09b2 --- /dev/null +++ b/MP.TaskMan/TaskExeList.razor.cs @@ -0,0 +1,134 @@ +using MailKit; +using Microsoft.AspNetCore.Components; +using MongoDB.Bson; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.TaskMan +{ + public partial class TaskExeList + { + #region Public Properties + + [Parameter] + public TaskListModel? CurrRecord { get; set; } = null; + + #endregion Public Properties + + #region Protected Fields + + protected bool isLoading = false; + + #endregion Protected Fields + + #region Protected Properties + + [Inject] + protected NavigationManager NavManager { get; set; } + + /// + /// Show error mode: 0 = tutti 1 = solo errori 2 = solo ok + /// + protected int ShowErrorMode + { + get => showErrorMode; + set + { + if (showErrorMode != value) + { + showErrorMode = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + } + + protected int totalCount { get; set; } = 0; + + [Inject] + protected TaskService TService { get; set; } + + #endregion Protected Properties + + #region Protected Methods + + protected string alCss(TaskExecModel TaskRec) + { + return TaskRec.IsError ? "alert-danger" : "alert-success"; + } + + protected async Task ForceReload(int newNum) + { + numRecord = newNum; + await ReloadData(); + } + + protected async Task ForceReloadPage(int newNum) + { + currPage = newNum; + await ReloadData(); + } + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + } + + 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; + } + + #endregion Protected Methods + + #region Private Fields + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + private List ListRecords; + private List SearchRecords; + + #endregion Private Fields + + #region Private Properties + + private int currPage { get; set; } = 1; + private int numRecord { get; set; } = 10; + private int showErrorMode { get; set; } = 0; + + #endregion Private Properties + + #region Private Methods + + private async Task ReloadData() + { + SearchRecords = await TService.TaskExecGetFilt(CurrRecord.TaskId, 1000, ""); + // se non tutti filtro... + if (ShowErrorMode != 0) + { + if (ShowErrorMode == 1) + { + SearchRecords = SearchRecords.FindAll(x => x.IsError); + } + else if (ShowErrorMode == 2) + { + SearchRecords = SearchRecords.FindAll(x => !x.IsError); + } + } + totalCount = SearchRecords.Count; + ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP.TaskMan/_Imports.razor b/MP.TaskMan/_Imports.razor new file mode 100644 index 00000000..77285129 --- /dev/null +++ b/MP.TaskMan/_Imports.razor @@ -0,0 +1 @@ +@using Microsoft.AspNetCore.Components.Web diff --git a/MP.TaskMan/wwwroot/background.png b/MP.TaskMan/wwwroot/background.png new file mode 100644 index 0000000000000000000000000000000000000000..e15a3bde6e2bdb380df6a0b46d7ed00bdeb0aaa8 GIT binary patch literal 378 zcmeAS@N?(olHy`uVBq!ia0vp^x**KK1SGdsl%54rjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJwr2>%=KS^ie7oTIEF;HpS|GCbyPusHSqiXaCu3qf)82(9Gq&mZq2{Kq}M*X&MWtJ zSi1Jo7ZzfImg%g=t(qo=wsSR2lZoP(Rj#3wacN=q0?Br(rXzgZEGK2$ID{|A=5S{xJEuzSH>!M+7wSY6hB<=-E^*n0W7 S8wY^CX7F_Nb6Mw<&;$S{dxtsz literal 0 HcmV?d00001 diff --git a/MP.TaskMan/wwwroot/exampleJsInterop.js b/MP.TaskMan/wwwroot/exampleJsInterop.js new file mode 100644 index 00000000..ea8d76ad --- /dev/null +++ b/MP.TaskMan/wwwroot/exampleJsInterop.js @@ -0,0 +1,6 @@ +// This is a JavaScript module that is loaded on demand. It can export any number of +// functions, and may import other JavaScript modules if required. + +export function showPrompt(message) { + return prompt(message, 'Type anything here'); +}