Skip to content

Commit

Permalink
Dont allow changing of selection within applicant details because the…
Browse files Browse the repository at this point in the history
… lists don't update properly and a major refactor would be required to fix it
  • Loading branch information
davidlang42 committed Nov 27, 2023
1 parent 7f89c6f commit 134610d
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 180 deletions.
30 changes: 30 additions & 0 deletions Desktop/Converters/CollapsedIfNull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace Carmen.Desktop.Converters
{
/// <summary>
/// Convert an object value to a Visibility based on whether or not it is null.
/// If ConverterParameter is set to a type, then the value must be this type to be considered not null.
/// </summary>
public class CollapsedIfNull : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return Visibility.Collapsed;
if (parameter is Type type && !(value.GetType() == type || value.GetType().IsSubclassOf(type)))
return Visibility.Collapsed;
return Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
}
4 changes: 2 additions & 2 deletions Desktop/Converters/HideIfNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class HideIfNull : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return Visibility.Hidden;
return Visibility.Collapsed;
if (parameter is Type type && !(value.GetType() == type || value.GetType().IsSubclassOf(type)))
return Visibility.Hidden;
return Visibility.Collapsed;
return Visibility.Visible;
}

Expand Down
33 changes: 7 additions & 26 deletions Desktop/Pages/SelectCast.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,38 +441,16 @@ private async Task RemoveFromList(IList list, Applicant[] applicants)

private void List_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//TODO changing the selection status via >/>>/</<< doesn't update details window
var list_box = (ListBox)sender;
if (list_box.SelectedItem is not Applicant applicant)
return;
if (selectionList.SelectedItem is CastGroup cg)
{
ShowDetailsWindow(new ApplicantForCastGroup(applicant, criterias, cg));
e.Handled = true;
}
else if (selectionList.SelectedItem is AlternativeCast ac)
if (list_box.SelectedItem is Applicant applicant)
{
ShowDetailsWindow(new ApplicantForAlternativeCast(applicant, criterias, ac));
e.Handled = true;
}
else if (selectionList.SelectedItem is Tag tag)
{
ShowDetailsWindow(new ApplicantForTag(applicant, criterias, tag));
ShowDetailsWindow(new ApplicantForSelection(applicant, criterias));
e.Handled = true;
}
}

Dictionary<Applicant, ApplicantDetailsWindow> detailsWindows = new();

void CloseDetailsWindows()
{
foreach (var window in detailsWindows.Values)
{
window.Close();
}
detailsWindows.Clear();
}

void ShowDetailsWindow(ApplicantForSelection afs)
{
if (!detailsWindows.TryGetValue(afs.Applicant, out var window) || window.IsClosed)
Expand All @@ -491,7 +469,11 @@ void ShowDetailsWindow(ApplicantForSelection afs)

protected override void DisposeInternal()
{
CloseDetailsWindows();
foreach (var window in detailsWindows.Values)
{
window.Close();
}
detailsWindows.Clear();
base.DisposeInternal();
}

Expand Down Expand Up @@ -549,7 +531,6 @@ private void selectionList_SelectionChanged(object sender, SelectionChangedEvent
{
if (suitabilityComparer != null)
suitabilityComparer.SelectedCastGroupOrTag = selectionList.SelectedItem;
CloseDetailsWindows();
RefreshMainPanel();
}

Expand Down
49 changes: 0 additions & 49 deletions Desktop/ViewModels/ApplicantForAlternativeCast.cs

This file was deleted.

49 changes: 0 additions & 49 deletions Desktop/ViewModels/ApplicantForCastGroup.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Desktop/ViewModels/ApplicantForRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public IEnumerable<string> UnavailabilityReasons

public string CommaSeparatedIneligibilityReason => string.Join(", ", IneligibilityReasons);

public string SelectionText => $"Allocate {RoleName} to {FirstName}";
public string? SelectionText => $"Allocate {RoleName} to {FirstName}";

public ApplicantForRole(IAllocationEngine engine, Applicant applicant, Role role, Criteria[] primary_criterias)
{
Expand Down
12 changes: 8 additions & 4 deletions Desktop/ViewModels/ApplicantForSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@

namespace Carmen.Desktop.ViewModels
{
public abstract class ApplicantForSelection : ISelectableApplicant, INotifyPropertyChanged
public class ApplicantForSelection : ISelectableApplicant, INotifyPropertyChanged
{
public Applicant Applicant { get; init; }
public Criteria[] PrimaryCriterias { get; init; }

public event PropertyChangedEventHandler? PropertyChanged;

public abstract bool IsSelected { get; set; }
public bool IsSelected
{
get => true; // so that colour images are shown
set => throw new InvalidOperationException();
}

public string FirstName => Applicant.FirstName;
public string LastName => Applicant.LastName;

public IEnumerable<string> ExistingRoles => Enumerable.Empty<string>();
public IEnumerable<string> UnavailabilityReasons => Enumerable.Empty<string>();
public IEnumerable<string> IneligibilityReasons => Enumerable.Empty<string>(); //TODO populate ineligability
public IEnumerable<string> IneligibilityReasons => Enumerable.Empty<string>();

public abstract string SelectionText { get; }
public string? SelectionText => null; // this hides the checkbox completely

public ApplicantForSelection(Applicant applicant, Criteria[] criterias)
{
Expand Down
47 changes: 0 additions & 47 deletions Desktop/ViewModels/ApplicantForTag.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Desktop/ViewModels/ISelectableApplicant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ISelectableApplicant
bool IsSelected { get; set; }
string FirstName { get; }
string LastName { get; }
string SelectionText { get; }
string? SelectionText { get; }
IEnumerable<string> ExistingRoles { get; }
IEnumerable<string> UnavailabilityReasons { get; }
IEnumerable<string> IneligibilityReasons { get; }
Expand Down
3 changes: 2 additions & 1 deletion Desktop/Windows/ApplicantDetailsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<BooleanToVisibilityConverter/>
</cv:MultiConverter>
<BooleanToVisibilityConverter x:Key="showIfTrue"/>
<cv:CollapsedIfNull x:Key="collapsedIfNull"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -157,7 +158,7 @@
</StackPanel>
</ScrollViewer>
<Grid Grid.Row="2" Margin="5">
<CheckBox IsChecked="{Binding IsSelected}">
<CheckBox IsChecked="{Binding IsSelected}" Visibility="{Binding SelectionText, Converter={StaticResource collapsedIfNull}}">
<TextBlock>
<Run Text="{Binding SelectionText, Mode=OneWay}"/>
</TextBlock>
Expand Down

0 comments on commit 134610d

Please sign in to comment.