Overview window of past notifications

This commit is contained in:
Daniel Schick 2024-12-23 11:23:37 +01:00
parent 880a8a2a8d
commit a648cc2e71
14 changed files with 322 additions and 58 deletions

View File

@ -86,6 +86,12 @@
<setting name="FilterCriteriaMap" serializeAs="String">
<value />
</setting>
<setting name="W5Top" serializeAs="String">
<value>0</value>
</setting>
<setting name="W5Left" serializeAs="String">
<value>0</value>
</setting>
</BreCalClient.Properties.Settings>
</userSettings>
</configuration>

View File

@ -3,11 +3,11 @@
//
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
{
@ -15,22 +15,58 @@ namespace BreCalClient
{
private static Dictionary<int, AppNotification> _notifications = new();
private readonly int _id;
private static ObservableCollection<AppNotification> _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<AppNotification> 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,36 +83,31 @@ namespace BreCalClient
internal static bool UpdateNotifications(List<BreCalClient.misc.Model.Notification> notifications, System.Collections.Concurrent.ConcurrentDictionary<int, ShipcallControlModel> currentShipcalls, ToastViewModel vm)
{
bool result = false;
foreach (BreCalClient.misc.Model.Notification notification in notifications)
{
if(!_notifications.ContainsKey(notification.Id))
{
_notifications.Add(notification.Id, new AppNotification(notification.Id));
if (notification.ParticipantId.HasValue && notification.ParticipantId.Value != App.Participant.Id) // not meant for us
continue;
// filter if the notification concerns us
if(notification.ParticipantId != null)
{
if(App.Participant.Id == notification.ParticipantId)
{
result = true;
}
}
else
{
// find out if this notification concerns us
if(currentShipcalls.ContainsKey(notification.ShipcallId))
{
result = true;
}
}
if (!currentShipcalls.ContainsKey(notification.ShipcallId)) // not one of our shipcalls (maybe for another port or filtered)
continue;
if(result)
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);
Times? agencyTimes = currentShipcalls[notification.ShipcallId]?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY);
ap.Berth = currentShipcalls[notification.ShipcallId]?.GetBerthText(agencyTimes);
System.Diagnostics.Trace.WriteLine($"Notification {notification.Id} Type {notification.Type}");
MessageOptions options = new MessageOptions();
MessageOptions options = new();
options.FontSize = 14;
options.ShowCloseButton = true;
switch(notification.Type)
switch(notification.Type) // TODO: Set toast color and icon
{
case misc.Model.NotificationType.TimeConflict:
@ -95,13 +126,18 @@ namespace BreCalClient
break;
}
string toastText = $"{currentShipcalls[notification.ShipcallId]?.Ship?.Name} ({currentShipcalls[notification.ShipcallId]?.Shipcall?.Type}) - {currentShipcalls[notification.ShipcallId]?.GetETAETD(true)} - {currentShipcalls[notification.ShipcallId]?.GetBerthText(null)}";
_notificationsCollection.Add(ap);
string toastText = $"{ap.Ship} ({ap.ShipcallType}) - {ap.ETA} - {ap.Berth}";
if (!_notifications.ContainsKey(notification.Id))
{
_notifications.Add(notification.Id, ap);
App.Current.Dispatcher.Invoke(() =>
{
vm.ShowInformation(toastText, options);
});
}
}
}
return result;

View File

@ -26,6 +26,7 @@
<None Remove="Resources\arrow_up_blue.png" />
<None Remove="Resources\arrow_up_green.png" />
<None Remove="Resources\arrow_up_red.png" />
<None Remove="Resources\bell3.png" />
<None Remove="Resources\check.png" />
<None Remove="Resources\clipboard.png" />
<None Remove="Resources\clock.png" />
@ -84,6 +85,7 @@
<Resource Include="Resources\arrow_up_blue.png" />
<Resource Include="Resources\arrow_up_green.png" />
<Resource Include="Resources\arrow_up_red.png" />
<Resource Include="Resources\bell3.png" />
<Resource Include="Resources\check.png" />
<Resource Include="Resources\clipboard.png" />
<Resource Include="Resources\clock.png" />

View File

@ -1,5 +1,5 @@
// Copyright (c) 2024- schick Informatik
// Description: Window to show (complete) list of current shipcall histories
// Description:
//
using BreCalClient.misc.Api;

View File

@ -124,6 +124,8 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="26" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="26" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="26" />
@ -157,19 +159,25 @@
</StatusBarItem>
<Separator Grid.Column="9"/>
<StatusBarItem Grid.Column="10">
<Button x:Name="buttonNotifications" Click="buttonNotifications_Click" Width="20" ToolTip="{x:Static p:Resources.textShowNotifications}">
<Image Source="./Resources/bell3.png"/>
</Button>
</StatusBarItem>
<Separator Grid.Column="9"/>
<StatusBarItem Grid.Column="12">
<TextBlock Name="labelStatusBar"></TextBlock>
</StatusBarItem>
<Separator Grid.Column="11"/>
<StatusBarItem Grid.Column="12">
<Separator Grid.Column="13"/>
<StatusBarItem Grid.Column="14">
<Button x:Name="buttonManualRefresh" Width="20" Click="buttonManualRefresh_Click" ToolTip="{x:Static p:Resources.textTriggerManualRefresh}">
<Image Source="./Resources/nav_refresh_green.png"/>
</Button>
</StatusBarItem>
<StatusBarItem Grid.Column="13">
<StatusBarItem Grid.Column="15">
<TextBlock x:Name="labelLatestUpdate" />
</StatusBarItem>
<Separator Grid.Column="14"/>
<StatusBarItem Grid.Column="15">
<Separator Grid.Column="16"/>
<StatusBarItem Grid.Column="17">
<ProgressBar Name="generalProgressStatus" Width="90" Height="16" Foreground="LightGray"/>
</StatusBarItem>
</StatusBar>

View File

@ -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,10 +665,13 @@ namespace BreCalClient
while (true)
{
Thread.Sleep(CHECK_NOTIFICATIONS_INTERVAL_SECONDS * 1000);
if (_loginResult?.NotifyPopup ?? false)
{
List<Notification> notifications = await _staticApi.NotificationsGetAsync();
AppNotification.UpdateNotifications(notifications, _allShipcallsDict, _vm);
}
}
}
#endregion

View File

@ -0,0 +1,61 @@
<Window x:Class="BreCalClient.NotificationDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BreCalClient"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:p = "clr-namespace:BreCalClient.Resources"
mc:Ignorable="d" Left="{local:SettingBinding W5Left}" Top="{local:SettingBinding W5Top}"
Title="{x:Static p:Resources.textNotifications}" Height="450" Width="800" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<local:ENIDataGrid x:Name="dataGridNotifications" Grid.Row="0" SelectionMode="Single" IsReadOnly="True" AlternatingRowBackground="LightBlue" AutoGenerateColumns="False"
CanUserAddRows="False" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<local:ENIDataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding NotificationType}" Value="Assignment">
<Setter Property="Foreground" Value="Blue"/>
</DataTrigger>
<DataTrigger Binding="{Binding NotificationType}" Value="Next24h">
<Setter Property="Foreground" Value="DarkOrange"/>
</DataTrigger>
<DataTrigger Binding="{Binding NotificationType}" Value="TimeConflict">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding NotificationType}" Value="TimeConflictResolved">
<Setter Property="Foreground" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding NotificationType}" Value="Unassigned">
<Setter Property="Foreground" Value="DarkGray"/>
</DataTrigger>
</Style.Triggers>
</Style>
</local:ENIDataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Id" Binding="{Binding Path=Id}" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static p:Resources.textType}" Binding="{Binding Path=NotificationType}" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static p:Resources.textDate}" Binding="{Binding Path=NotificationDate}" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static p:Resources.textShip}" Binding="{Binding Path=Ship}" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static p:Resources.textShipcall}" Binding="{Binding Path=ShipcallType}" IsReadOnly="True"/>
<DataGridTextColumn Header="ETA/ETD" Binding="{Binding Path=ETA}" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static p:Resources.textBerth}" Binding="{Binding Path=Berth}" IsReadOnly="True"/>
</DataGrid.Columns>
</local:ENIDataGrid>
<Grid Grid.Row="1" Grid.Column="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="22" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width=".2*" />
</Grid.ColumnDefinitions>
<Button x:Name="buttonClose" Click="buttonClose_Click" Content="{x:Static p:Resources.textClose}" Width="80" Margin="2" Grid.Row="0" Grid.Column="3" HorizontalAlignment="Right" />
</Grid>
</Grid>
</Window>

View File

@ -0,0 +1,44 @@
// Copyright (c) 2024- schick Informatik
// Description:
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace BreCalClient
{
/// <summary>
/// Interaction logic for NotificationDialog.xaml
/// </summary>
public partial class NotificationDialog : Window
{
public NotificationDialog()
{
InitializeComponent();
}
internal ObservableCollection<AppNotification>? AppNotifications { get; set; }
private void buttonClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.dataGridNotifications.ItemsSource = AppNotifications;
}
}
}

View File

@ -237,5 +237,29 @@ namespace BreCalClient.Properties {
this["Notifications"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public double W5Top {
get {
return ((double)(this["W5Top"]));
}
set {
this["W5Top"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public double W5Left {
get {
return ((double)(this["W5Left"]));
}
set {
this["W5Left"] = value;
}
}
}
}

View File

@ -59,5 +59,11 @@
<Setting Name="Notifications" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="W5Top" Type="System.Double" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="W5Left" Type="System.Double" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -167,6 +167,16 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] bell3 {
get {
object obj = ResourceManager.GetObject("bell3", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
@ -560,6 +570,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Date.
/// </summary>
public static string textDate {
get {
return ResourceManager.GetString("textDate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Delete.
/// </summary>
@ -1208,6 +1227,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Shipcall.
/// </summary>
public static string textShipcall {
get {
return ResourceManager.GetString("textShipcall", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Ship length.
/// </summary>
@ -1244,6 +1272,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Show notificiations.
/// </summary>
public static string textShowNotifications {
get {
return ResourceManager.GetString("textShowNotifications", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sort order.
/// </summary>

View File

@ -565,4 +565,13 @@
<data name="textNotifyPush" xml:space="preserve">
<value>Banner / Push Benachrichtigung in App</value>
</data>
<data name="textDate" xml:space="preserve">
<value>Datum</value>
</data>
<data name="textShipcall" xml:space="preserve">
<value>Anlauf</value>
</data>
<data name="textShowNotifications" xml:space="preserve">
<value>Benachrichtigungen anzeigen</value>
</data>
</root>

View File

@ -613,4 +613,16 @@
<data name="textNotifyPush" xml:space="preserve">
<value>Notify by push notification in app</value>
</data>
<data name="bell3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>bell3.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="textDate" xml:space="preserve">
<value>Date</value>
</data>
<data name="textShipcall" xml:space="preserve">
<value>Shipcall</value>
</data>
<data name="textShowNotifications" xml:space="preserve">
<value>Show notificiations</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB