From bb77a4e79a33d788c061593f4be534063d4836a3 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Fri, 5 Jul 2024 22:03:46 +0200 Subject: [PATCH] [#26] AreaComAdminWindow: Overhaul status bar and search filters --- Elwig/Services/AreaComService.cs | 22 +++++++-- Elwig/ViewModels/AreaComAdminViewModel.cs | 9 ++-- Elwig/Windows/AreaComAdminWindow.xaml | 59 +++++++++++++++++------ Elwig/Windows/AreaComAdminWindow.xaml.cs | 24 ++++++--- 4 files changed, 84 insertions(+), 30 deletions(-) diff --git a/Elwig/Services/AreaComService.cs b/Elwig/Services/AreaComService.cs index c9141b0..dcbde54 100644 --- a/Elwig/Services/AreaComService.cs +++ b/Elwig/Services/AreaComService.cs @@ -40,8 +40,8 @@ namespace Elwig.Services { List filterNames = []; IQueryable 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(); @@ -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); diff --git a/Elwig/ViewModels/AreaComAdminViewModel.cs b/Elwig/ViewModels/AreaComAdminViewModel.cs index 73ca90c..c890f48 100644 --- a/Elwig/ViewModels/AreaComAdminViewModel.cs +++ b/Elwig/ViewModels/AreaComAdminViewModel.cs @@ -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; } } diff --git a/Elwig/Windows/AreaComAdminWindow.xaml b/Elwig/Windows/AreaComAdminWindow.xaml index bf3c7e4..a0446be 100644 --- a/Elwig/Windows/AreaComAdminWindow.xaml +++ b/Elwig/Windows/AreaComAdminWindow.xaml @@ -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"> @@ -51,6 +51,7 @@ + @@ -60,7 +61,10 @@ - + + + + @@ -73,9 +77,22 @@ - + + + Strg+F + Flächenbindungen filtern und durchsuchen. Die Filter sind beliebig kombinierbar. + Groß- und Kleinschreibung ist in den meisten Fällen egal. + + Filtern nach: + Sorte: z.B. GV, zw, RR, ... + Attribut: z.B. Kabinett, dac, ... + Flächenbindung: z.B. GVK, GVD, ... + + + + @@ -94,7 +111,13 @@ - + + + + + @@ -138,12 +161,12 @@ - + - + - - + + @@ -237,9 +260,9 @@ - + - + @@ -247,15 +270,21 @@ - + + Flächenbindungen: + - + + Fläche: + - + + Vertragsarten: + diff --git a/Elwig/Windows/AreaComAdminWindow.xaml.cs b/Elwig/Windows/AreaComAdminWindow.xaml.cs index 59006b6..a5a856f 100644 --- a/Elwig/Windows/AreaComAdminWindow.xaml.cs +++ b/Elwig/Windows/AreaComAdminWindow.xaml.cs @@ -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) {