using MudBlazor; using SteUp.Shared.Core.Entities; namespace SteUp.Shared.Core.Helpers; /// /// Stato di sincronizzazione di una scheda rispetto al server Integry. /// Principio "Offline è la verità": il rilevatore deve sempre vedere cosa è /// ancora solo sul dispositivo e cosa è già arrivato al server. /// public enum SyncState { /// Salvata solo in locale, non ancora inviata al server. DaInviare = 0, /// Inviata al server (ha un ActivityId). Inviato = 1, /// Salvata in locale ma non completata: da riprendere, non inviabile. Bozza = 2 } public static class SchedaSyncHelper { public static SyncState GetSyncState(this Scheda scheda) => scheda.Bozza ? SyncState.Bozza : string.IsNullOrEmpty(scheda.ActivityId) ? SyncState.DaInviare : SyncState.Inviato; public static string ToLabel(this SyncState state) => state switch { SyncState.DaInviare => "Da inviare", SyncState.Inviato => "Inviato", SyncState.Bozza => "Da completare", _ => string.Empty }; /// /// Colore del badge. Corallo (Primary) = azione richiesta (da inviare); /// verde (Success) = fatto (inviato). Rispetta la Regola dell'Unico Accento. /// public static Color GetColor(this SyncState state) => state switch { SyncState.DaInviare => Color.Primary, SyncState.Inviato => Color.Success, SyncState.Bozza => Color.Warning, _ => Color.Default }; public static string GetIcon(this SyncState state) => state switch { SyncState.DaInviare => Icons.Material.Rounded.PhonelinkOff, SyncState.Inviato => Icons.Material.Rounded.CloudDone, SyncState.Bozza => Icons.Material.Rounded.EditNote, _ => string.Empty }; /// Numero di schede non ancora inviate in una lista. Le bozze non contano: /// non sono inviabili finché non vengono completate. public static int CountDaInviare(this IEnumerable schede) => schede.Count(s => s.GetSyncState() == SyncState.DaInviare); /// Numero di schede lasciate a metà, da riprendere. public static int CountBozze(this IEnumerable schede) => schede.Count(s => s.GetSyncState() == SyncState.Bozza); }