+
- @*
*@
-
-
-
+
+ @if (ShowPercent)
+ {
+
+ }
+
diff --git a/EgwCoreLib.Razor/ProgressDisplay.razor.cs b/EgwCoreLib.Razor/ProgressDisplay.razor.cs
index 03a4d2d..db4435b 100644
--- a/EgwCoreLib.Razor/ProgressDisplay.razor.cs
+++ b/EgwCoreLib.Razor/ProgressDisplay.razor.cs
@@ -4,32 +4,98 @@ namespace EgwCoreLib.Razor
{
public partial class ProgressDisplay : IDisposable
{
+ #region Public Enums
+
+ public enum ModalSize
+ {
+ Small,
+ Medium,
+ Large
+ }
+
+ #endregion Public Enums
+
#region Public Properties
+ ///
+ /// Valore corrente
+ ///
[Parameter]
public double CurrVal
{
- get => ActVal;
+ get => actVal;
set
{
- ActVal = value;
- StartVal = value;
- IsLoading = ActVal < MaxVal;
+ actVal = value;
+ startVal = value;
+ isLoading = actVal < MaxVal;
}
}
+ ///
+ /// Dimensioni attese modale
+ /// default: ModalSize.Medium
+ ///
[Parameter]
- public double ExpTimeMSec { get; set; } = 10000;
+ public ModalSize DisplaySize { get; set; } = ModalSize.Medium;
+ ///
+ /// Tempo atteso per prossimo step
+ /// default: 10000
+ ///
[Parameter]
- public bool IsLoading { get; set; } = false;
+ public int ExpTimeMSec { get; set; } = 10000;
+ ///
+ /// Valore massimo ammesso
+ /// default: 100
+ ///
[Parameter]
public double MaxVal { get; set; } = 100;
+ ///
+ /// Style modale
+ /// default: card
+ /// alternative: card alert-primary
+ ///
+ [Parameter]
+ public string ModalCss { get; set; } = "card";
+
+ ///
+ /// Prossimo valore ammesso (fino al max)
+ /// default: 100
+ ///
[Parameter]
public double NextVal { get; set; } = 100;
+ ///
+ /// Style progressbar
+ /// default: progress-bar progress-bar-striped progress-bar-animated
+ ///
+ [Parameter]
+ public string ProgressCss { get; set; } = "progress-bar progress-bar-striped progress-bar-animated";
+
+ ///
+ /// Intervallo interno per refresh percentuale avanzamento
+ /// default: 100ms
+ ///
+ [Parameter]
+ public int RefreshInterval { get; set; } = 100;
+
+ ///
+ /// Indica se mostrare la percentuale vanzamento
+ /// default: true
+ ///
+ [Parameter]
+ public bool ShowPercent { get; set; } = true;
+
+ ///
+ /// Numero di secondi prima (rispetto valore ExpTimeMsec) da cui iniziare rallentamento
+ ///
+ [Parameter]
+ public int SlowWindowMSec { get; set; } = 3000;
+
+ //Titolo da mostrare (se "" NON lo mostra)
[Parameter]
public string Title { get; set; } = "Progress";
@@ -39,33 +105,40 @@ namespace EgwCoreLib.Razor
public void Dispose()
{
- periodicTimer?.Dispose();
+ uiTimer?.Dispose();
}
#endregion Public Methods
- #region Protected Fields
-
- protected PeriodicTimer? periodicTimer = null;
-
- #endregion Protected Fields
-
#region Protected Properties
- protected string currWidth { get; set; } = "";
- protected string modalCss { get; set; } = "alert alert-success";
+ protected string modalDialogCss
+ {
+ get
+ {
+ string answ = "modal-dialog";
+ switch (DisplaySize)
+ {
+ case ModalSize.Small:
+ answ = "modal-dialog modal-sm";
+ break;
+
+ case ModalSize.Large:
+ answ = "modal-dialog modal-xl";
+ break;
+
+ case ModalSize.Medium:
+ default:
+ break;
+ }
+ return answ;
+ }
+ }
#endregion Protected Properties
#region Protected Methods
-#if false
- protected override void OnInitialized()
- {
- RunTimer(); // fire-and-forget
- }
-#endif
-
protected override async Task OnParametersSetAsync()
{
// salvo valori aggiornamento...
@@ -75,78 +148,71 @@ namespace EgwCoreLib.Razor
nextUpdate = lastUpdate.AddMilliseconds(ExpTimeMSec);
await RefreshDisplay();
}
- if(IsLoading)
+ if (isLoading)
{
- periodicTimer?.Dispose();
- periodicTimer = new PeriodicTimer(TimeSpan.FromMilliseconds(RefInt));
+ uiTimer?.Dispose();
+ uiTimer = new PeriodicTimer(TimeSpan.FromMilliseconds(RefreshInterval));
RunTimer();
}
else
{
- periodicTimer = null;
+ uiTimer = null;
}
}
- protected async Task RefreshDisplay()
- {
- currWidth = $"{(double)ActVal / MaxVal:P0}";
- DisplayMsg = $"{ActVal / MaxVal:P2}";
- await InvokeAsync(StateHasChanged);
- }
-
#endregion Protected Methods
#region Private Fields
- [Parameter]
- public int RefreshInterval
- {
- get => RefInt;
- set
- {
- if (RefInt != value && value > 0)
- {
- RefInt = value;
-#if false
- periodicTimer?.Dispose();
- periodicTimer = new PeriodicTimer(TimeSpan.FromMilliseconds(value));
- RunTimer();
-#endif
- }
- }
- }
- private int RefInt { get; set; } = 100;
+ private PeriodicTimer? uiTimer = null;
#endregion Private Fields
#region Private Properties
- private double ActVal { get; set; } = 100;
- private string DisplayMsg { get; set; } = "Loading...";
+ private double actVal { get; set; } = 100;
+ private string currWidth { get; set; } = "";
+ private string displayMsg { get; set; } = "Loading...";
+
+ private bool isLoading { get; set; } = false;
+
private DateTime lastUpdate { get; set; } = DateTime.Now.AddMinutes(-1);
+
private DateTime nextUpdate { get; set; } = DateTime.Now;
- private double StartVal { get; set; } = 100;
+
+ private double startVal { get; set; } = 100;
#endregion Private Properties
#region Private Methods
+ private async Task RefreshDisplay()
+ {
+ currWidth = $"{(double)actVal / MaxVal:P0}";
+ if (ShowPercent)
+ {
+ displayMsg = $"{actVal / MaxVal:P2}";
+ }
+ await InvokeAsync(StateHasChanged);
+ }
+
private async void RunTimer()
{
- while (periodicTimer!=null && await periodicTimer.WaitForNextTickAsync())
+ while (uiTimer != null && await uiTimer.WaitForNextTickAsync())
{
- if (IsLoading)
+ if (isLoading)
{
DateTime adesso = DateTime.Now;
- if (nextUpdate <= adesso)
+ if (nextUpdate <= adesso.AddMilliseconds(SlowWindowMSec))
{
nextUpdate = adesso.AddMilliseconds(RefreshInterval);
}
// calcolo delta ms...
- var deltaMs = adesso.Subtract(lastUpdate).TotalMilliseconds;
- var denomMs = nextUpdate.Subtract(lastUpdate).TotalMilliseconds;
+ var numMs = adesso.Subtract(lastUpdate).TotalMilliseconds;
+ var denMs = nextUpdate.Subtract(lastUpdate).TotalMilliseconds;
+ denMs = denMs > 0 ? denMs : 1;
// aggiorno display...
- ActVal = StartVal + (NextVal - StartVal) * (deltaMs / denomMs);
+ actVal = startVal + (NextVal - startVal) * (numMs / denMs);
await RefreshDisplay();
}
}