Browse Source

Fixed InvalidateRow; Made FitlerButtonComponenet public; Added DynamicSeelectorGrid

Kenric Nugteren 1 year ago
parent
commit
182871be34

+ 2 - 0
InABox.Core/CoreTreeNodes.cs

@@ -55,6 +55,7 @@ namespace InABox.Core
             {
                 _row = value;
                 RaisedOnPropertyChanged("Row");
+                RaisedOnPropertyChanged("Item[]");
             }
         }
 
@@ -95,6 +96,7 @@ namespace InABox.Core
         public void InvalidateData()
         {
             RaisedOnPropertyChanged("Row");
+            RaisedOnPropertyChanged("Item[]");
         }
 
         public String Number

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicDataGrid.cs

@@ -35,7 +35,7 @@ namespace InABox.DynamicGrid
         private readonly int ChunkSize = 500;
         private Button MergeBtn = null!; //Late-initialised
 
-        protected DynamicGridFilterButtonComponent<TEntity> FilterComponent;
+        public DynamicGridFilterButtonComponent<TEntity> FilterComponent;
         protected DynamicGridCustomColumnsComponent<TEntity> ColumnsComponent;
 
         private Column<TEntity>[] FilterColumns;

+ 63 - 0
inabox.wpf/DynamicGrid/DynamicSelectorGrid.cs

@@ -0,0 +1,63 @@
+using InABox.Core;
+using InABox.WPF;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
+
+namespace InABox.DynamicGrid;
+
+public class DynamicSelectorGrid<T> : DynamicDataGrid<T>
+    where T : Entity, IRemotable, IPersistent, new()
+{
+    private static BitmapImage tick = InABox.Wpf.Resources.tick.AsBitmapImage();
+
+    public HashSet<Guid> SelectedIDs { get; set; } = new();
+
+    public delegate void SelectionChangedEvent(HashSet<Guid> selected);
+    public event SelectionChangedEvent? SelectionChanged;
+
+    public DynamicSelectorGrid(DynamicActionColumnPosition tickPosition)
+    {
+        ActionColumns.Add(new DynamicImageColumn(Selected_Image, Selected_Click)
+        {
+            Position = tickPosition
+        });
+    }
+
+    private BitmapImage? Selected_Image(CoreRow? row)
+    {
+        if (row is null) return tick;
+
+        return SelectedIDs.Contains(row.Get<T, Guid>(x => x.ID)) ? tick : null;
+    }
+
+    private bool Selected_Click(CoreRow? row)
+    {
+        if (row is null) return false;
+
+        var id = row.Get<T, Guid>(x => x.ID);
+
+        if (SelectedIDs.Contains(id))
+        {
+            SelectedIDs.Remove(id);
+        }
+        else
+        {
+            SelectedIDs.Add(id);
+        }
+
+        SelectionChanged?.Invoke(SelectedIDs);
+
+        InvalidateRow(row);
+        return false;
+    }
+
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+        options.Clear();
+    }
+}

+ 15 - 12
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -903,14 +903,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         foreach (var row in data.Rows)
         {
             var newRow = _innerTable.NewRow();
-            newRow.LoadValues(row.Values);
-
-            for (var i = 0; i < ActionColumns.Count; i++)
-            {
-                var ac = ActionColumns[i];
-                newRow[$"_ActionColumn{i}"] = ac.Data(row);
-            }
-
+            ProcessRow(newRow, row);
             _innerTable.Rows.Add(newRow);
 
             var _id = row.Get<Guid>(IDColumn.Property);
@@ -926,6 +919,17 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         UpdateRecordCount();
     }
 
+    private void ProcessRow(CoreRow innerRow, CoreRow row)
+    {
+        innerRow.LoadValues(row.Values);
+
+        for (var i = 0; i < ActionColumns.Count; i++)
+        {
+            var ac = ActionColumns[i];
+            innerRow[$"_ActionColumn{i}"] = ac.Data(row);
+        }
+    }
+
     private void CalculateRowHeight()
     {
         if(Parent.Data != null && Parent.Data.Rows.Count > 0)
@@ -983,11 +987,10 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         if (_innerTable is null || row.Index < 0 || row.Index >= _innerTable.Rows.Count) return;
 
         var _innerRow = _innerTable.Rows[row.Index];
+        ProcessRow(_innerRow, row);
+
         var coreTreeNode = Nodes.Find(_innerRow);
-        if(coreTreeNode is not null)
-        {
-            coreTreeNode.InvalidateData();
-        }
+        coreTreeNode?.InvalidateData();
     }