[#26] AreaComAdminWindow: Overhaul status bar and search filters
This commit is contained in:
@ -40,8 +40,8 @@ namespace Elwig.Services {
|
||||
List<string> filterNames = [];
|
||||
IQueryable<AreaCom> areaComQuery = ctx.AreaCommitments.Where(a => a.MgNr == vm.FilterMember.MgNr).OrderBy(a => a.FbNr);
|
||||
if (vm.ShowOnlyActiveAreaComs) {
|
||||
areaComQuery = Utils.ActiveAreaCommitments(areaComQuery);
|
||||
filterNames.Add("laufend");
|
||||
areaComQuery = Utils.ActiveAreaCommitments(areaComQuery, Utils.CurrentLastSeason);
|
||||
filterNames.Add($"laufend {Utils.CurrentLastSeason}");
|
||||
}
|
||||
|
||||
var filterVar = new List<string>();
|
||||
@ -53,6 +53,7 @@ namespace Elwig.Services {
|
||||
if (filter.Count > 0) {
|
||||
var var = await ctx.WineVarieties.ToDictionaryAsync(v => v.SortId, v => v);
|
||||
var attr = await ctx.WineAttributes.ToDictionaryAsync(a => a.Name.ToLower().Split(" ")[0], a => a);
|
||||
var attrId = await ctx.WineAttributes.ToDictionaryAsync(a => a.AttrId, a => a);
|
||||
|
||||
for (int i = 0; i < filter.Count; i++) {
|
||||
var e = filter[i];
|
||||
@ -63,6 +64,7 @@ namespace Elwig.Services {
|
||||
} else if (e.Length == 3 && e[0] == '!' && var.ContainsKey(e[1..].ToUpper())) {
|
||||
filterNotVar.Add(e[1..].ToUpper());
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add($"ohne {var[e.ToUpper()].Name}");
|
||||
} else if (attr.ContainsKey(e.ToLower())) {
|
||||
var a = attr[e.ToLower()];
|
||||
filterAttr.Add(a.AttrId);
|
||||
@ -73,13 +75,25 @@ namespace Elwig.Services {
|
||||
filterNotAttr.Add(a.AttrId);
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add($"ohne Attribut {a.Name}");
|
||||
} else if (e.Length > 2 && var.ContainsKey(e.ToUpper()[..2]) && attrId.ContainsKey(e[2..].ToUpper())) {
|
||||
filterVar.Add(e[..2].ToUpper());
|
||||
filterAttr.Add(e[2..].ToUpper());
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add(var[e[..2].ToUpper()].Name);
|
||||
filterNames.Add($"Attribut {attrId[e[2..].ToUpper()].Name}");
|
||||
} else if (e[0] == '!' && e.Length > 3 && var.ContainsKey(e.ToUpper()[1..3]) && attrId.ContainsKey(e[3..].ToUpper())) {
|
||||
filterNotVar.Add(e[1..3].ToUpper());
|
||||
filterNotAttr.Add(e[3..].ToUpper());
|
||||
filter.RemoveAt(i--);
|
||||
filterNames.Add($"ohne {var[e[1..3].ToUpper()].Name}");
|
||||
filterNames.Add($"ohne Attribut {attrId[e[3..].ToUpper()].Name}");
|
||||
}
|
||||
}
|
||||
|
||||
if (filterVar.Count > 0) areaComQuery = areaComQuery.Where(a => filterVar.Contains(a.AreaComType.WineVar.SortId));
|
||||
if (filterNotVar.Count > 0) areaComQuery = areaComQuery.Where(a => !filterNotVar.Contains(a.AreaComType.WineVar.SortId));
|
||||
if (filterAttr.Count > 0) areaComQuery = areaComQuery.Where(a => a.AreaComType.WineAttr != null && a.AreaComType.WineAttr.AttrId != null && filterAttr.Contains(a.AreaComType.WineAttr.AttrId));
|
||||
if (filterNotAttr.Count > 0) areaComQuery = areaComQuery.Where(a => a.AreaComType.WineAttr == null || a.AreaComType.WineAttr.AttrId == null || !filterAttr.Contains(a.AreaComType.WineAttr.AttrId));
|
||||
if (filterAttr.Count > 0) areaComQuery = areaComQuery.Where(a => a.AreaComType.WineAttr!.AttrId != null && filterAttr.Contains(a.AreaComType.WineAttr.AttrId));
|
||||
if (filterNotAttr.Count > 0) areaComQuery = areaComQuery.Where(a => a.AreaComType.WineAttr!.AttrId == null || !filterNotAttr.Contains(a.AreaComType.WineAttr.AttrId));
|
||||
}
|
||||
|
||||
return (filterNames, areaComQuery, filter);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Elwig.Models.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Elwig.ViewModels {
|
||||
public partial class AreaComAdminViewModel : ObservableObject {
|
||||
@ -83,10 +84,12 @@ namespace Elwig.ViewModels {
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private string _statusAreaCommitments = "Flächenbindungen: -";
|
||||
private string _statusAreaCommitments = "-";
|
||||
[ObservableProperty]
|
||||
private string _statusArea = "Fläche: -";
|
||||
private string _statusContracts = "-";
|
||||
[ObservableProperty]
|
||||
private string _statusContracts = "Vertragsarten: -";
|
||||
private string _statusArea = "-";
|
||||
[ObservableProperty]
|
||||
private Grid? _statusAreaToolTip;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
xmlns:local="clr-namespace:Elwig.Windows"
|
||||
xmlns:ctrl="clr-namespace:Elwig.Controls"
|
||||
xmlns:vm="clr-namespace:Elwig.ViewModels"
|
||||
Title="{Binding Title}" Height="500" MinHeight="440" Width="920" MinWidth="860"
|
||||
Title="{Binding Title}" Height="550" MinHeight="450" Width="920" MinWidth="860"
|
||||
Loaded="Window_Loaded">
|
||||
<Window.DataContext>
|
||||
<vm:AreaComAdminViewModel/>
|
||||
@ -51,6 +51,7 @@
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="19"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="24"/>
|
||||
</Grid.RowDefinitions>
|
||||
@ -60,7 +61,10 @@
|
||||
<ColumnDefinition Width="*" MinWidth="280"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Grid.Column="0" Margin="5,0,0,0">
|
||||
<Menu Grid.ColumnSpan="3" BorderThickness="0,0,0,1" BorderBrush="LightGray" Background="White">
|
||||
</Menu>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="0" Margin="5,0,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="35"/>
|
||||
<RowDefinition Height="*"/>
|
||||
@ -73,9 +77,22 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBox x:Name="SearchInput" Text="{Binding SearchQuery, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Grid.ColumnSpan="3" Margin="5,5,140,0" IsReadOnly="False"
|
||||
TextChanged="SearchInput_TextChanged"/>
|
||||
<CheckBox x:Name="ActiveAreaCommitmentInput" Content="Nur aktive anzeigen" IsChecked="{Binding ShowOnlyActiveAreaComs}"
|
||||
Grid.ColumnSpan="3" Margin="5,5,190,0" IsReadOnly="False"
|
||||
TextChanged="SearchInput_TextChanged">
|
||||
<TextBox.ToolTip>
|
||||
<TextBlock>
|
||||
<Bold>Strg+F</Bold><LineBreak/><LineBreak/>
|
||||
Flächenbindungen filtern und durchsuchen. Die Filter sind beliebig kombinierbar.<LineBreak/>
|
||||
Groß- und Kleinschreibung ist in den meisten Fällen egal.<LineBreak/>
|
||||
<LineBreak/>
|
||||
Filtern nach:<LineBreak/>
|
||||
<Bold>Sorte</Bold>: z.B. GV, zw, RR, ...<LineBreak/>
|
||||
<Bold>Attribut</Bold>: z.B. Kabinett, dac, ... <LineBreak/>
|
||||
<Bold>Flächenbindung</Bold>: z.B. GVK, GVD, ...
|
||||
</TextBlock>
|
||||
</TextBox.ToolTip>
|
||||
</TextBox>
|
||||
<CheckBox x:Name="ActiveAreaCommitmentInput" Content="Nur laufende anzeigen (2020)" IsChecked="{Binding ShowOnlyActiveAreaComs}"
|
||||
Checked="ActiveAreaCommitmentInput_Changed" Unchecked="ActiveAreaCommitmentInput_Changed"
|
||||
HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
|
||||
|
||||
@ -94,7 +111,13 @@
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Sorte" Binding="{Binding AreaComType.WineVar.SortId}" Width="70"/>
|
||||
<DataGridTextColumn Header="Sorte" Binding="{Binding AreaComType.WineVar.SortId}" Width="70">
|
||||
<DataGridTextColumn.CellStyle>
|
||||
<Style>
|
||||
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
|
||||
</Style>
|
||||
</DataGridTextColumn.CellStyle>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Attribut" Binding="{Binding AreaComType.WineAttr.Name}" Width="120"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
@ -138,12 +161,12 @@
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<GridSplitter Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
||||
<GridSplitter Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
||||
|
||||
<Grid Grid.Column="2" Grid.Row="0">
|
||||
<Grid Grid.Column="2" Grid.Row="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="1.125*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<GroupBox Header="Vertrag" Grid.Column="2" Grid.Row="0" Grid.RowSpan="1" Margin="5,5,5,5">
|
||||
@ -237,9 +260,9 @@
|
||||
<ItemsPanelTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="160"/>
|
||||
<ColumnDefinition Width="180"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition Width="180"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
@ -247,15 +270,21 @@
|
||||
</ItemsPanelTemplate>
|
||||
</StatusBar.ItemsPanel>
|
||||
<StatusBarItem>
|
||||
<TextBlock Name="StatusAreaCommitments" Text="{Binding StatusAreaCommitments}"/>
|
||||
<TextBlock>
|
||||
Flächenbindungen: <Run Text="{Binding StatusAreaCommitments}"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
<Separator Grid.Column="1"/>
|
||||
<StatusBarItem Grid.Column="2">
|
||||
<TextBlock Name="StatusArea" Text="{Binding StatusArea}"/>
|
||||
<TextBlock ToolTip="{Binding StatusAreaToolTip}">
|
||||
Fläche: <Run Text="{Binding StatusArea}"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
<Separator Grid.Column="3"/>
|
||||
<StatusBarItem Grid.Column="4">
|
||||
<TextBlock Name="StatusContracts" Text="{Binding StatusContracts}"/>
|
||||
<TextBlock>
|
||||
Vertragsarten: <Run Text="{Binding StatusContracts}"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
|
@ -35,6 +35,7 @@ namespace Elwig.Windows {
|
||||
|
||||
InitializeDelayTimer(SearchInput, SearchInput_TextChanged);
|
||||
SearchInput.TextChanged -= SearchInput_TextChanged;
|
||||
ActiveAreaCommitmentInput.Content = ((string)ActiveAreaCommitmentInput.Content).Replace("2020", $"{Utils.CurrentLastSeason}");
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
@ -55,6 +56,9 @@ namespace Elwig.Windows {
|
||||
var areaComs = await areaComQuery
|
||||
.Include(a => a.Kg.AtKg)
|
||||
.Include(a => a.Rd!.Kg.AtKg)
|
||||
.Include(a => a.WineCult)
|
||||
.Include(a => a.AreaComType.WineAttr)
|
||||
.Include(a => a.AreaComType.WineVar)
|
||||
.ToListAsync();
|
||||
|
||||
if (filter.Count > 0 && areaComs.Count > 0) {
|
||||
@ -72,17 +76,21 @@ namespace Elwig.Windows {
|
||||
AreaCommitmentList_SelectionChanged, filter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort);
|
||||
RefreshInputs();
|
||||
|
||||
if(filter.Count == 0) {
|
||||
ViewModel.StatusAreaCommitments = $"Flächenbindungen: {await areaComQuery.CountAsync()}";
|
||||
ViewModel.StatusArea = $"Fläche: {await areaComQuery.Select(a => a.Area).SumAsync():N0} m²";
|
||||
if (filter.Count == 0) {
|
||||
ViewModel.StatusAreaCommitments = $"{await areaComQuery.CountAsync():N0}";
|
||||
var s = await ctx.Seasons.FindAsync(await ctx.Seasons.MaxAsync(s => s.Year));
|
||||
var (text, grid) = await AreaComService.GenerateToolTip(areaComQuery, s?.MaxKgPerHa ?? 10_000);
|
||||
ViewModel.StatusArea = text;
|
||||
ViewModel.StatusAreaToolTip = grid;
|
||||
} else {
|
||||
ViewModel.StatusAreaCommitments = $"Flächenbindungen: {areaComs.Count}";
|
||||
ViewModel.StatusArea = $"Fläche: {areaComs.Select(a => a.Area).Sum():N0} m²";
|
||||
ViewModel.StatusAreaCommitments = $"{areaComs.Count:N0}";
|
||||
ViewModel.StatusArea = $"{areaComs.Select(a => a.Area).Sum():N0} m²";
|
||||
ViewModel.StatusAreaToolTip = null;
|
||||
}
|
||||
var groups = areaComs.GroupBy(a => $"{a.AreaComType.SortId}{a.AreaComType.AttrId}").Select(a => (a.Key, a.Sum(b => b.Area))).OrderByDescending(a => a.Item2).ToList();
|
||||
ViewModel.StatusContracts = $"Vertragsarten: {groups.Count} (" + string.Join(", ", groups.Select(g => $"{g.Key}: {g.Item2:N0} m²")) + ")";
|
||||
groups = areaComs.GroupBy(a => a.AreaComType.DisplayName).Select(a => (a.Key, a.Sum(b => b.Area))).OrderByDescending(a => a.Item2).ToList();
|
||||
StatusContracts.ToolTip = $"Vertragsarten: {groups.Count}\n" + string.Join($"\n", groups.Select(g => $"{g.Key}: {g.Item2:N0} m²"));
|
||||
ViewModel.StatusContracts = $"{groups.Count:N0}";
|
||||
if (groups.Count > 0)
|
||||
ViewModel.StatusContracts += $" ({string.Join(", ", groups.Select(g => g.Key))})";
|
||||
}
|
||||
|
||||
private void RefreshInputs(bool validate = false) {
|
||||
|
Reference in New Issue
Block a user