Selaa lähdekoodia

Merge remote-tracking branch 'origin/kenric' into frank

frankvandenbos 9 kuukautta sitten
vanhempi
commit
49bb12e037

+ 1 - 0
InABox.Core/Configuration/GlobalConfiguration.cs

@@ -10,6 +10,7 @@ namespace InABox.Configuration
     }
 
     [UserTracking(false)]
+    [Unrecoverable]
     public class GlobalSettings : Entity, IPersistent, IRemotable, ILicense<CoreLicense>
     {
         public string Section { get; set; } = "";

+ 1 - 0
InABox.Core/Configuration/UserConfiguration.cs

@@ -19,6 +19,7 @@ namespace InABox.Configuration
     }
 
     [UserTracking(false)]
+    [Unrecoverable]
     public class UserSettings : Entity, IPersistent, IRemotable, ILicense<CoreLicense>
     {
         public string Section { get; set; }

+ 6 - 0
InABox.Core/CoreUtils.cs

@@ -2728,6 +2728,12 @@ namespace InABox.Core
             return new Queue<T>(enumerable.ToArray());
         }
 
+        public static void SortBy<T, TProp>(this List<T> list, Func<T, TProp> comparison)
+            where TProp : IComparable
+        {
+            list.Sort((a, b) => comparison(a).CompareTo(comparison(b)));
+        }
+
         #endregion
 
     }

+ 3 - 1
inabox.wpf/DynamicGrid/ColumnFilter/StaticColumnFilter.cs

@@ -105,7 +105,8 @@ public abstract class CheckBoxDynamicGridColumnFilter : IDynamicGridColumnFilter
         itemList.ItemTemplate = TemplateGenerator.CreateDataTemplate(() =>
         {
             var box = new CheckBox();
-            box.Padding = new(5.0);
+            box.Height = 25;
+            box.VerticalAlignment = VerticalAlignment.Center;
             box.VerticalContentAlignment = VerticalAlignment.Center;
             box.HorizontalAlignment = HorizontalAlignment.Stretch;
             box.Bind<FilterItem, string?>(
@@ -120,6 +121,7 @@ public abstract class CheckBoxDynamicGridColumnFilter : IDynamicGridColumnFilter
             return box;
         });
         itemList.HorizontalContentAlignment = HorizontalAlignment.Stretch;
+        itemList.VerticalContentAlignment = VerticalAlignment.Center;
         itemList.ItemsSource = CoreUtils.One(_selectAll).Concat(_items);
 
         searchBox.TextChanged += (o, e) =>

+ 1 - 1
inabox.wpf/DynamicGrid/Columns/DynamicTextColumn.cs

@@ -18,7 +18,7 @@ public class DynamicTextColumn : DynamicActionColumn
         Alignment = Alignment.MiddleCenter;
         VerticalHeader = false;
     }
-        
+
     public DynamicTextColumn(GetTextDelegate text, ActionDelegate? action = null) : this()
     {
         Text = text;

+ 5 - 6
inabox.wpf/DynamicGrid/Editors/FilterEditor/FilterNode.cs

@@ -245,8 +245,8 @@ public class FilterNode<T> : BaseFilterNode
 
     private ValueNode? CreateValueNode(string propertyName, Operator op)
     {
-        var property = CoreUtils.GetProperty(typeof(T), propertyName);
-        return CreateValueNode(property.PropertyType, op);
+        var property = DatabaseSchema.Property(typeof(T), propertyName);
+        return property is not null ? CreateValueNode(property.PropertyType, op) : null;
     }
 
     [MemberNotNull(nameof(Value))]
@@ -262,11 +262,10 @@ public class FilterNode<T> : BaseFilterNode
     private ConstantNode? CreateConstantNode(string? propertyName, Operator op, FilterConstant? constantvalue)
     {
         var values = new List<KeyValuePair<string, FilterConstant?>>();
-        if (!string.IsNullOrWhiteSpace(propertyName))
+        if (!string.IsNullOrWhiteSpace(propertyName) && DatabaseSchema.Property(typeof(T), propertyName) is IProperty property)
         {
-            var property = CoreUtils.GetProperty(typeof(T), propertyName);
-            var constants = FilterConstants.Constants(property.PropertyType, op, property.GetCustomAttribute<AggregateAttribute>() != null);
-            if (constants.Any())
+            var constants = FilterConstants.Constants(property.PropertyType, op, property.HasAttribute<AggregateAttribute>());
+            if (constants.Length != 0)
             {
                 values.Add(new KeyValuePair<string, FilterConstant?>("", null));
                 foreach (var constant in constants)

+ 13 - 2
inabox.wpf/DynamicGrid/Grids/DynamicGrid.cs

@@ -562,9 +562,20 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
                 return new StandardDynamicGridColumnFilter(this, column);
             }
         }
-        else if(column is DynamicActionColumn ac && ac.GetFilter is not null)
+        else if(column is DynamicActionColumn ac)
         {
-            return ac.GetFilter();
+            if(ac.GetFilter is not null)
+            {
+                return ac.GetFilter();
+            }
+            else if(ac is DynamicTextColumn textColumn)
+            {
+                return new StandardDynamicGridColumnFilter(this, textColumn);
+            }
+            else
+            {
+                return null;
+            }
         }
         else
         {

+ 4 - 10
inabox.wpf/DynamicGrid/UIComponent/DynamicGridGridUIComponent.cs

@@ -186,7 +186,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         DataGrid.RowDragDropController ??= new GridRowDragDropController();
         
         DataGrid.CurrentCellBorderThickness = new Thickness(0);
-        DataGrid.AllowFiltering = false;
         DataGrid.EnableDataVirtualization = true;
         DataGrid.RowHeight = 30;
         DataGrid.QueryRowHeight += DataGrid_QueryRowHeight;
@@ -272,10 +271,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         var table = DataGridItems;
         if(table is null) return;
 
-        var dataRows = rows.Where(x => x.Index > -1).Select(row =>
-        {
-            return table.Rows[row.Index];
-        });
+
+        var dataRows = rows.Select(x => _rowMap.FirstOrDefault(y => x == y.Value).Key);
         if (!Parent.Options.MultiSelect)
         {
             dataRows = dataRows.Take(1);
@@ -500,7 +497,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
             DataGrid.AllowEditing = allowEditing;
             reloadColumns = true;
         }
-        DataGrid.AllowFiltering = Parent.Options.FilterRows && Parent.CanFilter();
         DataGrid.FilterRowPosition = Parent.Options.FilterRows && Parent.CanFilter() ? FilterRowPosition.FixedTop : FilterRowPosition.None;
 
         if (Parent.Options.DragSource || Parent.Options.ReorderRows)
@@ -888,8 +884,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
     private void ApplyFilterStyle(GridColumn column, bool filtering, bool allowSorting)
     {
-        column.AllowFiltering = false;
-
         var filterstyle = new Style();
         if (filtering)
         {
@@ -906,7 +900,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
             filterstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
             filterstyle.Setters.Add(new Setter(Control.IsEnabledProperty, false));
             column.ColumnFilter = ColumnFilter.Value;
-            column.AllowFiltering = false;
             column.AllowSorting = false;
             column.FilterRowEditorType = "TextBox";
             column.FilterRowOptionsVisibility = Visibility.Collapsed;
@@ -935,6 +928,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
     private void SetFilterUIButton(GridColumn gridColumn, DynamicColumnBase column)
     {
+        if (!Parent.Options.FilterRows || !Parent.CanFilter()) return;
+
         if (Parent.GetColumnFilter(column) is not IDynamicGridColumnFilter filter) return;
 
         var vertical = column is DynamicActionColumn ac && ac.VerticalHeader && !ac.HeaderText.IsNullOrWhiteSpace();
@@ -1183,7 +1178,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
             newcol.Width = tmplCol.Width;
             newcol.ColumnSizer = GridLengthUnitType.None;
             newcol.HeaderText = column.HeaderText;
-            newcol.AllowFiltering = false;
             newcol.AllowSorting = false;
             newcol.FilterRowOptionsVisibility = Visibility.Collapsed;
             

+ 2 - 7
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -667,8 +667,6 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
             reloadColumns = true;
         }
 
-        _tree.AllowFiltering = Parent.Options.FilterRows;
-
         if (Parent.Options.DragSource)
         {
             if (!_tree.AllowDraggingRows)
@@ -1061,8 +1059,6 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
 
     private void ApplyFilterStyle(TreeGridColumn column, bool filtering, bool isactioncolumn)
     {
-        column.AllowFiltering = false;
-
         var filterstyle = new Style();
         if (filtering)
         {
@@ -1079,7 +1075,6 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
             filterstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
             filterstyle.Setters.Add(new Setter(Control.IsEnabledProperty, false));
             column.ColumnFilter = ColumnFilter.Value;
-            column.AllowFiltering = false;
             column.AllowSorting = false;
         }
     }
@@ -1104,6 +1099,8 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
 
     private void SetFilterUIButton(TreeGridColumn gridColumn, DynamicColumnBase column)
     {
+        if (!Parent.Options.FilterRows || !Parent.CanFilter()) return;
+
         if (Parent.GetColumnFilter(column) is not IDynamicGridColumnFilter filter) return;
 
         var vertical = column is DynamicActionColumn ac && ac.VerticalHeader && !ac.HeaderText.IsNullOrWhiteSpace();
@@ -1219,7 +1216,6 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
             newcol.Width = column.Width;
             newcol.ColumnSizer = TreeColumnSizer.None;
             newcol.HeaderText = column.HeaderText;
-            //newcol.AllowFiltering = column.Filters != null && column.Filters.Any();
             newcol.AllowSorting = false;
             newcol.ShowHeaderToolTip = column.ToolTip != null;
             
@@ -1243,7 +1239,6 @@ public class DynamicGridTreeUIComponent<T, TKey> : IDynamicGridUIComponent<T>, I
             newcol.Width = tmplCol.Width;
             newcol.ColumnSizer = TreeColumnSizer.None;
             newcol.HeaderText = column.HeaderText;
-            //newcol.AllowFiltering = false;
             newcol.AllowSorting = false;
             newcol.ShowToolTip = false;
             newcol.ShowHeaderToolTip = false;