allow read-only views of not-assigned participants of any data

This commit is contained in:
Daniel Schick 2023-10-10 11:50:43 +02:00
parent ebfa7c1fc7
commit 02705f2677
7 changed files with 180 additions and 54 deletions

View File

@ -44,6 +44,23 @@ namespace BreCalClient
this.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths; this.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths;
this.CopyToControls(); this.CopyToControls();
Participant? p = null;
if(this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY))
p = BreCalLists.Participants.Find(x => x.Id == this.ShipcallModel.AssignedParticipants[ParticipantType.AGENCY].ParticipantId);
bool allowBSMD = false;
if (p != null)
{
allowBSMD = p.IsFlagSet(ParticipantFlag.ALLOW_BSMD);
}
bool enableControls = (this.Times.ParticipantId == App.Participant.Id) ||
(App.Participant.IsTypeFlagSet(ParticipantType.BSMD) && allowBSMD);
this.EnableControls(enableControls);
} }
private void buttonOK_Click(object sender, RoutedEventArgs e) private void buttonOK_Click(object sender, RoutedEventArgs e)
@ -220,6 +237,32 @@ namespace BreCalClient
} }
} }
private void EnableControls(bool isEnabled)
{
this.datePickerETA.IsEnabled = isEnabled;
this.comboBoxArrivalBerth.IsEnabled = isEnabled;
this.comboBoxPierside.IsEnabled = isEnabled;
this.textBoxBerthRemarks.IsEnabled = isEnabled;
this.doubleUpDownDraft.IsEnabled = isEnabled;
this.datePickerTidalWindowFrom.IsEnabled = isEnabled;
this.datePickerTidalWindowTo.IsEnabled = isEnabled;
this.checkBoxCanceled.IsEnabled = isEnabled;
this.checkBoxAnchored.IsEnabled = isEnabled;
this.checkBoxTugRequired.IsEnabled = isEnabled;
this.comboBoxTug.IsEnabled = isEnabled;
this.integerUpDownRecommendedTugs.IsEnabled = isEnabled;
this.checkBoxPilotRequired.IsEnabled = isEnabled;
this.comboBoxPilot.IsEnabled = isEnabled;
this.comboBoxMooring.IsEnabled = isEnabled;
this.checkBoxMooredLock.IsEnabled = isEnabled;
this.comboBoxTerminal.IsEnabled = isEnabled;
this.checkBoxBunkering.IsEnabled = isEnabled;
this.checkBoxReplenishingTerminal.IsEnabled = isEnabled;
this.checkBoxReplenishingLock.IsEnabled = isEnabled;
this.textBoxRemarks.IsEnabled = isEnabled;
}
#endregion #endregion
#region context menu handlers #region context menu handlers

View File

@ -45,6 +45,22 @@ namespace BreCalClient
this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths; this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths;
this.CopyToControls(); this.CopyToControls();
Participant? p = null;
if (this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY))
p = BreCalLists.Participants.Find(x => x.Id == this.ShipcallModel.AssignedParticipants[ParticipantType.AGENCY].ParticipantId);
bool allowBSMD = false;
if (p != null)
{
allowBSMD = p.IsFlagSet(ParticipantFlag.ALLOW_BSMD);
}
bool enableControls = (this.Times.ParticipantId == App.Participant.Id) ||
(App.Participant.IsTypeFlagSet(ParticipantType.BSMD) && allowBSMD);
this.EnableControls(enableControls);
} }
private void buttonOK_Click(object sender, RoutedEventArgs e) private void buttonOK_Click(object sender, RoutedEventArgs e)
@ -210,6 +226,29 @@ namespace BreCalClient
} }
} }
private void EnableControls(bool isEnabled)
{
this.datePickerETD.IsEnabled = isEnabled;
this.comboBoxDepartureBerth.IsEnabled = isEnabled;
this.comboBoxPierside.IsEnabled = isEnabled;
this.textBoxBerthRemarks.IsEnabled = isEnabled;
this.doubleUpDownDraft.IsEnabled = isEnabled;
this.datePickerTidalWindowFrom.IsEnabled = isEnabled;
this.datePickerTidalWindowTo.IsEnabled = isEnabled;
this.checkBoxCanceled.IsEnabled = isEnabled;
this.checkBoxTugRequired.IsEnabled = isEnabled;
this.comboBoxTug.IsEnabled = isEnabled;
this.integerUpDownRecommendedTugs.IsEnabled = isEnabled;
this.checkBoxPilotRequired.IsEnabled = isEnabled;
this.comboBoxPilot.IsEnabled = isEnabled;
this.comboBoxMooring.IsEnabled = isEnabled;
this.checkBoxMooredLock.IsEnabled = isEnabled;
this.comboBoxTerminal.IsEnabled = isEnabled;
this.checkBoxRainsensitiveCargo.IsEnabled = isEnabled;
this.textBoxRemarks.IsEnabled = isEnabled;
}
#endregion #endregion
#region context menu handlers #region context menu handlers

View File

@ -46,6 +46,22 @@ namespace BreCalClient
this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths; this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths;
this.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths; this.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths;
this.CopyToControls(); this.CopyToControls();
Participant? p = null;
if (this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY))
p = BreCalLists.Participants.Find(x => x.Id == this.ShipcallModel.AssignedParticipants[ParticipantType.AGENCY].ParticipantId);
bool allowBSMD = false;
if (p != null)
{
allowBSMD = p.IsFlagSet(ParticipantFlag.ALLOW_BSMD);
}
bool enableControls = (this.Times.ParticipantId == App.Participant.Id) ||
(App.Participant.IsTypeFlagSet(ParticipantType.BSMD) && allowBSMD);
this.EnableControls(enableControls);
} }
private void buttonOK_Click(object sender, RoutedEventArgs e) private void buttonOK_Click(object sender, RoutedEventArgs e)
@ -226,6 +242,31 @@ namespace BreCalClient
} }
} }
private void EnableControls(bool isEnabled)
{
this.datePickerETD.IsEnabled = isEnabled;
this.comboBoxArrivalBerth.IsEnabled = isEnabled;
this.doubleUpDownDraft.IsEnabled = isEnabled;
this.datePickerTidalWindowFrom.IsEnabled = isEnabled;
this.datePickerTidalWindowTo.IsEnabled = isEnabled;
this.datePickerETA.IsEnabled = isEnabled;
this.comboBoxDepartureBerth.IsEnabled = isEnabled;
this.comboBoxPiersideArrival.IsEnabled = isEnabled;
this.textBoxBerthRemarksArrival.IsEnabled = isEnabled;
this.checkBoxCanceled.IsEnabled = isEnabled;
this.checkBoxTugRequired.IsEnabled = isEnabled;
this.comboBoxTug.IsEnabled = isEnabled;
this.integerUpDownRecommendedTugs.IsEnabled = isEnabled;
this.checkBoxPilotRequired.IsEnabled = isEnabled;
this.comboBoxPilot.IsEnabled = isEnabled;
this.comboBoxMooring.IsEnabled = isEnabled;
this.checkBoxMooredLock.IsEnabled = isEnabled;
this.comboBoxTerminal.IsEnabled = isEnabled;
this.checkBoxRainsensitiveCargo.IsEnabled = isEnabled;
this.textBoxRemarks.IsEnabled = isEnabled;
}
#endregion #endregion
#region context menu handlers #region context menu handlers

View File

@ -36,26 +36,19 @@ namespace BreCalClient
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
this.CopyToControls(); this.CopyToControls();
// enable controls according to participant type bool enableControls = this.Times.ParticipantId == App.Participant.Id;
this.datePickerETABerth.IsEnabled = App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) ||
App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) ||
App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) ||
App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) ||
App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG);
this.datePickerETABerth.IsEnabled = enableControls;
this.checkBoxEtaBerthFixed.IsEnabled = this.datePickerETABerth.IsEnabled; this.checkBoxEtaBerthFixed.IsEnabled = enableControls;
this.datePickerETDBerth.IsEnabled = this.datePickerETABerth.IsEnabled; this.datePickerETDBerth.IsEnabled = enableControls;
this.checkBoxEtDBerthFixed.IsEnabled = this.datePickerETABerth.IsEnabled; this.checkBoxEtDBerthFixed.IsEnabled = enableControls;
this.datePickerLockTime.IsEnabled = enableControls;
this.checkBoxLockTimeFixed.IsEnabled = enableControls;
this.datePickerZoneEntry.IsEnabled = enableControls;
this.checkBoxZoneEntryFixed.IsEnabled = enableControls;
this.textBoxRemarks.IsEnabled = enableControls;
this.buttonOK.IsEnabled = enableControls;
this.datePickerLockTime.IsEnabled = App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) ||
App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) ||
App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION);
this.checkBoxLockTimeFixed.IsEnabled = this.datePickerLockTime.IsEnabled;
this.datePickerZoneEntry.IsEnabled = App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) ||
App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT);
this.checkBoxZoneEntryFixed.IsEnabled = this.datePickerZoneEntry.IsEnabled;
} }
private void buttonOK_Click(object sender, RoutedEventArgs e) private void buttonOK_Click(object sender, RoutedEventArgs e)

View File

@ -29,6 +29,15 @@ namespace BreCalClient
{ {
this.comboBoxBerth.ItemsSource = BreCalLists.Berths; this.comboBoxBerth.ItemsSource = BreCalLists.Berths;
this.CopyToControls(); this.CopyToControls();
bool enableControls = this.Times.ParticipantId == App.Participant.Id;
this.datePickerOperationStart.IsEnabled = enableControls;
this.datePickerOperationEnd.IsEnabled = enableControls;
this.comboBoxBerth.IsEnabled = enableControls;
this.comboBoxPierside.IsEnabled = enableControls;
this.textBoxRemarks.IsEnabled = enableControls;
this.textBoxBerthRemarks.IsEnabled = enableControls;
this.buttonOK.IsEnabled = enableControls;
} }
private void contextMenuItemClearOperationStart_Click(object sender, RoutedEventArgs e) private void contextMenuItemClearOperationStart_Click(object sender, RoutedEventArgs e)

View File

@ -560,8 +560,13 @@ namespace BreCalClient
private async void Sc_EditTimesRequested(ShipcallControl obj, Times? times, Extensions.ParticipantType participantType) private async void Sc_EditTimesRequested(ShipcallControl obj, Times? times, Extensions.ParticipantType participantType)
{ {
if( obj.ShipcallControlModel == null) { return; }
if (!obj.ShipcallControlModel.AssignedParticipants.ContainsKey(participantType)) return; // no assigment means no dialog my friend
// show a dialog that lets the user create / update times for the given shipcall // show a dialog that lets the user create / update times for the given shipcall
IEditTimesControl etc = (participantType == ParticipantType.TERMINAL) ? new EditTimesTerminalControl() : new EditTimesControl(); IEditTimesControl etc = (participantType == ParticipantType.TERMINAL) ? new EditTimesTerminalControl() : new EditTimesControl();
bool wasEdit = false; bool wasEdit = false;
if (times != null) if (times != null)
@ -569,6 +574,13 @@ namespace BreCalClient
etc.Times = times; etc.Times = times;
wasEdit = true; wasEdit = true;
} }
else
{
if(obj.ShipcallControlModel.AssignedParticipants[participantType].ParticipantId == App.Participant.Id)
{
etc.Times.ParticipantId = App.Participant.Id; // this is my record, so the Participant Id is set that allows editing
}
}
// actually we should only do this on create but we have existing data // actually we should only do this on create but we have existing data
etc.Times.ParticipantType = (int) participantType; etc.Times.ParticipantType = (int) participantType;
@ -632,7 +644,15 @@ namespace BreCalClient
{ {
try try
{ {
editControl.Times.ParticipantId = App.Participant.Id; // always try to be the agent, even if we are BSMD
if (editControl.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY))
{
editControl.Times.ParticipantId = editControl.ShipcallModel.AssignedParticipants[ParticipantType.AGENCY].ParticipantId;
}
else
{
editControl.Times.ParticipantId = App.Participant.Id;
}
if (wasEdit) if (wasEdit)
{ {

View File

@ -270,13 +270,13 @@ namespace BreCalClient
private void UserControl_Loaded(object sender, RoutedEventArgs e) private void UserControl_Loaded(object sender, RoutedEventArgs e)
{ {
// TBD
} }
private void buttonEditShipcall_Click(object? sender, RoutedEventArgs? e) private void buttonEditShipcall_Click(object? sender, RoutedEventArgs? e)
{ {
if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD)) if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD))
this.EditRequested?.Invoke(this); this.EditRequested?.Invoke(this);
} }
private void Image_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void Image_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
@ -285,58 +285,39 @@ namespace BreCalClient
} }
private void labelAgent_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelAgent_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if ((App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == _agency?.Id)) || Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY);
(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD) && (_agency != null) && _agency.IsFlagSet(Extensions.ParticipantFlag.ALLOW_BSMD))) this.EditAgencyRequested?.Invoke(this, times);
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY);
this.EditAgencyRequested?.Invoke(this, times);
}
} }
private void labelMooring_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelMooring_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) && (App.Participant.Id == _mooring?.Id)) Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.MOORING);
{ this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.MOORING);
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.MOORING);
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.MOORING);
}
} }
private void labelPortAuthority_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelPortAuthority_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) && (App.Participant.Id == _port_administration?.Id)) Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PORT_ADMINISTRATION);
{ this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PORT_ADMINISTRATION);
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PORT_ADMINISTRATION);
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PORT_ADMINISTRATION);
}
} }
private void labelPilot_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelPilot_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) && (App.Participant.Id == _pilot?.Id)) Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PILOT);
{ this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PILOT);
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PILOT);
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PILOT);
}
} }
private void labelTug_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelTug_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG) && (App.Participant.Id == _tug?.Id)) Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TUG);
{ this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TUG);
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TUG);
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TUG);
}
} }
private void labelTerminal_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelTerminal_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TERMINAL) && (App.Participant.Id == _terminal?.Id)) Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL);
{ this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TERMINAL);
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL);
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TERMINAL);
}
} }
#endregion #endregion