Browse Source

Enforced stripping out of Non-persistent columns when querying data
Fixed Lookups for Digital Forms
Corrected Issues with Geofence Editor

frogsoftware 2 weeks ago
parent
commit
aec66ea428

+ 8 - 0
InABox.Core/Client/Client.cs

@@ -558,6 +558,14 @@ namespace InABox.Clients
             {
                 using var timer = new Profiler<TEntity>(false);
                 CheckSupported();
+                
+                if (columns != null)
+                {
+                    var nonpersistent = columns.Where(x => !x.PropertyDefinition.IsPersistable).ToArray();
+                    foreach (var column in nonpersistent)
+                        columns.Remove(column.Property);
+                }
+                
                 var result = _client.Query(filter, columns, orderby, range);
                 timer.Log(result.Rows.Count);
                 return result;

+ 3 - 2
inabox.wpf/DynamicGrid/DynamicGridUtils.cs

@@ -782,8 +782,9 @@ public static class DynamicGridUtils
         addForm.Click += (o, e) =>
         {
             var entity = loadEntity();
-            var filter = LookupFactory.DefineChildFilter<TEntity, DigitalForm>(new TEntity[] { entity })
-                ?? LookupFactory.DefineLookupFilter<TEntityForm, DigitalForm, DigitalFormLink>(x => x.Form, Array.Empty<TEntityForm>());
+            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 select = new MultiSelectDialog<DigitalForm>(
                 filter,

+ 46 - 36
inabox.wpf/DynamicGrid/Editors/AddressEditor/GeofenceEditor.xaml

@@ -16,54 +16,53 @@
         <Grid.RowDefinitions>
             <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
+        
         <syncfusion:SfMap 
             x:Name="Map" 
             BorderBrush="Gray"
             BorderThickness="0.75" 
-            ZoomLevel="19" 
-            MinZoom="19"
-            MaxZoom="19"
+            ZoomLevel="18" 
+            MinZoom="18"
+            MaxZoom="18"
             EnableZoom="False"
             EnablePan="False"
             Grid.Row="0"
             Grid.Column="0"
-            MouseUp="Map_OnMouseUp">
+            PreviewMouseUp="Map_OnPreviewMouseUp">
             
-            <!-- <syncfusion:SfMap.Layers> -->
-            <!--     <local:GoogleImageryLayer -->
-            <!--         Type="Satellite" -->
-            <!--         x:Name="ImageryLayer" -->
-            <!--         Center="-31.95105, 115.85939" -->
-            <!--         Radius="10" -->
-            <!--         > -->
-            <!--         <syncfusion:ImageryLayer.SubShapeFileLayers> -->
-            <!--             <syncfusion:SubShapeFileLayer x:Name="subLayer"> -->
-            <!--                 <syncfusion:SubShapeFileLayer.MapElements> -->
-            <!-- -->
-            <!--                     <syncfusion:MapPolygon  -->
-            <!--                         x:Name="Polygon"  -->
-            <!--                         Stroke="Firebrick"  -->
-            <!--                         StrokeThickness="0.75"> -->
-            <!--                         <syncfusion:MapPolygon.Fill> -->
-            <!--                             <SolidColorBrush Color="Salmon" Opacity="0.5"/>      -->
-            <!--                         </syncfusion:MapPolygon.Fill> -->
-            <!--                     </syncfusion:MapPolygon> -->
-            <!--                      -->
-            <!--                 </syncfusion:SubShapeFileLayer.MapElements> -->
-            <!--             </syncfusion:SubShapeFileLayer> -->
-            <!--         </syncfusion:ImageryLayer.SubShapeFileLayers> -->
-            <!--          -->
-            <!--     </local:GoogleImageryLayer> -->
-            <!-- </syncfusion:SfMap.Layers> -->
+            <syncfusion:SfMap.Layers>
+                <local:GoogleImageryLayer
+                    x:Name="ImageryLayer"
+                    Center="-31.95105, 115.85939"
+                    Radius="11"
+                    >
+                    <syncfusion:ImageryLayer.SubShapeFileLayers>
+                        <syncfusion:SubShapeFileLayer x:Name="ShapeLayer">
+                            <syncfusion:SubShapeFileLayer.MapElements>
+           
+                                <syncfusion:MapPolygon 
+                                    x:Name="Polygon" 
+                                    Stroke="Firebrick" 
+                                    StrokeThickness="0.75">
+                                    <syncfusion:MapPolygon.Fill>
+                                        <SolidColorBrush Color="Salmon" Opacity="0.5"/>     
+                                    </syncfusion:MapPolygon.Fill>
+                                </syncfusion:MapPolygon>
+                                
+                            </syncfusion:SubShapeFileLayer.MapElements>
+                        </syncfusion:SubShapeFileLayer>
+                    </syncfusion:ImageryLayer.SubShapeFileLayers>
+                    
+                </local:GoogleImageryLayer>
+            </syncfusion:SfMap.Layers>
         </syncfusion:SfMap>
         
         <Border
             x:Name="SearchBar"
+            VerticalAlignment="Top"
             Grid.Row="0"
             Grid.Column="0"
-            HorizontalAlignment="Stretch"
-            VerticalAlignment="Top"
-            Margin="10,10,10,0"
+            Margin="5"
             Padding="5"
             Background="WhiteSmoke"
             CornerRadius="5" 
@@ -116,9 +115,8 @@
         </Border>
         
         <DockPanel 
-            VerticalAlignment="Bottom" 
-            HorizontalAlignment="Stretch"
-            Margin="10,0,10,10" 
+            Margin="5" 
+            VerticalAlignment="Bottom"
             Grid.Row="0"
             Grid.Column="0">
             
@@ -144,6 +142,18 @@
                 <Image Source="../../../Resources/zoomin.png" />
             </Button>
             
+            <Button 
+                x:Name="CloseEditor" 
+                Height="50" 
+                Width="50"
+                Padding="5"
+                Margin="0,0,5,0"
+                DockPanel.Dock="Left"
+                Click="CloseEditor_OnClick"
+                Visibility="Collapsed">
+                <Image Source="../../../Resources/tick.png" />
+            </Button>
+            
             <Button 
                 x:Name="SetCoordinates" 
                 Height="50" 

+ 114 - 65
inabox.wpf/DynamicGrid/Editors/AddressEditor/GeofenceEditor.xaml.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Net.Http;
+using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Input;
@@ -10,11 +11,13 @@ using Geocoding;
 using Geocoding.Google;
 using InABox.Clients;
 using InABox.Core;
+using InABox.WPF;
 using Nominatim.API.Geocoders;
 using Nominatim.API.Models;
 using Nominatim.API.Web;
 using Syncfusion.UI.Xaml.Maps;
 using Address = InABox.Core.Address;
+using OnAfterLoad = InABox.DynamicGrid.OnAfterLoad;
 using Point = System.Windows.Point;
 
 namespace InABox.Wpf.DynamicGrid;
@@ -25,31 +28,37 @@ public partial class GeofenceEditor : Window
     
     GeoFenceDefinition _definition = null;
 
-    private ImageryLayer ImageryLayer;
-    public MapPolygon Polygon;
+    //private ImageryLayer ImageryLayer;
+    //private MapPolygon Polygon;
+    //private SubShapeFileLayer ShapeLayer;
+
+    private bool _canEdit = false;
     
     public GeofenceEditor(Address address, bool canEdit)
     {
+        _canEdit = canEdit;
         Address = address;
         _definition = Serialization.Deserialize<GeoFenceDefinition>(address.Geofence) ?? new GeoFenceDefinition();
         
         InitializeComponent();
-
-        ImageryLayer = string.IsNullOrWhiteSpace(CoreUtils.GoogleAPIKey)
-            ? new ImageryLayer()
-            : new GoogleImageryLayer() { Type = GoogleImageryLayerType.Satellite };
-        ImageryLayer.Radius = 10;
         
-        Map.Layers.Add(ImageryLayer);
-
-        Polygon = new MapPolygon()
-        {
-            Fill = new SolidColorBrush(Colors.LightSalmon) { Opacity = 0.5 },
-            Stroke = new SolidColorBrush(Colors.Firebrick),
-            StrokeThickness = 0.75,
-        };
-        var layer = new SubShapeFileLayer() { MapElements = new ObservableCollection<MapElement>([Polygon]) }; 
-        ImageryLayer.SubShapeFileLayers = new ObservableCollection<SubShapeFileLayer>([layer]);
+        // ImageryLayer = string.IsNullOrWhiteSpace(CoreUtils.GoogleAPIKey)
+        //     ? new ImageryLayer()
+        //     : new GoogleImageryLayer() { Type = GoogleImageryLayerType.Satellite };
+        // ImageryLayer.Radius = 10;
+        //
+        // Map.Layers.Add(ImageryLayer);
+        //
+        // Polygon = new MapPolygon()
+        // {
+        //     Fill = new SolidColorBrush(Colors.LightSalmon) { Opacity = 0.5 },
+        //     Stroke = new SolidColorBrush(Colors.Firebrick),
+        //     StrokeThickness = 0.75,
+        //     Points = new CoreObservableCollection<Point>()
+        // };
+        // ShapeLayer = new SubShapeFileLayer() { MapElements = new ObservableCollection<MapElement>([Polygon]) };
+        //
+        // ImageryLayer.SubShapeFileLayers = new ObservableCollection<SubShapeFileLayer>([ShapeLayer]);
         
         SetGeometry.Visibility = canEdit ? Visibility.Visible : Visibility.Collapsed;
         SetRadius.Visibility = canEdit ? Visibility.Visible : Visibility.Collapsed;
@@ -62,13 +71,20 @@ public partial class GeofenceEditor : Window
 
         Title = $"Geofence Editor ({(string.IsNullOrWhiteSpace(CoreUtils.GoogleAPIKey) ? "OSM" : "Google")})";
 
-        if (canEdit && string.IsNullOrWhiteSpace(Address.Geofence))
+        
+        
+    }
+
+    public override void OnApplyTemplate()
+    {
+        base.OnApplyTemplate();
+        if (_canEdit && string.IsNullOrWhiteSpace(Address.Geofence))
             Task.Run(CheckAddress);
         else
             SetupMap();
-        
     }
-    
+
+
     private class HttpClientFactory : IHttpClientFactory
     {
         private static HttpClient? _client;
@@ -242,8 +258,12 @@ public partial class GeofenceEditor : Window
 
     private void UpdateMap()
     {
-       
-        Polygon.Points = new ObservableCollection<Point>(_definition.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
+        // if (Polygon.Points is CoreObservableCollection<Point> _pts)
+        //     _pts.ReplaceRange(_definition.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
+        Polygon.Points.Clear();
+        foreach (var p in  _definition.Coordinates)
+            Polygon.Points.Add(new Point(p.Latitude, p.Longitude));
+        ShapeLayer.Refresh();
         
     }
     
@@ -274,18 +294,34 @@ public partial class GeofenceEditor : Window
     private void UpdateButtons(GeoFenceAction action)
     {
         _action = action;
-        SetGeometry.IsEnabled = action == GeoFenceAction.None || action == GeoFenceAction.Polygon;
+        
+        CloseEditor.Visibility = action == GeoFenceAction.None 
+            ? Visibility.Collapsed 
+            : Visibility.Visible;
+        
+        SetGeometry.Visibility = action == GeoFenceAction.None || action == GeoFenceAction.Polygon
+            ? Visibility.Visible
+            : Visibility.Collapsed;
+        SetGeometry.IsEnabled = action == GeoFenceAction.None;
         SetGeometry.Background = action == GeoFenceAction.Polygon
             ? Brushes.Yellow
             : Brushes.Silver;
-        SetRadius.IsEnabled = action == GeoFenceAction.None || action == GeoFenceAction.Square;
+        
+        SetRadius.Visibility = action == GeoFenceAction.None || action == GeoFenceAction.Square
+            ? Visibility.Visible
+            : Visibility.Collapsed;
+        SetRadius.IsEnabled = action == GeoFenceAction.None;
         SetRadius.Background = action == GeoFenceAction.Square
             ? Brushes.Yellow
             : Brushes.Silver;
         RadiusSlider.Visibility = action == GeoFenceAction.Square 
             ? Visibility.Visible 
             : Visibility.Collapsed;
-        SetCoordinates.IsEnabled = action == GeoFenceAction.None || action == GeoFenceAction.Coordinates;
+        
+        SetCoordinates.Visibility = action == GeoFenceAction.None || action == GeoFenceAction.Coordinates
+            ? Visibility.Visible
+            : Visibility.Collapsed;
+        SetCoordinates.IsEnabled = action == GeoFenceAction.None;
         SetCoordinates.Background = action == GeoFenceAction.Coordinates
             ? Brushes.Yellow
             : Brushes.Silver;
@@ -293,49 +329,23 @@ public partial class GeofenceEditor : Window
     
     private void SetGeometry_OnClick(object sender, RoutedEventArgs e)
     {
-        if (_action == GeoFenceAction.Polygon)
-            UpdateButtons(GeoFenceAction.None);
-        else
-        {
+        //if (_action == GeoFenceAction.Polygon)
+        //    UpdateButtons(GeoFenceAction.None);
+        //else
+        //{
             UpdateButtons(GeoFenceAction.Polygon);
             _definition.Coordinates.Clear();
             UpdateMap();
-        }
+        //}
     }
 
-    private void Map_OnMouseUp(object sender, MouseButtonEventArgs e)
-    {
-        var point = Mouse.GetPosition(Map);
-        var latlon = ImageryLayer.GetLatLonFromPoint(point);
-        var geopoint = new GeoPoint(latlon.Y, latlon.X);
-
-        if (_action == GeoFenceAction.Polygon)
-        {
-            if (!_definition.Coordinates.Any())
-                _definition.Coordinates.Add(geopoint.Copy());
-            _definition.Coordinates.Insert(_definition.Coordinates.Count - 1, geopoint.Copy());
-            Address.Geofence = Serialization.Serialize(_definition);
-            UpdateMap();
-            e.Handled = true;
-        }
-        else if (_action == GeoFenceAction.Coordinates)
-        {
-            Address.Location.Latitude = geopoint.Latitude;
-            Address.Location.Longitude = geopoint.Longitude;
-            CenterMap();
-            UpdateMap();
-            e.Handled = true;
-        }
-
-    }
-
-
+    
     private void SetRadius_OnClick(object sender, RoutedEventArgs e)
     {
-        if (_action == GeoFenceAction.Square)
-            UpdateButtons(GeoFenceAction.None);
-        else
-        {
+        //if (_action == GeoFenceAction.Square)
+        //    UpdateButtons(GeoFenceAction.None);
+        //else
+        //{
             UpdateButtons(GeoFenceAction.Square);
 
             RadiusSlider.ValueChanged -= RadiusSliderChanged;
@@ -344,7 +354,7 @@ public partial class GeofenceEditor : Window
             RadiusSlider.ValueChanged += RadiusSliderChanged;
             RecalculateSquareFence();
             UpdateMap();
-        }
+        //}
     }
 
     private void SearchAddress_Click(object sender, RoutedEventArgs e)
@@ -354,9 +364,48 @@ public partial class GeofenceEditor : Window
 
     private void SetCoordinates_OnClick(object sender, RoutedEventArgs e)
     {
-        if (_action == GeoFenceAction.Coordinates)
-            UpdateButtons(GeoFenceAction.None);
-        else
+        //if (_action == GeoFenceAction.Coordinates)
+        //    UpdateButtons(GeoFenceAction.None);
+        //else
+        {
             UpdateButtons(GeoFenceAction.Coordinates);
+            _definition.Coordinates.Clear();
+            UpdateMap();
+        }
+    }
+
+    private void CloseEditor_OnClick(object sender, RoutedEventArgs e)
+    {
+        UpdateButtons(GeoFenceAction.None);
+    }
+
+    private void Map_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
+    {
+        var point = Mouse.GetPosition(Map);
+        System.Console.WriteLine($@"Preview: {point.X}, {point.Y}");
+        Dispatcher.BeginInvoke(() =>
+        {
+            var latlon = ImageryLayer.GetLatLonFromPoint(point);
+            var geopoint = new GeoPoint(latlon.Y, latlon.X);
+        
+            if (_action == GeoFenceAction.Polygon)
+            {
+                if (!_definition.Coordinates.Any())
+                    _definition.Coordinates.Add(geopoint.Copy());
+                _definition.Coordinates.Insert(_definition.Coordinates.Count - 1, geopoint.Copy());
+                Address.Geofence = Serialization.Serialize(_definition);
+                UpdateMap();
+                e.Handled = true;
+            }
+            else if (_action == GeoFenceAction.Coordinates)
+            {
+                Address.Location.Latitude = geopoint.Latitude;
+                Address.Location.Longitude = geopoint.Longitude;
+                CenterMap();
+                UpdateMap();
+                e.Handled = true;
+            }
+        });
+        
     }
 }