Bladeren bron

Tweaked Dyanmic Editor DefineLookups to allow synchronous as well as asynchronous refreshes
Fixed a problem with DynamicManyToMany Grids where the link IDs were being updated with the wrong values
Fixed an issue that was causing LinkedProperties to not trigger when required

frogsoftware 1 jaar geleden
bovenliggende
commit
24381b98e6

+ 3 - 1
InABox.Core/Editors/Utils/LookupGenerator.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace InABox.Core
 {
@@ -72,7 +73,8 @@ namespace InABox.Core
 
         protected void AddColumn(string name, Type type)
         {
-            columns.Add(new Tuple<string, Type>(name, type));
+            if (!columns.Any(x=>String.Equals(x.Item1,name)))
+                columns.Add(new Tuple<string, Type>(name, type));
         }
     }
 }

+ 1 - 1
InABox.Core/LinkedProperties.cs

@@ -99,7 +99,7 @@ namespace InABox.Core
             if(!_LinkedProperties.TryGetValue(parent.GetType(), out var props))
                 return false;
             var path = GetPath(subObject);
-            property = props.FirstOrDefault(x => x.Path == path && x.Source == name);
+            property = props.FirstOrDefault(x => String.Equals($"{x.Path}{(String.IsNullOrWhiteSpace(x.Path) ? "" : ".")}{x.Source}", $"{path}{(String.IsNullOrWhiteSpace(path) ? "" : ".")}{name}"));
             return property != null;
         }
         

+ 8 - 0
InABox.Core/LinkedProperty.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Linq;
 using System.Linq.Expressions;
 using System.Reflection;
 
@@ -27,6 +28,11 @@ namespace InABox.Core
         public String Source { get; }
         public String Target { get; }
         
+        public override string ToString()
+        {
+            return $"{Type.EntityName().Split('.').Last()}: {Path}{(String.IsNullOrWhiteSpace(Path) ? "" : ".")}{Source} => {Target}";
+        }
+        
         public LinkedProperty(Expression<Func<TLinkedEntity, TEntityLink>> path, 
             Expression<Func<TEntityLink, TType>> source,
             Expression<Func<TLinkedEntity, TType>> target)
@@ -57,5 +63,7 @@ namespace InABox.Core
             }
             return false;
         }
+
+
     }
 }

+ 2 - 2
inabox.wpf/DynamicGrid/DynamicColumnGrid.cs

@@ -119,7 +119,7 @@ namespace InABox.DynamicGrid
             }
         }
 
-        protected override void DefineLookups(ILookupEditorControl sender, DynamicGridColumn[] items)
+        protected override void DefineLookups(ILookupEditorControl sender, DynamicGridColumn[] items, bool async = true)
         {
             if (Type != null && sender.ColumnName.Equals("ColumnName"))
             {
@@ -141,7 +141,7 @@ namespace InABox.DynamicGrid
             }
             else
             {
-                base.DefineLookups(sender, items);
+                base.DefineLookups(sender, items, async);
             }
         }
 

+ 33 - 26
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -1042,7 +1042,7 @@ namespace InABox.DynamicGrid
             var datacolname = colname.Replace(".", "_");
             var table = DataGridItems;
             if (table is null) return;
-
+            
             var colno = table.Columns.IndexOf(datacolname);
             if (colno < 0)
             {
@@ -2751,40 +2751,47 @@ namespace InABox.DynamicGrid
 
         private readonly Dictionary<Tuple<Type, Type>, Dictionary<object, object>> _lookupcache = new();
 
-        protected virtual void DefineLookups(ILookupEditorControl sender, T[] items)
+        protected virtual void DefineLookups(ILookupEditorControl sender, T[] items, bool async = true)
         {
             if (sender.EditorDefinition is not ILookupEditor editor)
                 return;
 
             var colname = sender.ColumnName;
-
-            //Logger.Send(LogType.Information, typeof(T).Name, "Into Define Lookups: " + colname);
-            Task.Run(() =>
+            if (async)
             {
-                try
+                Task.Run(() =>
                 {
-                    var values = editor.Values(colname, items);
-                    Dispatcher.Invoke(
-                        () =>
-                        {
-                            try
-                            {
-                                //Logger.Send(LogType.Information, typeof(T).Name, "Dispatching Results" + colname);
-                                sender.LoadLookups(values);
-                            }
-                            catch (Exception e2)
+                    try
+                    {
+                        var values = editor.Values(colname, items);
+                        Dispatcher.Invoke(
+                            () =>
                             {
-                                Logger.Send(LogType.Information, typeof(T).Name,
-                                    "Exception (2) in LoadLookups: " + e2.Message + "\n" + e2.StackTrace);
+                                try
+                                {
+                                    //Logger.Send(LogType.Information, typeof(T).Name, "Dispatching Results" + colname);
+                                    sender.LoadLookups(values);
+                                }
+                                catch (Exception e2)
+                                {
+                                    Logger.Send(LogType.Information, typeof(T).Name,
+                                        "Exception (2) in LoadLookups: " + e2.Message + "\n" + e2.StackTrace);
+                                }
                             }
-                        }
-                    );
-                }
-                catch (Exception e)
-                {
-                    Logger.Send(LogType.Information, typeof(T).Name, "Exception (1) in LoadLookups: " + e.Message + "\n" + e.StackTrace);
-                }
-            });
+                        );
+                    }
+                    catch (Exception e)
+                    {
+                        Logger.Send(LogType.Information, typeof(T).Name,
+                            "Exception (1) in LoadLookups: " + e.Message + "\n" + e.StackTrace);
+                    }
+                });
+            }
+            else
+            {
+                var values = editor.Values(colname, items);
+                sender.LoadLookups(values);
+            }
         }
 
         /// <summary>

+ 5 - 3
inabox.wpf/DynamicGrid/DynamicManyToManyGrid.cs

@@ -26,10 +26,11 @@ namespace InABox.DynamicGrid
         protected TThis Item;
         private TManyToMany[] MasterList = { };
         protected PropertyInfo otherproperty;
-
         protected IEntityLink GetOtherLink(TManyToMany item) => (otherproperty.GetValue(item) as IEntityLink)!;
 
         protected PropertyInfo thisproperty;
+        protected IEntityLink GetThisLink(TManyToMany item) => (thisproperty.GetValue(item) as IEntityLink)!;
+        
         protected List<TManyToMany> WorkingList = new();
 
         public PageType PageType => PageType.Other;
@@ -164,7 +165,7 @@ namespace InABox.DynamicGrid
 
             foreach (var map in WorkingList)
             {
-                var prop = GetOtherLink(map);
+                var prop = GetThisLink(map);
                 if (prop.ID != Item.ID)
                     prop.ID = Item.ID;
             }
@@ -259,7 +260,8 @@ namespace InABox.DynamicGrid
             var result = new List<Guid>();
             foreach (var item in WorkingList)
             {
-                var prop = GetOtherLink(item);
+                //var prop = GetOtherLink(item);
+                var prop = GetThisLink(item);
                 result.Add(prop.ID);
             }