diff --git a/misc/BreCalApi.cs b/misc/BreCalApi.cs index 833fdcd..f76c708 100644 --- a/misc/BreCalApi.cs +++ b/misc/BreCalApi.cs @@ -1,7 +1,7 @@ //---------------------- // -// Generated REST API Client Code Generator v1.8.4.0 on 11.09.2023 10:29:36 +// Generated REST API Client Code Generator v1.8.4.0 on 21.09.2023 07:07:32 // Using the tool OpenAPI Generator v7.0.0 // //---------------------- @@ -51,6 +51,7 @@ using System.Threading.Tasks; */ namespace BreCalClient.misc.Api { +#pragma warning disable CS8073 // The result of the expression is always the same since a value of this type is never equal to 'null' /// /// Represents a collection of functions to interact with the API endpoints /// @@ -6921,9 +6922,10 @@ namespace BreCalClient.misc.Model /// berthId. /// berthInfo. /// pierSide. + /// participantType. /// created. /// modified. - public Times(int id = default(int), DateTime? etaBerth = default(DateTime?), bool? etaBerthFixed = default(bool?), DateTime? etdBerth = default(DateTime?), bool? etdBerthFixed = default(bool?), DateTime? lockTime = default(DateTime?), bool? lockTimeFixed = default(bool?), DateTime? zoneEntry = default(DateTime?), bool? zoneEntryFixed = default(bool?), DateTime? operationsStart = default(DateTime?), DateTime? operationsEnd = default(DateTime?), string remarks = default(string), int shipcallId = default(int), int participantId = default(int), int? berthId = default(int?), string berthInfo = default(string), bool? pierSide = default(bool?), DateTime created = default(DateTime), DateTime? modified = default(DateTime?)) + public Times(int id = default(int), DateTime? etaBerth = default(DateTime?), bool? etaBerthFixed = default(bool?), DateTime? etdBerth = default(DateTime?), bool? etdBerthFixed = default(bool?), DateTime? lockTime = default(DateTime?), bool? lockTimeFixed = default(bool?), DateTime? zoneEntry = default(DateTime?), bool? zoneEntryFixed = default(bool?), DateTime? operationsStart = default(DateTime?), DateTime? operationsEnd = default(DateTime?), string remarks = default(string), int shipcallId = default(int), int participantId = default(int), int? berthId = default(int?), string berthInfo = default(string), bool? pierSide = default(bool?), int? participantType = default(int?), DateTime created = default(DateTime), DateTime? modified = default(DateTime?)) { this.ShipcallId = shipcallId; this.ParticipantId = participantId; @@ -6942,6 +6944,7 @@ namespace BreCalClient.misc.Model this.BerthId = berthId; this.BerthInfo = berthInfo; this.PierSide = pierSide; + this.ParticipantType = participantType; this.Created = created; this.Modified = modified; } @@ -7031,6 +7034,11 @@ namespace BreCalClient.misc.Model [DataMember(Name = "pier_side", EmitDefaultValue = true)] public bool? PierSide { get; set; } /// + /// Gets or Sets ParticipantType + /// + [DataMember(Name = "participant_type", EmitDefaultValue = true)] + public int? ParticipantType { get; set; } + /// /// Gets or Sets Created /// [DataMember(Name = "created", EmitDefaultValue = true)] @@ -7065,6 +7073,7 @@ namespace BreCalClient.misc.Model sb.Append(" BerthId: ").Append(BerthId).Append("\n"); sb.Append(" BerthInfo: ").Append(BerthInfo).Append("\n"); sb.Append(" PierSide: ").Append(PierSide).Append("\n"); + sb.Append(" ParticipantType: ").Append(ParticipantType).Append("\n"); sb.Append(" Created: ").Append(Created).Append("\n"); sb.Append(" Modified: ").Append(Modified).Append("\n"); sb.Append("}\n"); @@ -7181,6 +7190,11 @@ namespace BreCalClient.misc.Model (this.PierSide != null && this.PierSide.Equals(input.PierSide)) ) && + ( + this.ParticipantType == input.ParticipantType || + (this.ParticipantType != null && + this.ParticipantType.Equals(input.ParticipantType)) + ) && ( this.Created == input.Created || (this.Created != null && @@ -7260,6 +7274,10 @@ namespace BreCalClient.misc.Model { hashCode = (hashCode * 59) + this.PierSide.GetHashCode(); } + if (this.ParticipantType != null) + { + hashCode = (hashCode * 59) + this.ParticipantType.GetHashCode(); + } if (this.Created != null) { hashCode = (hashCode * 59) + this.Created.GetHashCode(); @@ -7472,5 +7490,6 @@ namespace BreCalClient.misc.Model yield break; } } +#pragma warning restore CS8073 // The result of the expression is always the same since a value of this type is never equal to 'null' } diff --git a/misc/BreCalApi.yaml b/misc/BreCalApi.yaml index 76953cb..cb8acfc 100644 --- a/misc/BreCalApi.yaml +++ b/misc/BreCalApi.yaml @@ -484,6 +484,9 @@ components: pier_side: type: boolean nullable: true + participant_type: + type: integer + nullable: true created: type: string format: date-time diff --git a/misc/create_schema.sql b/misc/create_schema.sql index 5e65740..dfa0cf1 100644 --- a/misc/create_schema.sql +++ b/misc/create_schema.sql @@ -280,6 +280,7 @@ CREATE TABLE `times` ( `berth_id` int unsigned DEFAULT NULL, `berth_info` varchar(512) DEFAULT NULL, `pier_side` bit(1) DEFAULT NULL, + `participant_type` int unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `FK_TIME_SHIPCALL` (`shipcall_id`), KEY `FK_TIME_PART` (`participant_id`) /*!80000 INVISIBLE */, diff --git a/src/BreCalClient/EditShipcallControl.xaml.cs b/src/BreCalClient/EditShipcallControl.xaml.cs index 788a7ae..eaa0d9a 100644 --- a/src/BreCalClient/EditShipcallControl.xaml.cs +++ b/src/BreCalClient/EditShipcallControl.xaml.cs @@ -115,31 +115,31 @@ namespace BreCalClient private void contextMenuItemClearAgency_Click(object sender, RoutedEventArgs e) { this.comboBoxAgency.SelectedIndex = -1; - this.ShipcallModel.AssignedParticipants.Remove((int)Extensions.ParticipantType.AGENCY); + this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.AGENCY); } private void contextMenuItemClearMooring_Click(object sender, RoutedEventArgs e) { this.comboBoxMooring.SelectedIndex = -1; - this.ShipcallModel.AssignedParticipants.Remove((int)Extensions.ParticipantType.MOORING); + this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.MOORING); } private void contextMenuItemClearPilot_Click(object sender, RoutedEventArgs e) { this.comboBoxPilot.SelectedIndex = -1; - this.ShipcallModel.AssignedParticipants.Remove((int)Extensions.ParticipantType.PILOT); + this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.PILOT); } private void contextMenuItemClearTug_Click(object sender, RoutedEventArgs e) { this.comboBoxTug.SelectedIndex = -1; - this.ShipcallModel.AssignedParticipants.Remove((int)Extensions.ParticipantType.TUG); + this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.TUG); } private void contextMenuItemClearTerminal_Click(object sender, RoutedEventArgs e) { this.comboBoxTerminal.SelectedIndex = -1; - this.ShipcallModel.AssignedParticipants.Remove((int)Extensions.ParticipantType.TERMINAL); + this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.TERMINAL); } private void contextMenuItemArrivalBerth_Click(object sender, RoutedEventArgs e) @@ -195,29 +195,29 @@ namespace BreCalClient if (participant != null) { this.ShipcallModel.Shipcall.Participants.Add(participant.Id); - this.ShipcallModel.AssignedParticipants[participant.Type] = participant; + this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.AGENCY] = participant; } participant = (Participant?)this.comboBoxMooring.SelectedItem; if (participant != null) { this.ShipcallModel.Shipcall.Participants.Add(participant.Id); - this.ShipcallModel.AssignedParticipants[participant.Type] = participant; + this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.MOORING] = participant; } participant = (Participant?)this.comboBoxPilot.SelectedItem; if (participant != null) { this.ShipcallModel.Shipcall.Participants.Add(participant.Id); - this.ShipcallModel.AssignedParticipants[participant.Type] = participant; + this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.PILOT] = participant; } participant = (Participant?)this.comboBoxTerminal.SelectedItem; if (participant != null) { this.ShipcallModel.Shipcall.Participants.Add(participant.Id); - this.ShipcallModel.AssignedParticipants[participant.Type] = participant; + this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.TERMINAL] = participant; } participant = (Participant?)this.comboBoxTug.SelectedItem; if (participant != null) { this.ShipcallModel.Shipcall.Participants.Add(participant.Id); - this.ShipcallModel.AssignedParticipants[participant.Type] = participant; + this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.TUG] = participant; } // BSMD and port authority are always added @@ -226,12 +226,12 @@ namespace BreCalClient if (p.Type == (int)Extensions.ParticipantType.PORT_ADMINISTRATION) { this.ShipcallModel.Shipcall.Participants.Add(p.Id); - this.ShipcallModel.AssignedParticipants[p.Type] = p; + this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.PORT_ADMINISTRATION] = p; } if (p.Type == (int)Extensions.ParticipantType.BSMD) { this.ShipcallModel.Shipcall.Participants.Add(p.Id); - this.ShipcallModel.AssignedParticipants[p.Type] = p; + this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.BSMD] = p; } } } diff --git a/src/BreCalClient/EditTimesControl.xaml b/src/BreCalClient/EditTimesControl.xaml index 4bac332..39de9a5 100644 --- a/src/BreCalClient/EditTimesControl.xaml +++ b/src/BreCalClient/EditTimesControl.xaml @@ -8,7 +8,7 @@ xmlns:db="clr-namespace:BreCalClient;assembly=BreCalClient" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" mc:Ignorable="d" - Title="{x:Static p:Resources.textEditTimes}" Height="280" Width="400" Loaded="Window_Loaded" ResizeMode="NoResize" Icon="Resources/containership.ico"> + Title="{x:Static p:Resources.textEditTimes}" Height="265" Width="400" Loaded="Window_Loaded" ResizeMode="NoResize" Icon="Resources/containership.ico"> diff --git a/src/BreCalClient/EditTimesTerminalControl.xaml b/src/BreCalClient/EditTimesTerminalControl.xaml index 28411fe..e93115d 100644 --- a/src/BreCalClient/EditTimesTerminalControl.xaml +++ b/src/BreCalClient/EditTimesTerminalControl.xaml @@ -7,7 +7,7 @@ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:local="clr-namespace:BreCalClient" mc:Ignorable="d" - Title="{x:Static p:Resources.textEditTimes}" Loaded="Window_Loaded" Height="280" Width="400" > + Title="{x:Static p:Resources.textEditTimes}" Loaded="Window_Loaded" Height="295" Width="400" > @@ -19,7 +19,7 @@ - + @@ -32,7 +32,7 @@ diff --git a/src/BreCalClient/ShipcallControl.xaml.cs b/src/BreCalClient/ShipcallControl.xaml.cs index ec58724..ca2e298 100644 --- a/src/BreCalClient/ShipcallControl.xaml.cs +++ b/src/BreCalClient/ShipcallControl.xaml.cs @@ -5,6 +5,7 @@ using BreCalClient.misc.Model; using System; using System.Collections.Generic; +using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -32,7 +33,7 @@ namespace BreCalClient public event Action? EditRequested; - internal event Action? EditTimesRequested; + internal event Action? EditTimesRequested; #endregion @@ -48,6 +49,11 @@ namespace BreCalClient /// public Dictionary? ParticipantDict { get; set; } + /// + /// For berth name lookup + /// + public List? Berths {get; set;} + #endregion #region public methods @@ -150,46 +156,48 @@ namespace BreCalClient if (this.ShipcallControlModel != null) { foreach (Times times in this.ShipcallControlModel.Times) - { - if(this.ParticipantDict.ContainsKey(times.ParticipantId)) + { + if (times.ParticipantType == (int)Extensions.ParticipantType.AGENCY) { - if (this.ParticipantDict[times.ParticipantId].IsTypeFlagSet(Extensions.ParticipantType.AGENCY)) - { - this.labelAgencyETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.labelAgencyETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockAgencyRemarks.Text = times.Remarks; - } - if (this.ParticipantDict[times.ParticipantId].IsTypeFlagSet(Extensions.ParticipantType.MOORING)) - { - this.labelMooringETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.labelMooringETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockMooringRemarks.Text = times.Remarks; - } - if (this.ParticipantDict[times.ParticipantId].IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION)) - { - this.labelPortAuthorityETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.labelPortAuthorityETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockPortAuthorityRemarks.Text = times.Remarks; - } - if (this.ParticipantDict[times.ParticipantId].IsTypeFlagSet(Extensions.ParticipantType.PILOT)) - { - this.labelPilotETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.labelPilotETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockPilotRemarks.Text = times.Remarks; - } - if (this.ParticipantDict[times.ParticipantId].IsTypeFlagSet(Extensions.ParticipantType.TUG)) - { - this.labelTugETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.labelTugETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockTugRemarks.Text = times.Remarks; - } - if (this.ParticipantDict[times.ParticipantId].IsTypeFlagSet(Extensions.ParticipantType.TERMINAL)) - { - this.labelTerminalETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.labelTerminalETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockTerminalRemarks.Text = times.Remarks; - } + this.labelAgencyETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.labelAgencyETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockAgencyRemarks.Text = times.Remarks; } + if (times.ParticipantType == (int) Extensions.ParticipantType.MOORING) + { + this.labelMooringETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.labelMooringETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockMooringRemarks.Text = times.Remarks; + } + if (times.ParticipantType == (int)Extensions.ParticipantType.PORT_ADMINISTRATION) + { + this.labelPortAuthorityETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.labelPortAuthorityETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockPortAuthorityRemarks.Text = times.Remarks; + } + if (times.ParticipantType == (int)Extensions.ParticipantType.PILOT) + { + this.labelPilotETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.labelPilotETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockPilotRemarks.Text = times.Remarks; + } + if (times.ParticipantType == (int)Extensions.ParticipantType.TUG) + { + this.labelTugETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.labelTugETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockTugRemarks.Text = times.Remarks; + } + if (times.ParticipantType == (int)Extensions.ParticipantType.TERMINAL) + { + if (this.Berths != null) + { + Berth? berth = this.Berths.Find((x) => x.Id == times.BerthId); + this.labelTerminalBerth.Content = (berth != null) ? berth.Name : ""; + } + this.labelOperationsStart.Content = times.OperationsStart.HasValue ? times.OperationsStart.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.labelOperationsEnd.Content = times.OperationsEnd.HasValue ? times.OperationsEnd.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockTerminalRemarks.Text = times.Remarks; + } } } } @@ -220,8 +228,7 @@ namespace BreCalClient { if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == this.ShipcallControlModel?.GetParticipantIdForType(Extensions.ParticipantType.AGENCY))) { - Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY); - this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.AGENCY); + this.EditRequested?.Invoke(this); } } diff --git a/src/BreCalClient/ShipcallControlModel.cs b/src/BreCalClient/ShipcallControlModel.cs index 78b4f30..0d39601 100644 --- a/src/BreCalClient/ShipcallControlModel.cs +++ b/src/BreCalClient/ShipcallControlModel.cs @@ -47,7 +47,7 @@ namespace BreCalClient public string? Berth { get; set; } - public Dictionary AssignedParticipants { get; } = new(); + internal Dictionary AssignedParticipants { get; } = new(); public List Times { get; set; } = new(); @@ -86,11 +86,15 @@ namespace BreCalClient { foreach (int participantId in Shipcall.Participants) { - foreach(Participant participant in participants) + Participant? participant = participants.Find((x) => x.Id == participantId); + if (participant != null) { - if(participant.Id == participantId) - AssignedParticipants[participant.Type] = participant; - } + foreach(Extensions.ParticipantType participantType in Enum.GetValues(typeof(Extensions.ParticipantType))) + { + if(participant.IsTypeFlagSet(participantType)) + AssignedParticipants[participantType] = participant; + } + } } } } @@ -98,11 +102,11 @@ namespace BreCalClient internal Times? GetTimesForParticipantType(Extensions.ParticipantType type) { - if (AssignedParticipants.ContainsKey((int)type)) { - int participantId = AssignedParticipants[(int)type].Id; + if (AssignedParticipants.ContainsKey(type)) { + int participantId = AssignedParticipants[type].Id; foreach (Times times in this.Times) { - if (times.ParticipantId == participantId) + if ((times.ParticipantId == participantId) && (times.ParticipantType == (int) type)) return times; } } diff --git a/src/server/BreCal/impl/times.py b/src/server/BreCal/impl/times.py index feac7e5..def3cfe 100644 --- a/src/server/BreCal/impl/times.py +++ b/src/server/BreCal/impl/times.py @@ -20,7 +20,7 @@ def GetTimes(options): commands = pydapper.using(pooledConnection) data = commands.query("SELECT id, eta_berth, eta_berth_fixed, etd_berth, etd_berth_fixed, lock_time, lock_time_fixed, " + "zone_entry, zone_entry_fixed, operations_start, operations_end, remarks, shipcall_id, participant_id, " + - "berth_id, berth_info, pier_side, created, modified FROM times " + + "berth_id, berth_info, pier_side, participant_type, created, modified FROM times " + "WHERE times.shipcall_id = ?scid?", model=model.Times, param={"scid" : options["shipcall_id"]}) pooledConnection.close() diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py index 464e501..9671492 100644 --- a/src/server/BreCal/schemas/model.py +++ b/src/server/BreCal/schemas/model.py @@ -146,6 +146,7 @@ class TimesSchema(Schema): berth_info = fields.String(Required = False, allow_none=True) pier_side = fields.Bool(Required = False, allow_none = True) shipcall_id = fields.Int(Required = True) + participant_type = fields.Int(Required = False, allow_none=True) created = fields.DateTime(Required = False, allow_none=True) modified = fields.DateTime(Required = False, allow_none=True) @@ -181,6 +182,7 @@ class Times: berth_id: int berth_info: str pier_side: bool + participant_type: int shipcall_id: int created: datetime modified: datetime