Browse Source

wpf: Added some handlers for when forms are saved in DynamicGridUtils.PopulateMenu

Kenric Nugteren 3 weeks ago
parent
commit
b0818f3a19

+ 4 - 6
InABox.Core/Query/Filter.cs

@@ -782,6 +782,10 @@ namespace InABox.Core
         {
             return new FilterBuilder<T, TProp>(new Filter<T>(property));
         }
+        public static FilterBuilder<T, TProp> Where<TProp>(string property)
+        {
+            return new FilterBuilder<T, TProp>(new Filter<T>(property));
+        }
 
         private Filter(IProperty property) : this()
         {
@@ -794,12 +798,6 @@ namespace InABox.Core
             _property = property;
         }
 
-        public Filter(string property, Operator op, object value) : this(property)
-        {
-            Operator = op;
-            Value = value;
-        }
-
         #endregion
 
         #region And

+ 21 - 4
inabox.wpf/DynamicGrid/DynamicGridUtils.cs

@@ -17,6 +17,7 @@ using System.Data;
 using System.Windows.Media;
 using AutoProperties;
 using InABox.WPF;
+using System.Windows.Threading;
 
 namespace InABox.DynamicGrid;
 
@@ -761,11 +762,21 @@ public static class DynamicGridUtils
         bool editOnAdd = false,
         DynamicFormEditWindow.CustomiseDynamicFormEditWindow? customiseEditor = null,
         DynamicEntityFormGrid<TEntityForm, TEntity, TEntityLink>.CustomiseNewFormHandler? customiseNewForm = null,
-        ISubPanelHost? nonModalHost = null)
+        ISubPanelHost? nonModalHost = null,
+        Action? onSaved = null)
         where TEntityForm : BaseEntityForm<TEntity, TEntityLink, TEntityForm>, new()
         where TEntity : Entity
         where TEntityLink : BaseObject, IEntityLink<TEntity>, new()
     {
+        if(onSaved is not null)
+        {
+            var oldOnSaved = onSaved;
+            onSaved = () =>
+            {
+                Application.Current.Dispatcher.BeginInvoke(oldOnSaved);
+            };
+        }
+
         var task = Task.Run(() =>
         {
             return new Client<TEntityForm>().Query(
@@ -783,6 +794,7 @@ public static class DynamicGridUtils
                         if (task.Result.shouldSave)
                         {
                             task.Result.model!.Update(null);
+                            onSaved?.Invoke();
                         }
                     }, TaskContinuationOptions.OnlyOnRanToCompletion);
             }
@@ -791,6 +803,7 @@ public static class DynamicGridUtils
                 if (DynamicFormEditWindow.EditDigitalForm(form, out var dataModel, customise: customiseEditor))
                 {
                     dataModel.Update(null);
+                    onSaved?.Invoke();
                 }
             }
         }
@@ -801,9 +814,8 @@ public static class DynamicGridUtils
             try
             {
                 var entity = loadEntity();
-                var filter = LookupFactory.DefineChildFilter<TEntity, DigitalForm>(new TEntity[] { entity });
-                if (filter == null)
-                    filter = LookupFactory.DefineLookupFilter<TEntityForm, DigitalForm, DigitalFormLink>(x => x.Form, Array.Empty<TEntityForm>());
+                var filter = LookupFactory.DefineChildFilter<TEntity, DigitalForm>([entity])
+                    ?? LookupFactory.DefineLookupFilter<TEntityForm, DigitalForm, DigitalFormLink>(x => x.Form, []);
 
                 var select = new MultiSelectDialog<DigitalForm>(
                     filter,
@@ -829,6 +841,7 @@ public static class DynamicGridUtils
                         else
                         {
                             Client.Save(form, "Added by user");
+                            onSaved?.Invoke();
                         }
                     }
                 };
@@ -846,6 +859,10 @@ public static class DynamicGridUtils
 
             var grid = new DynamicEntityFormGrid<TEntityForm, TEntity, TEntityLink>(loadEntity());
             grid.CustomiseNewForm = customiseNewForm;
+            grid.OnChanged += (o, e) =>
+            {
+                onSaved?.Invoke();
+            };
 
             grid.Refresh(true, true);
             grid.Margin = new Thickness(5);

+ 2 - 0
inabox.wpf/DynamicGrid/Grids/DynamicEntityFormGrid.cs

@@ -19,6 +19,7 @@ public class DynamicEntityFormGrid<TForm, TEntity, TEntityLink> : DynamicDataGri
     public delegate void CustomiseNewFormHandler(TEntity entity, TForm form);
 
     public CustomiseNewFormHandler? CustomiseNewForm;
+    public Action? OnSaved;
 
     protected virtual TEntity Entity { get; set; }
 
@@ -172,6 +173,7 @@ public class DynamicEntityFormGrid<TForm, TEntity, TEntityLink> : DynamicDataGri
         if (DynamicFormEditWindow.EditDigitalForm(form, out var dataModel))
         {
             dataModel.Update(null);
+            DoChanged();
             return true;
         }
         return false;