Add conditional service request row to ticket overview

This commit is contained in:
Meik
2026-07-17 18:48:48 +02:00
parent 0fef3ad49c
commit 62a5c97cbd
9 changed files with 338 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ namespace FasdDesktopUi.Basics.Services
{
#region Fields
private const string ServiceRequestsEnabledKey = "ServiceRequestsEnabled";
private readonly ITicketOverviewCommunicationSource _communicationSource;
private static readonly string[] OverviewKeys = new[]
{
@@ -35,6 +36,10 @@ namespace FasdDesktopUi.Basics.Services
"IncidentActive",
"IncidentCritical",
"IncidentNewInfo",
"ServiceRequestsNew",
"ServiceRequestsActive",
"ServiceRequestsCritical",
"ServiceRequestsNewInfo",
"UnassignedTickets",
"UnassignedTicketsCritical"
};
@@ -53,6 +58,7 @@ namespace FasdDesktopUi.Basics.Services
private bool _isDemo;
private bool _initialized;
private bool _isEnabled;
private bool _serviceRequestsEnabled;
private readonly Random _random = new Random();
#if isDemo
private readonly List<DemoTicketRecord> _persistedDemoTickets = new List<DemoTicketRecord>();
@@ -109,8 +115,10 @@ namespace FasdDesktopUi.Basics.Services
#region Public API
public event EventHandler<TicketOverviewCountsChangedEventArgs> OverviewCountsChanged;
public event EventHandler ServiceRequestsAvailabilityChanged;
public IReadOnlyDictionary<string, TileCounts> CurrentCounts => _currentCounts;
public bool ServiceRequestsEnabled => _serviceRequestsEnabled;
public bool IsScopeInitialized(TileScope scope)
{
@@ -215,6 +223,8 @@ namespace FasdDesktopUi.Basics.Services
{
_currentCounts[key] = TileCounts.Empty;
}
UpdateServiceRequestsAvailability(false);
});
}
@@ -328,8 +338,12 @@ namespace FasdDesktopUi.Basics.Services
_isDemo = communication.IsDemo();
var rawCounts = await communication.GetTicketOverviewCounts(OverviewKeys, scope == TileScope.Role).ConfigureAwait(false);
var requestedKeys = scope == TileScope.Personal
? OverviewKeys.Concat(new[] { ServiceRequestsEnabledKey }).ToArray()
: OverviewKeys;
var rawCounts = await communication.GetTicketOverviewCounts(requestedKeys, scope == TileScope.Role).ConfigureAwait(false);
var counts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
var serviceRequestsEnabled = _isDemo;
if (rawCounts != null)
{
@@ -338,6 +352,13 @@ namespace FasdDesktopUi.Basics.Services
if (string.IsNullOrWhiteSpace(kvp.Key))
continue;
if (string.Equals(kvp.Key, ServiceRequestsEnabledKey, StringComparison.OrdinalIgnoreCase))
{
if (scope == TileScope.Personal)
serviceRequestsEnabled = _isDemo || kvp.Value > 0;
continue;
}
counts[kvp.Key] = Math.Max(0, kvp.Value);
}
}
@@ -345,7 +366,13 @@ namespace FasdDesktopUi.Basics.Services
if (!_isEnabled)
return;
await _dispatcher.InvokeAsync(() => ProcessScopeCounts(scope, counts));
await _dispatcher.InvokeAsync(() =>
{
if (scope == TileScope.Personal)
UpdateServiceRequestsAvailability(serviceRequestsEnabled);
ProcessScopeCounts(scope, counts);
});
}
catch (Exception ex)
{
@@ -362,6 +389,15 @@ namespace FasdDesktopUi.Basics.Services
#region Count Processing
private void UpdateServiceRequestsAvailability(bool isEnabled)
{
if (_serviceRequestsEnabled == isEnabled)
return;
_serviceRequestsEnabled = isEnabled;
ServiceRequestsAvailabilityChanged?.Invoke(this, EventArgs.Empty);
}
private void RefreshTimerIntervals()
{
_ = _dispatcher.InvokeAsync(() =>