diff --git a/docs/ApiValidationRules.md b/docs/ApiValidationRules.md index 40788b7..c080ae0 100644 --- a/docs/ApiValidationRules.md +++ b/docs/ApiValidationRules.md @@ -105,7 +105,7 @@ Usually the "Z" is missing at the end indicating local time. | tidal_window_from | value must be in the future | | tidal_window_to | value must be in the future, value must be > tidal_window_from | | recommended_tugs | 0 < value < 10 | - | canceled | may not be set on POST | + | canceled | optional on POST | | evaluation | may not be set | | evaluation_message | may not be set | | created / modified | may not be set | diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 475c8ac..cf689e6 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -23,6 +23,8 @@ using Polly; using System.Net.Http; using System.Net; using System.Windows.Input; +using System.Text.RegularExpressions; +using Newtonsoft.Json.Linq; namespace BreCalClient @@ -1058,13 +1060,27 @@ namespace BreCalClient private void ShowErrorDialog(string message, string caption) { + // Example: + // Error calling ShipcallUpdate: {\"message\": \"PUT Requests for shipcalls can only be issued by an assigned AGENCY or BSMD users + // (if the special-flag is enabled). Assigned Agency: ShipcallParticipantMap(id=628, shipcall_id=115, participant_id=10, + // type=8, created=datetime.datetime(2024, 8, 28, 15, 13, 14), modified=None) with Flags: 42\"} + Match m = Regex.Match(message, "\\{(.*)\\}"); + if ((m != null) && m.Success) + { + dynamic? msg = JsonConvert.DeserializeObject(m.Value); + if(msg != null) + { + message = msg.message; + } + } + _log.ErrorFormat("{0} - {1}", caption, message); - /* + Dispatcher.Invoke(new Action(() => { MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Error); })); - */ + } private void EnableControlsForParticipant() diff --git a/src/BreCalClient/ShipListDialog.xaml.cs b/src/BreCalClient/ShipListDialog.xaml.cs index df7d112..a4149e2 100644 --- a/src/BreCalClient/ShipListDialog.xaml.cs +++ b/src/BreCalClient/ShipListDialog.xaml.cs @@ -90,7 +90,9 @@ namespace BreCalClient private async void DataGridShips_CreateRequested() { - ShipModel shipModel = new(new Ship()); + + ShipModel shipModel = new((ShipModel.LastEditShip != null) ? ShipModel.LastEditShip : new Ship()); + EditShipDialog esd = new() { Ship = shipModel.Ship @@ -111,14 +113,15 @@ namespace BreCalClient if(!BreCalLists.ShipLookupDict.TryAdd(id.VarId, shipModel)) BreCalLists.ShipLookupDict[id.VarId] = shipModel; this.dataGridShips.ItemsSource = BreCalLists.AllShips; + ShipModel.LastEditShip = null; } } catch (Exception ex) { - MessageBox.Show(ex.Message); + ShipModel.LastEditShip = shipModel.Ship; + MessageBox.Show(ex.Message); } - } - + } } #endregion diff --git a/src/BreCalClient/ShipModel.cs b/src/BreCalClient/ShipModel.cs index 4f06e21..9f11673 100644 --- a/src/BreCalClient/ShipModel.cs +++ b/src/BreCalClient/ShipModel.cs @@ -16,6 +16,8 @@ namespace BreCalClient public Ship Ship { get; private set; } + public static Ship? LastEditShip { get; set; } + public string TugCompany { get { if(this.Ship.ParticipantId.HasValue)