Просмотр исходного кода

Merge remote-tracking branch 'origin/kenric' into frank

frankvandenbos 6 месяцев назад
Родитель
Сommit
83502c1c9c

+ 11 - 2
InABox.Core/CoreUtils.cs

@@ -478,8 +478,17 @@ namespace InABox.Core
                     return Guid.Empty;
                 }
 
-            if (value is IEnumerable<object> objList && type == typeof(Guid))
-                return objList.Select(x => ChangeType<Guid>(x)).ToArray();
+            if (value is IEnumerable<object> objList)
+            {
+                if(type == typeof(Guid))
+                {
+                    return objList.Select(x => ChangeType<Guid>(x)).ToArray();
+                }
+                else if (type.IsArray)
+                {
+                    return objList.Select(x => ChangeType(x, type.GetElementType())).ToArray();
+                }
+            }
 
             if (value is byte[] && type == typeof(Guid))
                 return new Guid(value as byte[]);

+ 2 - 12
InABox.Core/Query/Column.cs

@@ -753,29 +753,19 @@ namespace InABox.Core
     {
         public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
         {
-            if(value is null)
+            if(!(value is IColumn col))
             {
                 writer.WriteNull();
                 return;
             }
 
-            var property = (CoreUtils.GetPropertyValue(value, "Expression") as Expression)
-                ?? throw new Exception("'Column.Expression' may not be null");
-
-            var prop = CoreUtils.ExpressionToString(value.GetType().GenericTypeArguments[0], property, true);
-
-            var name = CoreUtils.GetPropertyValue(value, "Property") as string;
-
             writer.WriteStartObject();
             
             writer.WritePropertyName("$type");
             writer.WriteValue(value.GetType().FullName);
-            
-            writer.WritePropertyName("Expression");
-            writer.WriteValue(prop);
 
             writer.WritePropertyName("Property");
-            writer.WriteValue(name);
+            writer.WriteValue(col.Name);
 
             writer.WriteEndObject();
         }

+ 9 - 1
InABox.Core/Query/Filter.cs

@@ -2075,8 +2075,16 @@ namespace InABox.Core
                     var wrapper = Serialization.Deserialize<SubQuerySerializationWrapper>((string)val);
                     val = Activator.CreateInstance(typeof(SubQuery<>).MakeGenericType(CoreUtils.GetEntity(wrapper.Type)), null, null);
                     Serialization.DeserializeInto(wrapper.SerializedSubquery, val);
+                    result.Value = val;
+                }
+                else if(op == Operator.InList || op == Operator.NotInList)
+                {
+                    result.Value = CoreUtils.ChangeType(val, result.Type.MakeArrayType());
+                }
+                else
+                {
+                    result.Value = CoreUtils.ChangeType(val, result.Type);
                 }
-                result.Value = CoreUtils.ChangeType(val, result.Type);
             }
             else if(data.TryGetValue("FilterConstant", out var filterConstant))
             {

+ 8 - 24
inabox.wpf/DynamicGrid/DynamicGridColumn/DynamicGridColumns.cs

@@ -53,24 +53,8 @@ public class DynamicGridColumns : List<DynamicGridColumn>, IGlobalConfigurationS
         return this;
     }
 
-    public DynamicGridColumn Add<TType, TProperty>(Expression<Func<TType, TProperty>> member, int width, string caption, string format,
-        Alignment alignment)
-    {
-        var name = CoreUtils.GetFullPropertyName(member, ".");
-        var result = new DynamicGridColumn
-        {
-            ColumnName = name,
-            Caption = caption,
-            Width = width,
-            Format = format,
-            Alignment = alignment
-        };
-        Add(result);
-        return result;
-    }
-
-    public static DynamicGridColumn CreateColumn<TType, TProperty>(
-        Expression<Func<TType, TProperty>> member,
+    public static DynamicGridColumn CreateColumn<TType>(
+        Expression<Func<TType, object?>> member,
         int? width = null,
         string? caption = null,
         string? format = null,
@@ -89,8 +73,8 @@ public class DynamicGridColumns : List<DynamicGridColumn>, IGlobalConfigurationS
         return col;
     }
 
-    public DynamicGridColumn Add<TType, TProperty>(
-        Expression<Func<TType, TProperty>> member,
+    public DynamicGridColumn Add<TType>(
+        Expression<Func<TType, object?>> member,
         int? width = null,
         string? caption = null,
         string? format = null,
@@ -105,12 +89,12 @@ public class DynamicGridColumns : List<DynamicGridColumn>, IGlobalConfigurationS
 
 public class DynamicGridColumns<T> : DynamicGridColumns
 {
-    public DynamicGridColumn Add<TProperty>(Expression<Func<T, TProperty>> member, int width, string caption, string format, Alignment alignment)
+    public DynamicGridColumn Add(Expression<Func<T, object?>> member, int width, string caption, string format, Alignment alignment)
     {
-        return Add<T, TProperty>(member, width, caption, format, alignment);
+        return Add<T>(member, width, caption, format, alignment);
     }
-    public DynamicGridColumn Add<TProperty>(
-        Expression<Func<T, TProperty>> member,
+    public DynamicGridColumn Add(
+        Expression<Func<T, object?>> member,
         int? width = null,
         string? caption = null,
         string? format = null,

+ 2 - 1
inabox.wpf/DynamicGrid/DynamicGridFilterEditor.xaml

@@ -6,7 +6,8 @@
         xmlns:wpf="clr-namespace:InABox.Wpf"
         xmlns:local="clr-namespace:InABox.DynamicGrid"
         mc:Ignorable="d"
-        Title="DynamicGridFilterEditor" Height="450" Width="800">
+        Title="DynamicGridFilterEditor" Height="450" Width="800"
+                    WindowStartupLocation="CenterScreen">
     <Grid x:Name="Grid">
         <Grid.RowDefinitions>
             <RowDefinition Height="*" />

+ 2 - 1
inabox.wpf/DynamicGrid/Editors/FilterEditor/FilterEditorWindow.xaml

@@ -7,7 +7,8 @@
         xmlns:wpf="clr-namespace:InABox.Wpf"
         xmlns:sf="http://schemas.syncfusion.com/wpf"
         mc:Ignorable="d"
-        Title="FilterEditorWindow" Height="450" Width="800">
+        Title="FilterEditorWindow" Height="450" Width="800"
+                    WindowStartupLocation="CenterScreen">
     <Grid x:Name="Grid">
         <Grid.RowDefinitions>
             <RowDefinition Height="*"/>

+ 6 - 0
inabox.wpf/DynamicGrid/Editors/FilterEditor/Nodes/ValueNodes/ArrayValueNode.cs

@@ -4,6 +4,8 @@ using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
+using InABox.Core;
+using netDxf.Tables;
 using Syncfusion.Windows.Shared;
 
 namespace InABox.DynamicGrid;
@@ -25,6 +27,10 @@ public class ArrayValueNode<TValueNode> : ValueNode where TValueNode : ValueNode
             {
                 list = objList.Cast<object?>().ToList();
             }
+            else if (value is ISubQuery)
+            {
+                list = new();
+            }
             else
             {
                 list = new List<object?> { value };

+ 1 - 1
inabox.wpf/DynamicGrid/Editors/FilterEditor/Nodes/ValueNodes/ArrayValueNodePopup.xaml

@@ -6,7 +6,7 @@
         xmlns:local="clr-namespace:InABox.DynamicGrid"
         xmlns:wpf="clr-namespace:InABox.Wpf"
         mc:Ignorable="d"
-        Title="Edit List" Height="450" Width="800">
+        Title="Edit List" Height="450" Width="800" WindowStartupLocation="CenterScreen">
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="*"/>

+ 9 - 3
inabox.wpf/DynamicGrid/Editors/FilterEditor/Nodes/ValueNodes/ArrayValueNodePopup.xaml.cs

@@ -92,9 +92,8 @@ namespace InABox.DynamicGrid
             AddValue(null);
         }
 
-        public void AddValue(object? value)
+        public void AddValue(object? value, int? index = null)
         {
-
             var node = new TValueNode()
             {
                 Margin = new Thickness(0, 0, 5, 5)
@@ -124,7 +123,14 @@ namespace InABox.DynamicGrid
             {
                 RemoveNode(node);
             };
-            Nodes.Add(new(removeButton, node));
+            if(index is null || index.Value >= Nodes.Count)
+            {
+                Nodes.Add(new(removeButton, node));
+            }
+            else
+            {
+                Nodes.Insert(index.Value, new(removeButton, node));
+            }
 
             if (!bChanging)
             {

+ 14 - 2
inabox.wpf/DynamicGrid/Editors/FilterEditor/Nodes/ValueNodes/SubQueryNodePopup.xaml

@@ -6,7 +6,8 @@
         xmlns:local="clr-namespace:InABox.DynamicGrid"
         xmlns:wpf="clr-namespace:InABox.Wpf"
         mc:Ignorable="d"
-        Title="Edit Subquery" Height="450" Width="800">
+        Title="Edit Subquery" Height="450" Width="800"
+                    WindowStartupLocation="CenterScreen">
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="*"/>
@@ -29,7 +30,18 @@
                     <Label Grid.Row="1" Grid.Column="0" Content="Return Value:" Margin="0,0,5,0"/>
 
                     <ComboBox x:Name="Type" Grid.Row="0" Grid.Column="1" Margin="0,0,0,5" Padding="5"/>
-                    <ComboBox x:Name="Property" Grid.Row="1" Grid.Column="1" Margin="0,0,0,5" Padding="5"/>
+                    <Button x:Name="Property" Grid.Row="1" Grid.Column="1" Margin="0,0,0,5" Padding="5,5,5,5"
+                            VerticalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalContentAlignment="Center"
+                            BorderBrush="#ACACAC"
+                            Click="Property_Click"
+                            Content=" ">
+                        <Button.Background>
+                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
+                                <GradientStop Color="#F0F0F0" Offset="0.0"/>
+                                <GradientStop Color="#E5E5E5" Offset="1.0"/>
+                            </LinearGradientBrush>
+                        </Button.Background>
+                    </Button>
                 </Grid>
             </ScrollViewer>
         </Border>

+ 25 - 7
inabox.wpf/DynamicGrid/Editors/FilterEditor/Nodes/ValueNodes/SubQueryNodePopup.xaml.cs

@@ -21,6 +21,7 @@ namespace InABox.DynamicGrid
     /// </summary>
     public partial class SubQueryNodePopup : ThemableWindow
     {
+        private string[] ColumnNames = [];
 
         public Type? QueryType
         {
@@ -42,12 +43,14 @@ namespace InABox.DynamicGrid
             }
         }
 
+        private string? _column;
         public string? Column
         {
-            get => Property.SelectedItem as string;
+            get => _column;
             set
             {
-                Property.SelectedItem = value;
+                _column = value;
+                Property.Content = value.IsNullOrWhiteSpace() ? " " : value;
             }
         }
         public IFilter? Filter
@@ -106,19 +109,24 @@ namespace InABox.DynamicGrid
         private void UpdateQueryType()
         {
             var type = (Type.SelectedItem as TypeEntry)?.Type;
+            Column = null;
 
-            Property.Items.Clear();
             if(type != null)
             {
-                foreach (var property in CoreUtils.PropertyList(type, x => true, true).Keys)
-                {
-                    Property.Items.Add(property);
-                }
                 Filter = Activator.CreateInstance(typeof(Filter<>).MakeGenericType(type)) as IFilter;
+                Property.IsEnabled = true;
+
+                var properties = DatabaseSchema.Properties(type)
+                    .Where(x => x.IsSerializable)
+                    .Select(x => x.Name)
+                    .ToList();
+                properties.Sort();
+                ColumnNames = properties.ToArray();
             }
             else
             {
                 Filter = null;
+                Property.IsEnabled = false;
             }
         }
 
@@ -149,5 +157,15 @@ namespace InABox.DynamicGrid
             DialogResult = true;
             Close();
         }
+
+        private void Property_Click(object sender, RoutedEventArgs e)
+        {
+            var type = (Type.SelectedItem as TypeEntry)?.Type;
+
+            if(type is not null && DynamicGridColumnNameSelectorGrid.SelectColumnName(type, ColumnNames, out var value))
+            {
+                Column = value.IsNullOrWhiteSpace() ? null : value;
+            }
+        }
     }
 }