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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Data; using System.Windows.Data;
using UCalc.Models; 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 class NegateConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+3
View File
@@ -64,6 +64,9 @@ namespace UCalc.Controls
case Label label: case Label label:
label.Foreground = foreground; label.Foreground = foreground;
break; break;
case TextBlock block:
block.Foreground = foreground;
break;
case Path path: case Path path:
path.Fill = foreground; path.Fill = foreground;
break; break;
+20 -2
View File
@@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UCalc.Data; using UCalc.Data;
@@ -13,13 +14,16 @@ namespace UCalc.Models
protected override string ValidateValue() protected override string ValidateValue()
{ {
var affectedFlats = ((CostProperty) Parent).AffectedFlats;
using var validator = Model.BeginValidation(); using var validator = Model.BeginValidation();
validator.Validate(((CostProperty) Parent).AffectedFlats); validator.Validate(affectedFlats);
return ""; return "";
} }
} }
public class AffectedFlatsProperty : Property public class AffectedFlatsProperty : Property, IReadOnlyCollection<FlatProperty>
{ {
private const string NoFlatsError = "Betroffene Wohnungen: Es wurde keine Wohnung zugewiesen."; private const string NoFlatsError = "Betroffene Wohnungen: Es wurde keine Wohnung zugewiesen.";
private readonly HashSet<FlatProperty> _flats; private readonly HashSet<FlatProperty> _flats;
@@ -81,7 +85,21 @@ namespace UCalc.Models
using var validator = Model.BeginValidation(); using var validator = Model.BeginValidation();
validator.Notify(this, "Errors"); 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 public class CostProperty : NestedProperty
+12
View File
@@ -285,6 +285,18 @@ namespace UCalc.Models
validator.ValidateRange(_properties); 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) public sealed override void OnPropertyChanged(string propertyName = null)
{ {
switch (propertyName) switch (propertyName)
+11 -5
View File
@@ -7,10 +7,11 @@
xmlns:local="clr-namespace:UCalc" xmlns:local="clr-namespace:UCalc"
xmlns:pages="clr-namespace:UCalc.Pages" xmlns:pages="clr-namespace:UCalc.Pages"
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<controls:EmptyMultiPropertyToVisibilityConverter x:Key="EmptyMultiPropertyToVisibilityConverter" /> <controls:EmptyMultiPropertyToVisibilityConverter x:Key="EmptyMultiPropertyToVisibilityConverter" />
<controls:NameToTextConverter x:Key="NameToTextConverter" /> <controls:NameToTextConverter x:Key="NameToTextConverter" />
<controls:CostToAffectedConverter x:Key="CostToAffectedConverter" />
</Page.Resources> </Page.Resources>
<DockPanel> <DockPanel>
@@ -88,8 +89,13 @@
DockPanel.Dock="Left" DockPanel.Dock="Left"
Margin="12, 12, 8, 12" /> Margin="12, 12, 8, 12" />
<Label Content="{Binding Path=Name.Value, Converter={StaticResource NameToTextConverter}}" <TextBlock VerticalAlignment="Center">
VerticalAlignment="Center" /> <Run
Text="{Binding Path=Name.Value, Converter={StaticResource NameToTextConverter}}" />
<LineBreak />
<Run
Text="{Binding Path=., Converter={StaticResource CostToAffectedConverter}}" />
</TextBlock>
</controls:HighlightButton> </controls:HighlightButton>
</DockPanel> </DockPanel>
</DataTemplate> </DataTemplate>
@@ -97,5 +103,5 @@
</ItemsControl> </ItemsControl>
</ScrollViewer> </ScrollViewer>
</DockPanel> </DockPanel>
</Page> </Page>