Changed cost page to view affected flats together with the name.

This commit is contained in:
Tobias Erbshäußer
2020-06-16 15:27:43 +02:00
parent 69cb2c924a
commit f566911d31
5 changed files with 77 additions and 7 deletions
+31
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using UCalc.Models;
@@ -149,6 +150,36 @@ namespace UCalc.Controls
}
}
public class CostToAffectedConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var cost = (CostProperty) value;
if (cost == null)
{
return "";
}
if (cost.AffectsAll.Value)
{
return "Betrifft: Alle Wohnungen";
}
if (cost.AffectedFlats.Count == 0)
{
return "Betrifft: Niemanden";
}
return $"Betrifft: {string.Join(", ", cost.AffectedFlats.Select(flat => flat.Name.Value))}";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new InvalidOperationException();
}
}
public class NegateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+3
View File
@@ -64,6 +64,9 @@ namespace UCalc.Controls
case Label label:
label.Foreground = foreground;
break;
case TextBlock block:
block.Foreground = foreground;
break;
case Path path:
path.Fill = foreground;
break;
+20 -2
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UCalc.Data;
@@ -13,13 +14,16 @@ namespace UCalc.Models
protected override string ValidateValue()
{
var affectedFlats = ((CostProperty) Parent).AffectedFlats;
using var validator = Model.BeginValidation();
validator.Validate(((CostProperty) Parent).AffectedFlats);
validator.Validate(affectedFlats);
return "";
}
}
public class AffectedFlatsProperty : Property
public class AffectedFlatsProperty : Property, IReadOnlyCollection<FlatProperty>
{
private const string NoFlatsError = "Betroffene Wohnungen: Es wurde keine Wohnung zugewiesen.";
private readonly HashSet<FlatProperty> _flats;
@@ -81,7 +85,21 @@ namespace UCalc.Models
using var validator = Model.BeginValidation();
validator.Notify(this, "Errors");
Model.Root.Costs.NotifyChanged((CostProperty) Parent);
}
public IEnumerator<FlatProperty> GetEnumerator()
{
return _flats.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public int Count => _flats.Count;
}
public class CostProperty : NestedProperty
+12
View File
@@ -285,6 +285,18 @@ namespace UCalc.Models
validator.ValidateRange(_properties);
}
public void NotifyChanged(T property)
{
var index = _properties.IndexOf(property);
if (index == -1)
{
return;
}
CollectionChanged?.Invoke(this,
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
public sealed override void OnPropertyChanged(string propertyName = null)
{
switch (propertyName)
+8 -2
View File
@@ -11,6 +11,7 @@
<Page.Resources>
<controls:EmptyMultiPropertyToVisibilityConverter x:Key="EmptyMultiPropertyToVisibilityConverter" />
<controls:NameToTextConverter x:Key="NameToTextConverter" />
<controls:CostToAffectedConverter x:Key="CostToAffectedConverter" />
</Page.Resources>
<DockPanel>
@@ -88,8 +89,13 @@
DockPanel.Dock="Left"
Margin="12, 12, 8, 12" />
<Label Content="{Binding Path=Name.Value, Converter={StaticResource NameToTextConverter}}"
VerticalAlignment="Center" />
<TextBlock VerticalAlignment="Center">
<Run
Text="{Binding Path=Name.Value, Converter={StaticResource NameToTextConverter}}" />
<LineBreak />
<Run
Text="{Binding Path=., Converter={StaticResource CostToAffectedConverter}}" />
</TextBlock>
</controls:HighlightButton>
</DockPanel>
</DataTemplate>