From 45f7f1d4e4ffdfd472e2a3647eb3d9a99c6a536c Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 1 Mar 2022 18:40:49 +0100 Subject: [PATCH] Fix display grafico + date storico impianto --- GWMS.UI/Components/ChartJs/Line.razor | 16 ++- GWMS.UI/Components/InputDateTime.cs | 124 ++++++++++++++++++++++ GWMS.UI/Components/PlantOverview.razor | 2 +- GWMS.UI/Components/PlantOverview.razor.cs | 76 ++++++------- GWMS.UI/GWMS.UI.csproj | 2 +- GWMS.UI/Pages/PlantAnalisys.razor | 38 +++---- GWMS.UI/wwwroot/lib/chartBoot.js | 10 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 10 files changed, 201 insertions(+), 73 deletions(-) create mode 100644 GWMS.UI/Components/InputDateTime.cs diff --git a/GWMS.UI/Components/ChartJs/Line.razor b/GWMS.UI/Components/ChartJs/Line.razor index a842b20..ba04479 100644 --- a/GWMS.UI/Components/ChartJs/Line.razor +++ b/GWMS.UI/Components/ChartJs/Line.razor @@ -31,6 +31,9 @@ [Parameter] public List Labels { get; set; } = new List(); + [Parameter] + public List pointColor { get; set; } = new List(); + [Parameter] public List lineColor { get; set; } = new List(); @@ -89,6 +92,7 @@ yAxes = new { display = true, + position = "right", ticks = new { maxTicksLimit = 10 @@ -102,6 +106,13 @@ distribution = "linear", } }, + plugins = new + { + legend = new + { + display = false + }, + }, Animation = false, AspectRatio = AspRatio == 0 ? "auto" : $"{AspRatio}" }, @@ -109,13 +120,16 @@ { labels = Labels, datasets = new[] - { + { new { data = DataTS, + pointBorderColor = backColor, borderColor = lineColor, backgroundColor = backColor, fill = true, + PointRadius = 2, + BorderWidth = 1, lineTension= lTens, stepped= false, label= Title diff --git a/GWMS.UI/Components/InputDateTime.cs b/GWMS.UI/Components/InputDateTime.cs new file mode 100644 index 0000000..9b7b6b6 --- /dev/null +++ b/GWMS.UI/Components/InputDateTime.cs @@ -0,0 +1,124 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Rendering; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; + +namespace GWMS.UI.Components +{ + /// + /// override calsse inputdate da + /// https://github.com/dotnet/aspnetcore/issues/18078 + /// + /// + public class InputDateTime : InputDate + { + #region Private Fields + + private const string DateFormat = "yyyy-MM-ddTHH:mm:ss"; + + #endregion Private Fields + + #region Private Methods + + private static bool TryParseDateTime(string value, out TValue result) + { + var success = BindConverter.TryConvertToDateTime(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue); + if (success) + { + result = (TValue)(object)parsedValue; + return true; + } + else + { + result = default; + return false; + } + } + + private static bool TryParseDateTimeOffset(string value, out TValue result) + { + var success = BindConverter.TryConvertToDateTimeOffset(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue); + if (success) + { + result = (TValue)(object)parsedValue; + return true; + } + else + { + result = default; + return false; + } + } + + #endregion Private Methods + + #region Protected Methods + + /// + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, "input"); + builder.AddMultipleAttributes(1, AdditionalAttributes); + builder.AddAttribute(2, "type", "datetime-local"); + builder.AddAttribute(3, "class", CssClass); + builder.AddAttribute(4, "value", BindConverter.FormatValue(CurrentValueAsString)); + builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); + builder.CloseElement(); + } + + /// + protected override string FormatValueAsString(TValue value) + { + switch (value) + { + case DateTime dateTimeValue: + return BindConverter.FormatValue(dateTimeValue, DateFormat, CultureInfo.InvariantCulture); + + case DateTimeOffset dateTimeOffsetValue: + return BindConverter.FormatValue(dateTimeOffsetValue, DateFormat, CultureInfo.InvariantCulture); + + default: + return string.Empty; // Handles null for Nullable, etc. + } + } + + /// + protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) + { + // Unwrap nullable types. We don't have to deal with receiving empty values for nullable + // types here, because the underlying InputBase already covers that. + var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); + + bool success; + if (targetType == typeof(DateTime)) + { + success = TryParseDateTime(value, out result); + } + else if (targetType == typeof(DateTimeOffset)) + { + success = TryParseDateTimeOffset(value, out result); + } + else + { + throw new InvalidOperationException($"The type '{targetType}' is not a supported date type."); + } + + if (success) + { + validationErrorMessage = null; + return true; + } + else + { + validationErrorMessage = string.Format(ParsingErrorMessage, FieldIdentifier.FieldName); + return false; + } + } + + #endregion Protected Methods + } +} diff --git a/GWMS.UI/Components/PlantOverview.razor b/GWMS.UI/Components/PlantOverview.razor index b8ca20c..3c875ef 100644 --- a/GWMS.UI/Components/PlantOverview.razor +++ b/GWMS.UI/Components/PlantOverview.razor @@ -103,7 +103,7 @@ } else { - + } diff --git a/GWMS.UI/Components/PlantOverview.razor.cs b/GWMS.UI/Components/PlantOverview.razor.cs index e299401..9b86afc 100644 --- a/GWMS.UI/Components/PlantOverview.razor.cs +++ b/GWMS.UI/Components/PlantOverview.razor.cs @@ -1,13 +1,13 @@ -using System; +using GWMS.Data; +using GWMS.Data.DTO; +using GWMS.UI.Data; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Configuration; +using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using GWMS.UI.Data; -using GWMS.Data.DTO; -using Microsoft.AspNetCore.Components; using System.Threading; -using Microsoft.Extensions.Configuration; -using GWMS.Data; +using System.Threading.Tasks; namespace GWMS.UI.Components { @@ -90,27 +90,13 @@ namespace GWMS.UI.Components // aggiunta delay o non riesce a disegnare int ChartWaitDelay = 150; int.TryParse(Configuration["ChartWaitDelay"], out ChartWaitDelay); - Random rnd = new Random(); - Thread.Sleep(ChartWaitDelay*rnd.Next(150)); + Thread.Sleep(ChartWaitDelay); await HandleRedraw(); }); } } } - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - await HandleRedraw(); - } - } - - protected override async Task OnInitializedAsync() - { - await HandleRedraw(); - } - public string headerStatus { get @@ -148,27 +134,6 @@ namespace GWMS.UI.Components redFact = answ; } -#if false - private LineChartDataset GetLineChartDataset() - { - fixRedFactor(); - var answ = new LineChartDataset - { - //Label = "Livello", - Data = _currItem.LevelTS.OrderByDescending(x => x.DtEvent).Where((cat, index) => index % redFact == 0).OrderBy(x => x.DtEvent).Select(x => x.ValDouble).ToList(), - BorderColor = getLineColors(1f), - BackgroundColor = getFillColors(0.25f), - Fill = true, - PointRadius = 3, - BorderWidth = 2, - LineTension = 0, - BorderDash = new List { } - }; - return answ; - } - -#endif - #endregion Private Methods #region Protected Methods @@ -197,6 +162,18 @@ namespace GWMS.UI.Components return answ; } + /// + /// Genera colori punti + /// + /// + /// + protected List getPointColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(108, 118, 158, {alpha})"); + return answ; + } + protected async Task HandleRedraw() { fixRedFactor(); @@ -204,6 +181,19 @@ namespace GWMS.UI.Components LevelVal = _currItem.LevelTS.OrderByDescending(x => x.DtEvent).Where((cat, index) => index % redFact == 0).OrderBy(x => x.DtEvent).Select(r => new chartJsData.chartJsTSerie() { x = r.DtEvent, y = r.ValDouble }).ToList(); } + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await HandleRedraw(); + } + } + + protected override async Task OnInitializedAsync() + { + await HandleRedraw(); + } + protected void ShowDetail(int currPlantId) { SelPlantId = currPlantId; diff --git a/GWMS.UI/GWMS.UI.csproj b/GWMS.UI/GWMS.UI.csproj index e550b5b..35fd693 100644 --- a/GWMS.UI/GWMS.UI.csproj +++ b/GWMS.UI/GWMS.UI.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.2203.0117 + 1.0.2203.0118 95c9f021-52d1-4390-a670-5810b7b777b0 true true diff --git a/GWMS.UI/Pages/PlantAnalisys.razor b/GWMS.UI/Pages/PlantAnalisys.razor index 060c9a1..c36e464 100644 --- a/GWMS.UI/Pages/PlantAnalisys.razor +++ b/GWMS.UI/Pages/PlantAnalisys.razor @@ -26,32 +26,32 @@ @*
- @if (ShowAddNew) - { - - } + @if (ShowAddNew) + { + + }
*@
-
-
-
-
- inizio: +
+
+
+
+ inizio: +
+ +
+
+
+
+
+ fine: +
+
-
-
-
-
- fine: -
- -
-
-
diff --git a/GWMS.UI/wwwroot/lib/chartBoot.js b/GWMS.UI/wwwroot/lib/chartBoot.js index 92b9008..45f9234 100644 --- a/GWMS.UI/wwwroot/lib/chartBoot.js +++ b/GWMS.UI/wwwroot/lib/chartBoot.js @@ -2,15 +2,15 @@ window.setup = (id, config) => { var ctx = document.getElementById(id).getContext('2d'); let currentDate = new Date(); - console.log(currentDate + " - Calling setup..."); - console.log(id); + //console.log(currentDate + " - Calling setup..."); + //console.log(id); if (window['chart-' + id] instanceof Chart) { //window.myChart.destroy(); window['chart-' + id].destroy(); - console.log("Chart " + id + " destroyed!"); + //console.log("Chart " + id + " destroyed!"); } window['chart-' + id] = new Chart(ctx, config); - console.log("Chart " + id + " created!"); - console.log(window['chart-' + id]); + //console.log("Chart " + id + " created!"); + //console.log(window['chart-' + id]); } diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 29adf62..e364637 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ GWMS - Gas Warehouse Management System -

Versione: 1.0.2203.0117

+

Versione: 1.0.2203.0118


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 692fa28..e58c123 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2203.0117 +1.0.2203.0118 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 97eaf80..4ab075c 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2203.0117 + 1.0.2203.0118 http://nexus.steamware.net/repository/SWS/GWMS/stable/0/GWMS.UI.zip http://nexus.steamware.net/repository/SWS/GWMS/stable/0/ChangeLog.html false