using Sonex.Data.Records; using System; using System.Collections.Generic; using System.Linq; namespace Sonex.Client.Controls.TimelineGrid; public static class TimelineGridDataAdapter { public static List CreateFunctionDefinitions( IEnumerable? operationTypes) { if (operationTypes == null) { return []; } return operationTypes .Select(TimelineGridFunctionDefinition.FromRecord) .OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase) .ThenBy(item => item.Id) .ToList(); } public static List CreateRows( IEnumerable? activityBars, IReadOnlyDictionary? accounts = null, string unit = "pcs/h") { if (activityBars == null) { return []; } var rows = new List(); var barsByAccount = activityBars .Where(item => item != null) .GroupBy(item => item.LocusAccountName ?? string.Empty) .OrderBy(group => group.Key, StringComparer.OrdinalIgnoreCase); foreach (var group in barsByAccount) { var accountName = string.IsNullOrWhiteSpace(group.Key) ? "unknown" : group.Key.Trim(); AccountRecord? account = null; if (accounts is not null) { accounts.TryGetValue(accountName, out account); } var displayName = account?.FullName; if (string.IsNullOrWhiteSpace(displayName)) { displayName = accountName; } var subtext = account?.Department; if (string.IsNullOrWhiteSpace(subtext)) { subtext = accountName; } var row = new TimelineGridRow { Id = accountName, HeaderText = displayName, HeaderSubtext = subtext, Unit = unit }; foreach (var bar in group.OrderBy(item => item.StartTime).ThenBy(item => item.EndTime).ThenBy(item => item.LineId)) { row.Bars.Add(TimelineGridBar.FromRecord(bar)); } rows.Add(row); } return rows; } }