Browse Source

Cleaning up

Kenric Nugteren 7 months ago
parent
commit
c353773b73

+ 0 - 8
inabox.wpf/DynamicGrid/Columns/DynamicActionColumn.cs

@@ -25,14 +25,6 @@ namespace InABox.DynamicGrid
 
         public Func<IDynamicGridColumnFilter?>? GetFilter = null;
         
-        public string[]? ExcludeFilters { get; set; }
-        public string[]? SelectedFilters { get; set; }
-        public string[]? Filters { get; set; } = null;
-
-        public Func<DynamicActionColumn, string>? GetFilterExpression = null;
-        
-        public Func<CoreRow, string[], bool>? FilterRecord { get; set; } = null;
-
         public Func<CoreRow[]?, ContextMenu?>? ContextMenu { get; set; }
         
         public string HeaderText { get; set; } = " ";

+ 3 - 20
inabox.wpf/DynamicGrid/Grids/DynamicGrid.cs

@@ -535,17 +535,6 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
         
     }
 
-    IEnumerable<Tuple<object?, string>>? IDynamicGridUIComponentParent<T>.GetColumnFilterItems(DynamicColumnBase column) => GetColumnFilterItems(column);
-
-    protected virtual IEnumerable<Tuple<object?, string>>? GetColumnFilterItems(DynamicColumnBase column)
-    {
-        if(column is DynamicGridColumn gc)
-        {
-            return Data.Rows.Select(x => x[gc.ColumnName]).Select(x => new Tuple<object?, string>(x, x.ToString()));
-        }
-        return null;
-    }
-
     private Dictionary<DynamicColumnBase, IDynamicGridColumnFilter?> ColumnFilters { get; set; } = new();
 
     IDynamicGridColumnFilter? IDynamicGrid.GetColumnFilter(DynamicColumnBase column) => GetColumnFilter(column);
@@ -1084,15 +1073,9 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
     
     protected virtual bool FilterRecord(CoreRow row)
     {
-        var bOK = ActionColumns.All(x =>
-        {
-            return x.FilterRecord is null
-                || ((x.SelectedFilters is null || x.SelectedFilters.Length == 0 || x.FilterRecord.Invoke(row, x.SelectedFilters))
-                    && (x.ExcludeFilters is null || x.ExcludeFilters.Length == 0 || !x.FilterRecord.Invoke(row, x.ExcludeFilters)));
-        });
-        if (bOK && OnFilterRecord is not null)
-            bOK = OnFilterRecord(row);
-        return bOK;
+        if (OnFilterRecord is not null)
+            return OnFilterRecord(row);
+        return true;
     }
 
     public IEnumerable<TType> ExtractValues<TType>(Expression<Func<T, TType>> column, Selection selection)

+ 0 - 21
inabox.wpf/DynamicGrid/UIComponent/DynamicGridGridUIComponent.cs

@@ -200,7 +200,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         
         DataGrid.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Visible);
         
-        DataGrid.FilterChanging += DataGrid_FilterChanging;
         DataGrid.FilterChanged += DataGrid_FilterChanged;
 
         var fltstyle = new Style(typeof(GridFilterControl));
@@ -547,27 +546,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         return reloadColumns && DataGrid.Columns.Count > 0;
     }
 
-    private void DataGrid_FilterChanging(object? sender, GridFilterEventArgs e)
-    {
-        var col = GetColumn(DataGrid.Columns.IndexOf(e.Column)) as DynamicActionColumn;
-        if (col?.GetFilterExpression != null)
-        {
-            col.SetFilters(e.FilterPredicates);
-            var view = (DataGrid.ItemsSource as DataTable)?.DefaultView;
-            view.ApplyFilters(ColumnList.OfType<DynamicActionColumn>());
-            e.Handled = true;
-        }
-    }
-    
     private void DataGrid_FilterChanged(object? o, GridFilterEventArgs e)
     {
-        var col = DataGrid.Columns.IndexOf(e.Column);
-        if (GetColumn(col) is DynamicActionColumn column)
-        {
-            column.SetFilters(e.FilterPredicates);
-            e.Handled = true;
-        }
-
         if (e.FilterPredicates == null)
         {
             if (_filterpredicates.ContainsKey(e.Column.MappingName))
@@ -1157,7 +1137,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
             newcol.Width = column.Width;
             newcol.ColumnSizer = GridLengthUnitType.None;
             newcol.HeaderText = column.HeaderText;
-            newcol.AllowFiltering = (column.Filters != null && column.Filters.Length != 0) || column.FilterRecord is not null;
             newcol.AllowSorting = false;
             newcol.FilterRowOptionsVisibility = Visibility.Collapsed;
             newcol.ShowHeaderToolTip = column.ToolTip != null;

+ 0 - 21
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -261,7 +261,6 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
         filterstyle.Setters.Add(new Setter(TreeGridFilterControl.ImmediateUpdateColumnFilterProperty, false));
         _tree.FilterPopupStyle = filterstyle;
 
-        _tree.FilterChanging += _tree_FilterChanging;
         _tree.FilterChanged += _tree_FilterChanged;
         _tree.FilterLevel = FilterLevel.Extended;
         _tree.SelectionForeground = DynamicGridUtils.SelectionForeground;
@@ -548,28 +547,8 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
 
     private readonly Dictionary<string, string> FilterPredicates = new();
 
-    private void _tree_FilterChanging(object? sender, TreeGridFilterChangingEventArgs e)
-    {
-        var col = GetColumn(_tree.Columns.IndexOf(e.Column)) as DynamicActionColumn;
-        if (col?.GetFilterExpression != null)
-        {
-            col.SetFilters(e.FilterPredicates);
-            var view = (_tree.ItemsSource as DataTable)?.DefaultView;
-            view.ApplyFilters(ColumnList.OfType<DynamicActionColumn>());
-            e.Handled = true;
-        }
-    }
-
     private void _tree_FilterChanged(object? sender, TreeGridFilterChangedEventArgs e)
     {
-        var col = _tree.Columns.IndexOf(e.Column);
-        if (GetColumn(col) is DynamicActionColumn column)
-        {
-            column.SetFilters(e.FilterPredicates);
-            _tree.ClearFilter(e.Column);
-            Parent.Refresh(false, false);
-        }
-
         if (e.FilterPredicates == null)
         {
             if (FilterPredicates.ContainsKey(e.Column.MappingName))

+ 0 - 2
inabox.wpf/DynamicGrid/UIComponent/IDynamicGridUIComponent.cs

@@ -56,8 +56,6 @@ public interface IDynamicGridUIComponentParent<T> : IDynamicGrid<T>
     void MoveRows(CoreRow[] rows, int index);
     
     void UIFilterChanged(object sender);
-
-    IEnumerable<Tuple<object?, string>>? GetColumnFilterItems(DynamicColumnBase column);
 }
 
 public interface IDynamicGridUIComponent<T>

+ 0 - 80
inabox.wpf/DynamicGrid/UIComponent/IDynamicGridUIComponentExtensions.cs

@@ -1,80 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Linq;
-using Syncfusion.Data;
-
-namespace InABox.DynamicGrid;
-
-public static class IDynamicGridUIComponentExtensions
-{
-    public static string CreateFilterExpression(this DynamicActionColumn column, string propertyName)
-    {
-        List<string> criteria = new();
-        
-        var sel = column.SelectedFilters ?? [];
-        var exc = column.ExcludeFilters ?? [];
-
-        if (sel.Any())
-        {
-            var sels = String.Join(", ",sel.Select(x => $"'{x}'"));
-            criteria.Add($"{propertyName} IN ({sels})");
-        }
-        
-        if (exc.Any())
-        {
-            var excs = String.Join(", ",exc.Select(x => $"'{x}'"));
-            criteria.Add($"{propertyName} NOT IN ({excs})");
-        }
-    
-        if (criteria.Any())
-            return $"{string.Join(" AND ", criteria)}";
-
-        return "true";
-    }
-    
-    public static void SetFilters(this DynamicActionColumn column, IEnumerable<FilterPredicate>? predicates)
-    {
-        if (predicates != null)
-        {
-            var filter = predicates.Select(x => x.FilterValue.ToString()!).ToArray();
-            var include = predicates.Any(x => x.FilterType == FilterType.Equals);
-            if (include)
-            {
-                column.SelectedFilters = filter;
-                column.ExcludeFilters = null;
-            }
-            else if(column.Filters is not null)
-            {
-                column.SelectedFilters = column.Filters.Except(filter).ToArray();
-                column.ExcludeFilters = null;
-            }
-            else
-            {
-                column.SelectedFilters = null;
-                column.ExcludeFilters = filter;
-            }
-        }
-        else
-        {
-            column.SelectedFilters = null;
-            column.ExcludeFilters = null;
-        }
-    }
-    
-    public static void ApplyFilters(this DataView? view, IEnumerable<DynamicActionColumn> columns)
-    {
-        List<String> criteria = new();
-        foreach (var column in columns)
-            criteria.Add(column.GetFilterExpression?.Invoke(column) ?? "");
-        var filter = string.Join(" AND ", criteria.Where(x => !string.IsNullOrWhiteSpace(x)));
-        if (view != null)
-        {
-            view.RowStateFilter = DataViewRowState.CurrentRows;
-            view.RowFilter = filter;
-            if (view.Count == 0)
-                view.RowStateFilter = DataViewRowState.None;
-        }
-    }
-    
-}