From 84462aead4c1b047f3c8150f27c50517b6c84276 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Mon, 14 Aug 2023 16:00:34 +0200 Subject: [PATCH] work on shipcall control --- src/BreCalClient/MainWindow.xaml.cs | 67 ++++++++++++------------ src/BreCalClient/ShipcallControl.xaml | 56 +++++++++++++------- src/BreCalClient/ShipcallControl.xaml.cs | 20 +++++++ src/BreCalClient/ShipcallControlModel.cs | 19 ++++++- src/server/BreCal/impl/shipcalls.py | 3 ++ 5 files changed, 111 insertions(+), 54 deletions(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index dd633e5..e88b3c3 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -2,28 +2,17 @@ // Description: Bremen calling main window // -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading; -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.Navigation; -using System.Windows.Shapes; - using BreCalClient.misc.Api; using BreCalClient.misc.Client; using BreCalClient.misc.Model; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; namespace BreCalClient { @@ -145,38 +134,50 @@ namespace BreCalClient if(selectedSCMModel != null) { - selectedSCMModel.Shipcall = shipcall; - + selectedSCMModel.Shipcall = shipcall; } else { // no: create new entry - ShipcallControlModel scm = new ShipcallControlModel(); - scm.Shipcall = shipcall; + selectedSCMModel = new ShipcallControlModel(); + selectedSCMModel.Shipcall = shipcall; if (this._shipLookupDict.ContainsKey(shipcall.ShipId)) - scm.Ship = this._shipLookupDict[shipcall.ShipId]; + selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId]; if (this._berthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0)) - scm.Berth = this._berthLookupDict[shipcall.ArrivalBerthId ?? 0].Name1; + selectedSCMModel.Berth = this._berthLookupDict[shipcall.ArrivalBerthId ?? 0].Name1; - _controlModels.Add(scm); + _controlModels.Add(selectedSCMModel); this.Dispatcher.Invoke(new Action(() => { ShipcallControl sc = new ShipcallControl(); sc.Height = 120; - sc.ShipcallControlModel = scm; + sc.ShipcallControlModel = selectedSCMModel; sc.TimesRequested += Sc_TimesRequested; sc.EditRequested += Sc_EditRequested; this.stackPanel.Children.Add(sc); })); - } + } + selectedSCMModel.AssignParticipants(this._participants); } - - // test for deletion, anything in the display that is not in the lookup result - foreach(ShipcallControlModel scm in this._controlModels) + + List removeList = new(); + foreach (ShipcallControlModel scm in this._controlModels) { - - } + if(shipcalls.Find(s => s.Id == scm.Shipcall?.Id) == null) + { + foreach (ShipcallControl sc in this.stackPanel.Children) + if (sc.ShipcallControlModel?.Shipcall?.Id == scm.Shipcall?.Id) + removeList.Add(sc); + } + } + foreach(ShipcallControl sc in removeList) + { + this.Dispatcher.Invoke(new Action(() => + { + this.stackPanel.Children.Remove(sc); + })); + } await Task.Delay(TimeSpan.FromSeconds(SHIPCALL_UPDATE_INTERVAL_SECONDS), _tokenSource.Token); } diff --git a/src/BreCalClient/ShipcallControl.xaml b/src/BreCalClient/ShipcallControl.xaml index 5f2c4a1..4455cb0 100644 --- a/src/BreCalClient/ShipcallControl.xaml +++ b/src/BreCalClient/ShipcallControl.xaml @@ -20,15 +20,16 @@ + - + + - - + @@ -38,25 +39,26 @@ - - - - + + - - +