Переглянути джерело

Merge remote-tracking branch 'origin/frank' into kenric; Also added Generate Columns back in

# Conflicts:
#	InABox.Core/DocumentCache.cs
Kenric Nugteren 1 рік тому
батько
коміт
539e8ed5de

+ 29 - 29
inabox.wpf/DynamicGrid/DynamicCrossJoinGrid.cs

@@ -6,38 +6,38 @@ using System.Linq.Expressions;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace InABox.DynamicGrid
+namespace InABox.DynamicGrid;
+
+public abstract class DynamicCrossJoinGrid<TEntity, TLeft> : DynamicDataGrid<TEntity>
+    where TEntity : Entity, IRemotable, IPersistent, new()
+    where TLeft : Entity
 {
-    public abstract class DynamicCrossJoinGrid<TEntity, TLeft> : DynamicDataGrid<TEntity>
-        where TEntity : Entity, IRemotable, IPersistent, new()
-        where TLeft : Entity
-    {
-        
-        public TLeft? Left { get; set; }
-        public abstract Expression<Func<TEntity, Guid>> LeftMapping { get; }
-        public abstract Expression<Func<TLeft, Guid>> LeftProperty { get; }
+    
+    public TLeft? Left { get; set; }
+    public abstract Expression<Func<TEntity, Guid>> LeftMapping { get; }
+    public abstract Expression<Func<TLeft, Guid>> LeftProperty { get; }
 
-        protected override void DoReconfigure(FluentList<DynamicGridOption> options)
-        {
-            base.DoReconfigure(options);
-            options.BeginUpdate().Clear().Add(DynamicGridOption.SelectColumns).EndUpdate();
-        }
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+        options.BeginUpdate().Clear().Add(DynamicGridOption.SelectColumns).EndUpdate();
+    }
 
-        protected override void GenerateColumns(DynamicGridColumns columns)
-        {
-            base.GenerateColumns(columns);
-            var prefix = $"{typeof(TLeft).Name}.";
-            columns.RemoveAll(x => x.ColumnName.StartsWith(prefix));
-        }
+    public override DynamicGridColumns GenerateColumns()
+    {
+        var columns = base.GenerateColumns();
+        var prefix = $"{typeof(TLeft).Name}.";
+        columns.RemoveAll(x => x.ColumnName.StartsWith(prefix));
+        return columns;
+    }
 
-        protected override void Reload(Filters<TEntity> criteria, Columns<TEntity> columns, ref SortOrder<TEntity>? sort, Action<CoreTable?, Exception?> action)
-        {
-            var filter = new Filter<TEntity>();
-            filter.Expression = CoreUtils.ExtractMemberExpression<TEntity, Guid>(LeftMapping);
-            filter.Operator = Operator.IsEqualTo;
-            filter.Value = CoreUtils.GetPropertyValue(Left, CoreUtils.GetFullPropertyName(LeftProperty, "."));
-            criteria.Add(filter);
-            base.Reload(criteria, columns, ref sort, action);
-        }
+    protected override void Reload(Filters<TEntity> criteria, Columns<TEntity> columns, ref SortOrder<TEntity>? sort, Action<CoreTable?, Exception?> action)
+    {
+        var filter = new Filter<TEntity>();
+        filter.Expression = CoreUtils.ExtractMemberExpression<TEntity, Guid>(LeftMapping);
+        filter.Operator = Operator.IsEqualTo;
+        filter.Value = CoreUtils.GetPropertyValue(Left, CoreUtils.GetFullPropertyName(LeftProperty, "."));
+        criteria.Add(filter);
+        base.Reload(criteria, columns, ref sort, action);
     }
 }

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

@@ -80,7 +80,7 @@ namespace InABox.DynamicGrid
                 new UserConfiguration<CoreFilterDefinitions>(GetTag()));
             FilterComponent.OnFilterRefresh += () => Refresh(false, true);
 
-            ColumnsComponent = new DynamicGridCustomColumnsComponent<TEntity>(this, GetTag(), base.LoadColumns);
+            ColumnsComponent = new DynamicGridCustomColumnsComponent<TEntity>(this, GetTag());
 
             MergeBtn = AddButton("Merge", Wpf.Resources.merge.AsBitmapImage(Color.White), DoMerge);
         }
@@ -381,28 +381,6 @@ namespace InABox.DynamicGrid
             new UserConfiguration<DynamicGridSettings>(tag).Save(settings);
         }
 
-        /// <summary>
-        /// Provide a set of columns which is the default for this grid.
-        /// </summary>
-        /// <param name="columns"></param>
-        protected virtual void GenerateColumns(DynamicGridColumns columns)
-        {
-            var cols = new Columns<TEntity>().Default(IsDirectEditMode()
-                ? new[] { ColumnType.IncludeForeignKeys, ColumnType.ExcludeID }
-                : new ColumnType[] {
-                    ColumnType.IncludeLinked, ColumnType.IncludeNestedLinks, ColumnType.IncludeFormulae,
-                    ColumnType.IncludeAggregates, ColumnType.ExcludeID });
-            if (cols != null)
-            {
-                foreach (var col in cols.Items)
-                {
-                    var mc = MasterColumns.FirstOrDefault(x => x.ColumnName.Equals(col.Property));
-                    if (mc != null && !(mc.Editor is NullEditor) && mc.Editor.Visible != Visible.Hidden)
-                        columns.Add(mc);
-                }
-            }
-        }
-
         protected override BaseEditor? GetEditor(object item, DynamicGridColumn column)
         {
             var prop = DatabaseSchema.Properties(typeof(TEntity)).FirstOrDefault(x => x.Name == column.ColumnName);

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

@@ -38,7 +38,7 @@ namespace InABox.DynamicGrid
             Items = new List<TMany>();
             property = prop;
 
-            ColumnsComponent = new(this, null, base.LoadColumns);
+            ColumnsComponent = new(this, null);
         }
 
         protected override void Init()

+ 25 - 0
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -1478,6 +1478,31 @@ namespace InABox.DynamicGrid
             return result;
         }
 
+
+        /// <summary>
+        /// Provide a set of columns which is the default for this grid.
+        /// </summary>
+        public virtual DynamicGridColumns GenerateColumns()
+        {
+            var columns = new DynamicGridColumns();
+
+            var cols = IsDirectEditMode()
+                ? new Columns<T>().Default(ColumnType.IncludeForeignKeys, ColumnType.ExcludeID)
+                : new Columns<T>().Default(ColumnType.IncludeLinked, ColumnType.ExcludeID);
+
+            if (cols != null)
+            {
+                foreach (var col in cols.Items)
+                {
+                    var mc = MasterColumns.FirstOrDefault(x => x.ColumnName.Equals(col.Property));
+                    if (mc != null && mc.Editor is not NullEditor && mc.Editor.Visible != Visible.Hidden)
+                        columns.Add(mc);
+                }
+            }
+            return columns;
+        }
+
+
         private bool SwapRows(int row1, int row2)
         {
 

+ 11 - 20
inabox.wpf/DynamicGrid/DynamicGridCustomColumnsComponent.cs

@@ -19,38 +19,31 @@ public class DynamicGridCustomColumnsComponent<T>
 {
     private readonly DynamicGrid<T> Grid;
 
-    public Func<DynamicGridColumns> DefaultColumns { get; set; }
-
     public string? Tag { get; set; }
 
-    public DynamicGridCustomColumnsComponent(DynamicGrid<T> grid, string? tag, Func<DynamicGridColumns> defaultColumns)
+    public DynamicGridCustomColumnsComponent(DynamicGrid<T> grid, string? tag)
     {
         Grid = grid;
         Tag = tag;
-        DefaultColumns = defaultColumns;
     }
 
     public DynamicGridColumns LoadColumns()
     {
-        var tag = GetTag();
-
+        var tag = GetTag(Grid.IsDirectEditMode());
+        
         var user = Task.Run(() => new UserConfiguration<DynamicGridColumns>(tag).Load());
-        user.Wait();
-
         var global = Task.Run(() => new GlobalConfiguration<DynamicGridColumns>(tag).Load());
-        global.Wait();
-        //Task.WaitAll(user, global);
+        Task.WaitAll(user, global);
+
         var columns = user.Result.Any() ? user.Result : global.Result;
 
-        //if (!columns.Any())
-        //    GenerateColumns(columns); //override this to provide specific columns on startup
+        if (!columns.Any())
+            columns = Grid.GenerateColumns();
 
         var removes = columns.Where(x => x is null || string.IsNullOrWhiteSpace(x.ColumnName) || DatabaseSchema.Property(typeof(T), x.ColumnName) == null || GetColumnEditor(x) is NullEditor)
            .ToArray();
         foreach (var remove in removes)
             columns.Remove(remove);
-        if (columns.Count == 0)
-            columns.AddRange(DefaultColumns());
 
         foreach (var column in columns)
             try
@@ -77,7 +70,7 @@ public class DynamicGridCustomColumnsComponent<T>
 
     public void SaveColumns(DynamicGridColumns columns)
     {
-        var tag = GetTag();
+        var tag = GetTag(Grid.IsDirectEditMode());
         new UserConfiguration<DynamicGridColumns>(tag).Save(columns);
     }
 
@@ -96,13 +89,11 @@ public class DynamicGridCustomColumnsComponent<T>
         }
     }
 
-    private string GetTag()
+    private string GetTag(bool directEdit)
     {
         var tag = Tag ?? typeof(T).Name;
-        if (Grid.IsDirectEditMode())
-        {
+        if (directEdit)
             tag += ":DirectEdit";
-        }
         return tag;
     }
 
@@ -133,7 +124,7 @@ public class DynamicGridCustomColumnsComponent<T>
 
     private void UpdateDefaultColumnsClick(object sender, RoutedEventArgs e)
     {
-        var tag = GetTag();
+        var tag = GetTag(Grid.IsDirectEditMode());
         new GlobalConfiguration<DynamicGridColumns>(tag).Save(Grid.VisibleColumns);
         new UserConfiguration<DynamicGridColumns>(tag).Delete();
         Grid.Refresh(true, true);

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

@@ -62,7 +62,7 @@ namespace InABox.DynamicGrid
             HiddenColumns.Add(x => x.ID);
             HiddenColumns.Add(CoreUtils.CreateLambdaExpression<TManyToMany>(otherproperty.Name + ".ID"));
 
-            ColumnsComponent = new DynamicGridCustomColumnsComponent<TManyToMany>(this, GetTag(), base.LoadColumns);
+            ColumnsComponent = new DynamicGridCustomColumnsComponent<TManyToMany>(this, GetTag());
         }
 
         protected override void Init()

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

@@ -40,7 +40,7 @@ namespace InABox.DynamicGrid
 
             property = CoreUtils.GetOneToManyProperty(typeof(TMany), typeof(TOne));
 
-            ColumnsComponent = new DynamicGridCustomColumnsComponent<TMany>(this, GetTag(), base.LoadColumns);
+            ColumnsComponent = new DynamicGridCustomColumnsComponent<TMany>(this, GetTag());
         }
 
         protected override void Init()