Browse Source

Added Editable.DisabledOnDirectEdit and utility methods.
Extracted LoadEditorCOlumns into utiltiy method.

Kenric Nugteren 1 year ago
parent
commit
1a28e1a843

+ 1 - 1
InABox.Core/Column.cs

@@ -440,7 +440,7 @@ namespace InABox.Core
                     bOK = (types.Any(x => x.Equals(ColumnType.IncludeForeignKeys)) && bIsForeignKey) ||
                           (!types.Any(x => x.Equals(ColumnType.ExcludeVisible)) && visible.Equals(Visible.Default)) ||
                           (types.Any(x => x.Equals(ColumnType.IncludeOptional)) && visible.Equals(Visible.Optional)) ||
-                          (types.Any(x => x.Equals(ColumnType.IncludeEditable)) && !editable.Equals(Editable.Hidden));
+                          (types.Any(x => x.Equals(ColumnType.IncludeEditable)) && editable.ColumnVisible());
                 }
 
                 var property = bOK ? DatabaseSchema.Property(typeof(T), prop.Name) : null;

+ 1 - 1
InABox.Core/DigitalForms/Layouts/DFLayout.cs

@@ -582,7 +582,7 @@ namespace InABox.Core
             foreach (var property in properties)
             {
                 var editor = EditorUtils.GetPropertyEditor(entityType, property);
-                if (editor != null && !(editor is NullEditor) && editor.Editable != Editable.Hidden)
+                if (editor != null && !(editor is NullEditor) && editor.Editable.EditorVisible())
                 {
                     var field = GenerateLayoutFieldFromEditor(editor);
                     if (field != null)

+ 1 - 1
InABox.Core/DigitalForms/Layouts/Fields/DFLayoutFieldProperties.cs

@@ -101,7 +101,7 @@ namespace InABox.Core
                         {
                             var info = CoreUtils.GetProperty(type, prop);
                             var editor = info.GetEditor();
-                            if (editor != null && editor.Editable == Editable.Enabled)
+                            if (editor != null && editor.Editable.IsEditable())
                             {
                                 var bOK = true;
                                 if (prop.Contains("."))

+ 27 - 1
InABox.Core/Editors/Utils/Editable.cs

@@ -4,6 +4,32 @@
     {
         Enabled,
         Disabled,
-        Hidden
+        Hidden,
+        /// <summary>
+        /// Disabled when using a DynamicGrid with DirectEdit option set, but enabled in editor
+        /// </summary>
+        DisabledOnDirectEdit
+    }
+
+    public static class EditableUtils
+    {
+        public static bool IsEditable(this Editable editable)
+        {
+            return editable == Editable.Enabled || editable == Editable.DisabledOnDirectEdit;
+        }
+        public static bool IsDirectEditable(this Editable editable)
+        {
+            return editable == Editable.Enabled;
+        }
+
+        public static bool ColumnVisible(this Editable editable)
+        {
+            return editable != Editable.Hidden;
+        }
+
+        public static bool EditorVisible(this Editable editable)
+        {
+            return editable != Editable.Hidden;
+        }
     }
 }

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

@@ -86,7 +86,7 @@ namespace InABox.DynamicGrid
                 if (!DirectEdit)
                     continue;
 
-                if (col.Editor.Editable == Editable.Enabled && col.ColumnName.Split('.').Length <= 2)
+                if (col.Editor.Editable.IsEditable() && col.ColumnName.Split('.').Length <= 2)
                     result.Add(col);
             }
             result.Sort((a, b) => a.ColumnName.CompareTo(b.ColumnName));

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

@@ -261,29 +261,7 @@ namespace InABox.DynamicGrid
 
         public Columns<TEntity> LoadEditorColumns()
         {
-            var result = new Columns<TEntity>().Default(
-                ColumnType.IncludeOptional,
-                ColumnType.IncludeForeignKeys,
-                ColumnType.IncludeUserProperties,
-                ColumnType.IncludeEditable);
-            var cols = DataColumns();
-            foreach (var col in cols.Items)
-                if (!result.Items.Any(x => string.Equals(x.Property, col.Property)))
-                    result.Add(col.Property);
-
-            foreach (var col in result.Items)
-            {
-                var prop = DatabaseSchema.Property(typeof(TEntity), col.Property);
-                if (prop?.Editor is DataLookupEditor dataLookup)
-                {
-                    foreach (var lookupColumn in LookupFactory.DefineFilterColumns<TEntity>(dataLookup.Type).ColumnNames())
-                    {
-                        result.Add(lookupColumn);
-                    }
-                }
-            }
-
-            return result;
+            return DynamicGridUtils.LoadEditorColumns(DataColumns());
         }
 
         private Filter<TEntity>? GetRowFilter(CoreRow row)

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml.cs

@@ -368,7 +368,7 @@ namespace InABox.DynamicGrid
                     editor.Caption = propEditor.Caption;
                 }
 
-                if (ReadOnly && editor.Editable.Equals(Editable.Enabled))
+                if (ReadOnly && editor.Editable.IsEditable())
                     editor.Editable = Editable.Disabled;
                 return editor;
             }

+ 3 - 3
inabox.wpf/DynamicGrid/DynamicEditorGrid.xaml.cs

@@ -196,7 +196,7 @@ namespace InABox.DynamicGrid
                 {
                     element.EditorDefinition = editor;
 
-                    element.IsEnabled = editor.Editable == Editable.Enabled;
+                    element.IsEnabled = editor.Editable.IsEditable();
 
                     if (!string.IsNullOrWhiteSpace(editor.ToolTip))
                     {
@@ -497,7 +497,7 @@ namespace InABox.DynamicGrid
                     OnGridCustomiseEditor?.Invoke(this, column, editor);
                 }
 
-                if (editor != null && editor.Editable != Editable.Hidden)
+                if (editor != null && editor.Editable.EditorVisible())
                 {
                     var page = string.IsNullOrWhiteSpace(editor.Page) ? iProp is StandardProperty ? "General" : "Custom Fields" : editor.Page;
                     var editPage = GetEditPage(page);
@@ -515,7 +515,7 @@ namespace InABox.DynamicGrid
                         {
                             OnGridCustomiseEditor?.Invoke(this, new DynamicGridColumn { ColumnName = parent.Name }, parentEditor);
                         }
-                        if(parentEditor is not null && parentEditor.Editable != Editable.Hidden)
+                        if(parentEditor is not null && parentEditor.Editable.EditorVisible())
                         {
                             var page = string.IsNullOrWhiteSpace(parentEditor.Page)
                                 ? parent is StandardProperty

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

@@ -1853,7 +1853,7 @@ namespace InABox.DynamicGrid
                     var cellstyle = new Style();
                     if (Options.Contains(DynamicGridOption.DirectEdit))
                     {
-                        if (prop.Editor is null || prop.Editor.Editable != Editable.Enabled)
+                        if (prop.Editor is null || !prop.Editor.Editable.IsDirectEditable())
                         {
                             cellstyle.Setters.Add(new Setter(BackgroundProperty, new SolidColorBrush(Colors.WhiteSmoke)));
                             newcol.AllowEditing = false;

+ 32 - 1
inabox.wpf/DynamicGrid/DynamicGridUtils.cs

@@ -355,9 +355,40 @@ namespace InABox.DynamicGrid
 
         #endregion
 
+        #region Columns
+
+        public static Columns<T> LoadEditorColumns<T>(Columns<T> additional)
+        {
+            var result = new Columns<T>().Default(
+                ColumnType.IncludeOptional,
+                ColumnType.IncludeForeignKeys,
+                ColumnType.IncludeUserProperties,
+                ColumnType.IncludeEditable);
+
+            foreach (var col in additional.Items)
+                if (!result.Items.Any(x => string.Equals(x.Property, col.Property)))
+                    result.Add(col.Property);
+
+            foreach (var col in result.Items)
+            {
+                var prop = DatabaseSchema.Property(typeof(T), col.Property);
+                if (prop?.Editor is DataLookupEditor dataLookup)
+                {
+                    foreach (var lookupColumn in LookupFactory.DefineFilterColumns<T>(dataLookup.Type).ColumnNames())
+                    {
+                        result.Add(lookupColumn);
+                    }
+                }
+            }
+
+            return result;
+        }
+
+        #endregion
+
         #region Editor Values
 
-        
+
 
         public static Dictionary<string, object?> UpdateEditorValue(BaseObject[] items, string name, object value)
         {

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

@@ -207,6 +207,7 @@ namespace InABox.DynamicGrid
             var result = new TMany();
             var prop = (IEntityLink)property.GetValue(result);
             prop.ID = Item.ID;
+            prop.Synchronise(Item);
             return result;
         }
 

+ 1 - 1
inabox.wpf/DynamicGrid/Editors/LookupEditor/LookupEditorControl.cs

@@ -102,7 +102,7 @@ namespace InABox.DynamicGrid
             //if ((value != null) && Lookups.ContainsKey(value))
             //    Editor.SelectedIndex = Lookups.Keys.ToList().IndexOf(value);
 
-            Editor.IsEnabled = EditorDefinition.Editable == Editable.Enabled;
+            Editor.IsEnabled = EditorDefinition.Editable.IsEditable();
         }
 
 

+ 1 - 1
inabox.wpf/DynamicGrid/Editors/MultiLookupEditor/MultiLookupEditorControl.cs

@@ -98,7 +98,7 @@ namespace InABox.DynamicGrid
             //if ((value != null) && Lookups.ContainsKey(value))
             //    Editor.SelectedIndex = Lookups.Keys.ToList().IndexOf(value);
 
-            Editor.IsEnabled = EditorDefinition.Editable == Editable.Enabled;
+            Editor.IsEnabled = EditorDefinition.Editable.IsEditable();
         }
 
         public override int DesiredHeight()