diff --git a/src/BreCalClient/App.config b/src/BreCalClient/App.config index 335a433..31f6f0a 100644 --- a/src/BreCalClient/App.config +++ b/src/BreCalClient/App.config @@ -86,6 +86,12 @@ + + 0 + + + 0 + \ No newline at end of file diff --git a/src/BreCalClient/AppNotification.cs b/src/BreCalClient/AppNotification.cs index 7a0f075..ed66f31 100644 --- a/src/BreCalClient/AppNotification.cs +++ b/src/BreCalClient/AppNotification.cs @@ -3,34 +3,70 @@ // using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Collections.ObjectModel; using ToastNotifications.Core; +using BreCalClient.misc.Model; namespace BreCalClient { internal class AppNotification { - private static Dictionary _notifications = new (); + private static Dictionary _notifications = new(); private readonly int _id; - + private static ObservableCollection _notificationsCollection = new(); public AppNotification(int id) { _id = id; } + #region Properties + public int Id { get { return _id; } } + public string? NotificationType + { + get; private set; + } + + public string? NotificationDate + { + get; private set; + } + + public string? Ship + { + get; private set; + } + + public string? ShipcallType + { + get; private set; + } + + public string? Berth + { + get; private set; + } + + public string? ETA + { + get; private set; + } + + public static ObservableCollection AppNotifications { get { return _notificationsCollection; } } + + #endregion + #region internal statics internal static void LoadFromSettings() { _notifications.Clear(); - // preload notifications that have been processed + // load notification ids that have been processed foreach (string? notification_id in Properties.Settings.Default.Notifications) { if(Int32.TryParse(notification_id, out int result)) @@ -47,61 +83,61 @@ namespace BreCalClient internal static bool UpdateNotifications(List notifications, System.Collections.Concurrent.ConcurrentDictionary currentShipcalls, ToastViewModel vm) { bool result = false; + foreach (BreCalClient.misc.Model.Notification notification in notifications) { - if(!_notifications.ContainsKey(notification.Id)) + if (notification.ParticipantId.HasValue && notification.ParticipantId.Value != App.Participant.Id) // not meant for us + continue; + + if (!currentShipcalls.ContainsKey(notification.ShipcallId)) // not one of our shipcalls (maybe for another port or filtered) + continue; + + if (!_notificationsCollection.Where(x => x.Id == notification.Id).Any()) { - _notifications.Add(notification.Id, new AppNotification(notification.Id)); + AppNotification ap = new(notification.Id); + ap.NotificationType = notification.Type.ToString(); + ap.Ship = currentShipcalls[notification.ShipcallId]?.Ship?.Name; + ap.ShipcallType = currentShipcalls[notification.ShipcallId]?.Shipcall?.Type.ToString(); + ap.ETA = currentShipcalls[notification.ShipcallId]?.GetETAETD(true); + Times? agencyTimes = currentShipcalls[notification.ShipcallId]?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY); + ap.Berth = currentShipcalls[notification.ShipcallId]?.GetBerthText(agencyTimes); - // filter if the notification concerns us - if(notification.ParticipantId != null) + System.Diagnostics.Trace.WriteLine($"Notification {notification.Id} Type {notification.Type}"); + MessageOptions options = new(); + options.FontSize = 14; + options.ShowCloseButton = true; + + switch(notification.Type) // TODO: Set toast color and icon { - if(App.Participant.Id == notification.ParticipantId) - { - result = true; - } - } - else - { - // find out if this notification concerns us - if(currentShipcalls.ContainsKey(notification.ShipcallId)) - { - result = true; - } + case misc.Model.NotificationType.TimeConflict: + + break; + case misc.Model.NotificationType.TimeConflictResolved: + + break; + case misc.Model.NotificationType.Assignment: + + break; + case misc.Model.NotificationType.Next24h: + + break; + case misc.Model.NotificationType.Unassigned: + + break; } - - if(result) + + _notificationsCollection.Add(ap); + + string toastText = $"{ap.Ship} ({ap.ShipcallType}) - {ap.ETA} - {ap.Berth}"; + + if (!_notifications.ContainsKey(notification.Id)) { - System.Diagnostics.Trace.WriteLine($"Notification {notification.Id} Type {notification.Type}"); - MessageOptions options = new MessageOptions(); - options.FontSize = 14; - options.ShowCloseButton = true; - switch(notification.Type) - { - case misc.Model.NotificationType.TimeConflict: - - break; - case misc.Model.NotificationType.TimeConflictResolved: - - break; - case misc.Model.NotificationType.Assignment: - - break; - case misc.Model.NotificationType.Next24h: - - break; - case misc.Model.NotificationType.Unassigned: - - break; - } - - string toastText = $"{currentShipcalls[notification.ShipcallId]?.Ship?.Name} ({currentShipcalls[notification.ShipcallId]?.Shipcall?.Type}) - {currentShipcalls[notification.ShipcallId]?.GetETAETD(true)} - {currentShipcalls[notification.ShipcallId]?.GetBerthText(null)}"; + _notifications.Add(notification.Id, ap); App.Current.Dispatcher.Invoke(() => { vm.ShowInformation(toastText, options); }); - } - + } } } return result; diff --git a/src/BreCalClient/BreCalClient.csproj b/src/BreCalClient/BreCalClient.csproj index 5ad9573..cd0a12e 100644 --- a/src/BreCalClient/BreCalClient.csproj +++ b/src/BreCalClient/BreCalClient.csproj @@ -26,6 +26,7 @@ + @@ -84,6 +85,7 @@ + diff --git a/src/BreCalClient/HistoryDialog.xaml.cs b/src/BreCalClient/HistoryDialog.xaml.cs index ce6cb2b..f827de0 100644 --- a/src/BreCalClient/HistoryDialog.xaml.cs +++ b/src/BreCalClient/HistoryDialog.xaml.cs @@ -1,5 +1,5 @@ // Copyright (c) 2024- schick Informatik -// Description: Window to show (complete) list of current shipcall histories +// Description: // using BreCalClient.misc.Api; diff --git a/src/BreCalClient/MainWindow.xaml b/src/BreCalClient/MainWindow.xaml index dd169f8..f7f14eb 100644 --- a/src/BreCalClient/MainWindow.xaml +++ b/src/BreCalClient/MainWindow.xaml @@ -124,6 +124,8 @@ + + @@ -157,19 +159,25 @@ + + + + - - + + - + - - + + diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 23e109a..be19337 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -71,6 +71,7 @@ namespace BreCalClient // private bool _filterChanged = false; // private bool _sequenceChanged = false; private HistoryDialog? _historyDialog; + private NotificationDialog? _notificationDialog; #endregion @@ -453,6 +454,21 @@ namespace BreCalClient } } + private void buttonNotifications_Click(object sender, RoutedEventArgs e) + { + if (_notificationDialog == null) + { + _notificationDialog = new NotificationDialog(); + _notificationDialog.AppNotifications = AppNotification.AppNotifications; + _notificationDialog.Closed += (sender, e) => { this._notificationDialog = null; }; + _notificationDialog.Show(); + } + else + { + _notificationDialog.Activate(); + } + } + private void buttonManualRefresh_Click(object sender, RoutedEventArgs e) { _refreshImmediately = true; // set flag to avoid timer loop termination @@ -649,8 +665,11 @@ namespace BreCalClient while (true) { Thread.Sleep(CHECK_NOTIFICATIONS_INTERVAL_SECONDS * 1000); - List notifications = await _staticApi.NotificationsGetAsync(); - AppNotification.UpdateNotifications(notifications, _allShipcallsDict, _vm); + if (_loginResult?.NotifyPopup ?? false) + { + List notifications = await _staticApi.NotificationsGetAsync(); + AppNotification.UpdateNotifications(notifications, _allShipcallsDict, _vm); + } } } diff --git a/src/BreCalClient/NotificationDialog.xaml b/src/BreCalClient/NotificationDialog.xaml new file mode 100644 index 0000000..799e732 --- /dev/null +++ b/src/BreCalClient/NotificationDialog.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +