diff --git a/src/BreCalClient/AppNotification.cs b/src/BreCalClient/AppNotification.cs index ed66f31..2dc95eb 100644 --- a/src/BreCalClient/AppNotification.cs +++ b/src/BreCalClient/AppNotification.cs @@ -13,9 +13,9 @@ namespace BreCalClient { internal class AppNotification { - private static Dictionary _notifications = new(); + private static readonly Dictionary _notifications = new(); private readonly int _id; - private static ObservableCollection _notificationsCollection = new(); + private static readonly ObservableCollection _notificationsCollection = new(); public AppNotification(int id) { @@ -31,6 +31,11 @@ namespace BreCalClient get; private set; } + public string? NotificationDisplay + { + get; private set; + } + public string? NotificationDate { get; private set; @@ -50,12 +55,18 @@ namespace BreCalClient { get; private set; } - + public string? ETA { get; private set; } + public string? Message + { + get; private set; + } + + public static ObservableCollection AppNotifications { get { return _notificationsCollection; } } #endregion @@ -94,48 +105,61 @@ namespace BreCalClient if (!_notificationsCollection.Where(x => x.Id == notification.Id).Any()) { - 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); + List newList = new(_notificationsCollection); + + AppNotification ap = new(notification.Id) + { + NotificationType = notification.Type.ToString(), + NotificationDate = notification.Created.ToString(), + Ship = currentShipcalls[notification.ShipcallId]?.Ship?.Name, + ShipcallType = currentShipcalls[notification.ShipcallId]?.Shipcall?.Type.ToString(), + ETA = currentShipcalls[notification.ShipcallId]?.GetETAETD(true) + }; Times? agencyTimes = currentShipcalls[notification.ShipcallId]?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY); ap.Berth = currentShipcalls[notification.ShipcallId]?.GetBerthText(agencyTimes); + ap.Message = notification.Message; 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 + MessageOptions options = new() { - case misc.Model.NotificationType.TimeConflict: + FontSize = 14, + ShowCloseButton = true, + Tag = ap + }; - break; - case misc.Model.NotificationType.TimeConflictResolved: + newList.Add(ap); + newList.Sort((a, b) => (a.NotificationDate ?? "").CompareTo(b.NotificationDate)); + _notificationsCollection.Clear(); + foreach(AppNotification newAp in newList) + _notificationsCollection.Add(newAp); - break; + ap.NotificationDisplay = string.Empty; + switch(notification.Type) + { case misc.Model.NotificationType.Assignment: - - break; + ap.NotificationDisplay = Resources.Resources.textAssignment; break; case misc.Model.NotificationType.Next24h: - - break; + ap.NotificationDisplay = Resources.Resources.textNext24h; break; + case misc.Model.NotificationType.TimeConflict: + ap.NotificationDisplay = Resources.Resources.textTimeConflict; break; + case misc.Model.NotificationType.TimeConflictResolved: + ap.NotificationDisplay = Resources.Resources.textTimeConflictResolved; break; case misc.Model.NotificationType.Unassigned: - - break; + ap.NotificationDisplay = Resources.Resources.textUnassigned; break; } - _notificationsCollection.Add(ap); + string toastText = ap.NotificationDisplay + "\n"; - string toastText = $"{ap.Ship} ({ap.ShipcallType}) - {ap.ETA} - {ap.Berth}"; + toastText += $"{ap.Ship} ({ap.ShipcallType}) - {ap.ETA} - {ap.Berth}"; + if (!string.IsNullOrEmpty(ap.Message)) + toastText += $" \n{ap.Message}"; if (!_notifications.ContainsKey(notification.Id)) { _notifications.Add(notification.Id, ap); App.Current.Dispatcher.Invoke(() => { - vm.ShowInformation(toastText, options); + vm.ShowAppNotification(toastText, options); }); } } diff --git a/src/BreCalClient/AppNotificationExtension.cs b/src/BreCalClient/AppNotificationExtension.cs new file mode 100644 index 0000000..927c67e --- /dev/null +++ b/src/BreCalClient/AppNotificationExtension.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2024- schick Informatik +// Description: +// + +using ToastNotifications; +using ToastNotifications.Core; + +namespace BreCalClient +{ + public static class AppNotificationExtension + { + public static void ShowAppNotification(this Notifier notifier, string message) + { + notifier.Notify(() => new AppNotificationMessage(message)); + } + + public static void ShowAppNotification(this Notifier notifier, string message, MessageOptions displayOptions) + { + notifier.Notify(() => new AppNotificationMessage(message, displayOptions)); + } + + } +} diff --git a/src/BreCalClient/AppNotificationMessage.cs b/src/BreCalClient/AppNotificationMessage.cs new file mode 100644 index 0000000..2a0e194 --- /dev/null +++ b/src/BreCalClient/AppNotificationMessage.cs @@ -0,0 +1,30 @@ +using System.Windows; +using ToastNotifications.Core; +using ToastNotifications.Messages.Core; + +namespace BreCalClient +{ + public class AppNotificationMessage : MessageBase + { + public AppNotificationMessage(string message) : this(message, new MessageOptions()) + { + } + + public AppNotificationMessage(string message, MessageOptions options) : base(message, options) + { + } + + protected override AppNotificationPart CreateDisplayPart() + { + return new AppNotificationPart(this); + } + + protected override void UpdateDisplayOptions(AppNotificationPart displayPart, MessageOptions options) + { + // if (options.FontSize != null) + // displayPart.Text.FontSize = options.FontSize.Value; + + // displayPart.CloseButton.Visibility = options.ShowCloseButton ? Visibility.Visible : Visibility.Collapsed; + } + } +} diff --git a/src/BreCalClient/AppNotificationPart.xaml b/src/BreCalClient/AppNotificationPart.xaml new file mode 100644 index 0000000..50b33c5 --- /dev/null +++ b/src/BreCalClient/AppNotificationPart.xaml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/BreCalClient/AppNotificationPart.xaml.cs b/src/BreCalClient/AppNotificationPart.xaml.cs new file mode 100644 index 0000000..b717fd7 --- /dev/null +++ b/src/BreCalClient/AppNotificationPart.xaml.cs @@ -0,0 +1,51 @@ +using BreCalClient.misc.Model; +using System.Windows; +using System.Windows.Media; +using ToastNotifications.Core; + +namespace BreCalClient +{ + /// + /// Interaction logic for NotificationPart.xaml + /// + public partial class AppNotificationPart : NotificationDisplayPart + { + public AppNotificationPart(AppNotificationMessage appNotification) + { + InitializeComponent(); + Bind(appNotification); + + if (appNotification.Options.Tag is AppNotification ap) + { + switch (ap.NotificationType) + { + case "TimeConflict": + this.ContentWrapper.Background = Brushes.Red; + break; + case "TimeConflictResolved": + this.ContentWrapper.Background = Brushes.Green; + break; + case "Assignment": + this.ContentWrapper.Background = Brushes.Blue; + break; + case "Next24h": + this.ContentWrapper.Background = Brushes.DarkOrange; + break; + case "Unassigned": + this.ContentWrapper.Background = Brushes.Gray; + break; + default: + break; + + } + } + + } + + private void OnClose(object sender, RoutedEventArgs e) + { + Notification.Close(); + } + + } +} diff --git a/src/BreCalClient/NotificationDialog.xaml b/src/BreCalClient/NotificationDialog.xaml index 799e732..6fab214 100644 --- a/src/BreCalClient/NotificationDialog.xaml +++ b/src/BreCalClient/NotificationDialog.xaml @@ -13,7 +13,7 @@ -