Browse Source

Fixed editor for AddtionalTables and omved columns into script.

Kenric Nugteren 6 months ago
parent
commit
91d806682c

+ 0 - 16
InABox.Core/Objects/Editors/CoreColumnsListEditor.cs

@@ -1,16 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace InABox.Core
-{
-    public class CoreColumnsListEditor : BaseEditor
-    {
-        public Type? Type { get; set; }
-
-        protected override BaseEditor DoClone()
-        {
-            return new CoreColumnsListEditor() { Type = Type };
-        }
-    }
-}

+ 39 - 10
inabox.wpf/Dashboard/DynamicDashboardDataComponent.cs

@@ -14,7 +14,7 @@ public interface IDynamicDashboardTable
 {
     string Key { get; set; }
 
-    IEnumerable<CoreColumn> CoreColumns { get; }
+    IEnumerable<CoreColumn> GetColumns(DynamicDashboardDataComponent data);
 }
 
 public interface IDynamicDashboardDataQuery : IDynamicDashboardTable
@@ -27,11 +27,12 @@ public interface IDynamicDashboardDataQuery : IDynamicDashboardTable
 
     ISortOrder? SortOrder { get; set; }
 
-    IEnumerable<CoreColumn> IDynamicDashboardTable.CoreColumns => Columns.Columns().Select(x => new CoreColumn
-    {
-        ColumnName = x.Name,
-        DataType = x.Type
-    });
+    IEnumerable<CoreColumn> IDynamicDashboardTable.GetColumns(DynamicDashboardDataComponent data) =>
+        Columns.Columns().Select(x => new CoreColumn
+        {
+            ColumnName = x.Name,
+            DataType = x.Type
+        });
 }
 
 public class DynamicDashboardDataQuery<T> : IDynamicDashboardDataQuery
@@ -74,8 +75,6 @@ public class DynamicDashboardAdditionalTable : IDynamicDashboardTable
 {
     public string Key { get; set; } = "";
 
-    public List<CoreColumn> Columns { get; set; } = new();
-
     private string? _script;
     public string? Script
     {
@@ -90,7 +89,7 @@ public class DynamicDashboardAdditionalTable : IDynamicDashboardTable
         }
     }
 
-    IEnumerable<CoreColumn> IDynamicDashboardTable.CoreColumns => Columns;
+    public IEnumerable<CoreColumn> GetColumns(DynamicDashboardDataComponent data) => SetupColumns(data);
 
     private ScriptDocument? _scriptDocument;
     private ScriptDocument? ScriptDocument
@@ -112,13 +111,43 @@ public class DynamicDashboardAdditionalTable : IDynamicDashboardTable
 
 public class Module
 {
+    public IEnumerable<CoreColumn> SetupColumns(DynamicDashboardDataComponent data)
+    {
+        // Return the list of columns for this table.
+        return [
+            new CoreColumn(typeof(string), ""Column1""),
+            new CoreColumn(typeof(int), ""Column2"")];
+    }
+
     public void PopulateTable(CoreTable table, DynamicDashboardData data)
     {
         // Populate 'table' using the data from 'data'.
+        
+        // For example, to add rows to the table:
+        var newRow = table.NewRow();
+        newRow[""Column1""] = ""First Column Data"";
+        newRow[""Column2""] = 1;
+        table.Rows.Add(newRow);
     }
 }";
     }
 
+    private IEnumerable<CoreColumn> SetupColumns(DynamicDashboardDataComponent data)
+    {
+        if (ScriptDocument is null) return [];
+
+        var method = ScriptDocument.GetMethod(methodName: "SetupColumns");
+        if(method is not null)
+        {
+            return method.Invoke(ScriptDocument!.GetObject(), [data]) as IEnumerable<CoreColumn>
+                ?? [];
+        }
+        else
+        {
+            return [];
+        }
+    }
+
     public void PopulateTable(CoreTable table, DynamicDashboardData data)
     {
         if (ScriptDocument is null) return;
@@ -152,7 +181,7 @@ public class DynamicDashboardDataComponent
         foreach(var tableDef in AdditionalTables)
         {
             var table = new CoreTable();
-            table.Columns.AddRange(tableDef.Columns);
+            table.Columns.AddRange(tableDef.GetColumns(this));
             tableDef.PopulateTable(table, data);
             data.Data.Add(tableDef.Key, table);
         }

+ 0 - 44
inabox.wpf/Dashboard/Editor/DynamicDashboardAdditionalTableGrid.cs

@@ -8,46 +8,12 @@ using System.Threading.Tasks;
 
 namespace InABox.Wpf.Dashboard.Editor;
 
-internal class CoreColumnEditItem : BaseObject
-{
-    [EditorSequence(1)]
-    public string ColumnName { get; set; } = "";
-
-    [EditorSequence(2)]
-    [ComboLookupEditor(typeof(PropertyTypeLookups), Visible = Core.Visible.Default)]
-    public Type DataType { get; set; } = typeof(string);
-
-    internal class PropertyTypeLookups : LookupGenerator<object>
-    {
-        private static IEnumerable<Type> Types => [
-            typeof(string),
-            typeof(int),
-            typeof(bool),
-            typeof(DateTime),
-            typeof(TimeSpan),
-            typeof(double),
-            ];
-
-        public PropertyTypeLookups(object[] items) : base(items)
-        {
-            foreach(var type in Types)
-            {
-                AddValue(type, type.Name);
-            }
-        }
-    }
-}
-
 internal class DynamicDashboardAdditionalTableEditItem : BaseObject
 {
     [EditorSequence(1)]
     public string Name { get; set; } = "";
 
     [EditorSequence(2)]
-    [ListEditor]
-    public List<CoreColumnEditItem> Columns { get; set; } = new();
-
-    [EditorSequence(3)]
     [ScriptEditor]
     public string Script { get; set; } = "";
 
@@ -58,11 +24,6 @@ internal class DynamicDashboardAdditionalTableEditItem : BaseObject
     public DynamicDashboardAdditionalTableEditItem(DynamicDashboardAdditionalTable table)
     {
         Name = table.Key;
-        Columns = table.Columns.ToList(x => new CoreColumnEditItem
-        {
-            DataType = x.DataType,
-            ColumnName = x.ColumnName
-        });
         Script = table.Script ?? "";
     }
 
@@ -71,11 +32,6 @@ internal class DynamicDashboardAdditionalTableEditItem : BaseObject
         return new DynamicDashboardAdditionalTable
         {
             Key = Name,
-            Columns = Columns.ToList(x => new CoreColumn
-            {
-                ColumnName = x.ColumnName,
-                DataType = x.DataType
-            }),
             Script = Script.IsNullOrWhiteSpace() ? null : Script
         };
     }

+ 2 - 2
inabox.wpf/Dashboard/Presenters/DynamicDashboardGridPresenter.cs

@@ -174,7 +174,7 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
             {
                 if (presenter.DataComponent.TryGetTable(presenter.Properties.Table, out var table))
                 {
-                    return table.CoreColumns.Where(x => EditorUtils.GetEditor(x.DataType) is not null).Select(x => x.ColumnName);
+                    return table.GetColumns(presenter.DataComponent).Where(x => EditorUtils.GetEditor(x.DataType) is not null).Select(x => x.ColumnName);
                 }
                 else
                 {
@@ -186,7 +186,7 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
         public DynamicGridColumn GetColumn(string column)
         {
             var table = presenter.DataComponent.GetTable(presenter.Properties.Table);
-            var coreCol = table.CoreColumns.First(x => x.ColumnName == column);
+            var coreCol = table.GetColumns(presenter.DataComponent).First(x => x.ColumnName == column);
             return DynamicGridColumn.FromCoreColumn(coreCol)!;
         }
 

+ 1 - 1
inabox.wpf/DynamicGrid/Editors/ButtonEditor/ListEditorControl.cs

@@ -63,7 +63,7 @@ public class ListEditorControl : DynamicEditorControl<IList, ListEditor>
                     options.DirectEdit = true;
             };
             idg.Reconfigure();
-            var window = DynamicGridUtils.CreateGridWindow("License Mappings", idg);
+            var window = DynamicGridUtils.CreateGridWindow("Edit Items", idg);
             if (ListWidth > 0)
                 window.Width = ListWidth;
             if (ListHeight > 0)