Explorar el Código

Added edit button on EventGrid

Kenric Nugteren hace 4 meses
padre
commit
5a7c5caa9b

+ 4 - 2
prs.shared/Grids/EventEditor/EventEditor.xaml

@@ -55,14 +55,16 @@
                            Margin="3,0,3,0"/>
                            Margin="3,0,3,0"/>
             </StackPanel>
             </StackPanel>
             <Border BorderBrush="Gray" BorderThickness="0.75" Background="WhiteSmoke"
             <Border BorderBrush="Gray" BorderThickness="0.75" Background="WhiteSmoke"
-                    Grid.Row="0" Grid.Column="0">
+                    Grid.Row="0" Grid.Column="0"
+                    Visibility="{Binding HasTriggers,Converter={StaticResource boolToVisibility}}">
                 <Label Content="Triggers" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                 <Label Content="Triggers" VerticalAlignment="Center" HorizontalAlignment="Center"/>
             </Border>
             </Border>
             <Border BorderBrush="Gray" BorderThickness="0.75" Background="WhiteSmoke"
             <Border BorderBrush="Gray" BorderThickness="0.75" Background="WhiteSmoke"
                     Grid.Row="0" Grid.Column="2">
                     Grid.Row="0" Grid.Column="2">
                 <Label Content="Actions" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                 <Label Content="Actions" VerticalAlignment="Center" HorizontalAlignment="Center"/>
             </Border>
             </Border>
-            <ContentControl x:Name="TriggersControl" Grid.Row="1" Grid.Column="0" Margin="0,5,0,0">
+            <ContentControl x:Name="TriggersControl" Grid.Row="1" Grid.Column="0" Margin="0,5,0,0"
+                            Visibility="{Binding HasTriggers,Converter={StaticResource boolToVisibility}}">
                 <Border BorderBrush="Gray" BorderThickness="0.75" Background="White" />
                 <Border BorderBrush="Gray" BorderThickness="0.75" Background="White" />
             </ContentControl>
             </ContentControl>
             <ContentControl x:Name="ActionsControl" Grid.Row="1" Grid.Column="2" Margin="0,5,0,0">
             <ContentControl x:Name="ActionsControl" Grid.Row="1" Grid.Column="2" Margin="0,5,0,0">

+ 23 - 2
prs.shared/Grids/EventEditor/EventEditor.xaml.cs

@@ -38,6 +38,7 @@ public partial class EventEditor : UserControl, INotifyPropertyChanged
             OnPropertyChanged();
             OnPropertyChanged();
 
 
             HasType = value.HasValue && EventTypeHasEntityType(value.Value);
             HasType = value.HasValue && EventTypeHasEntityType(value.Value);
+            HasTriggers = value != Comal.Classes.EventType.Scheduled;
             DoChanged();
             DoChanged();
 
 
             UpdateEventData();
             UpdateEventData();
@@ -57,6 +58,17 @@ public partial class EventEditor : UserControl, INotifyPropertyChanged
         }
         }
     }
     }
 
 
+    private bool _hasTriggers = true;
+    public bool HasTriggers
+    {
+        get => _hasTriggers;
+        set
+        {
+            _hasTriggers = value;
+            OnPropertyChanged();
+        }
+    }
+
     private bool _hasProperties;
     private bool _hasProperties;
     public bool HasProperties
     public bool HasProperties
     {
     {
@@ -110,9 +122,9 @@ public partial class EventEditor : UserControl, INotifyPropertyChanged
                     EventDataType = inter.GenericTypeArguments[0];
                     EventDataType = inter.GenericTypeArguments[0];
                     DataModelType = inter.GenericTypeArguments[1];
                     DataModelType = inter.GenericTypeArguments[1];
 
 
-                    if (EventTypeHasEntityType(EventType.Value))
+                    if (EventTypeGetEntityType(EventType.Value, EventDataType) is Type entityType)
                     {
                     {
-                        EntityType = EventDataType.GenericTypeArguments[0];
+                        EntityType = entityType;
                     }
                     }
                 }
                 }
                 var control = Activator.CreateInstance(typeof(EventEditorControl<,>).MakeGenericType(EventDataType, DataModelType), value);
                 var control = Activator.CreateInstance(typeof(EventEditorControl<,>).MakeGenericType(EventDataType, DataModelType), value);
@@ -154,6 +166,15 @@ public partial class EventEditor : UserControl, INotifyPropertyChanged
     {
     {
         return EventUtils.GetEventType(eventType).HasInterface(typeof(IEntityEvent<>));
         return EventUtils.GetEventType(eventType).HasInterface(typeof(IEntityEvent<>));
     }
     }
+    private Type? EventTypeGetEntityType(EventType eventType, Type eventDataType)
+    {
+        var evType = EventUtils.GetEventType(eventType);
+        var entType = evType?.GetInterfaceDefinition(typeof(IEntityEvent<>))?.GenericTypeArguments[0];
+        if (evType is null || entType is null) return null;
+
+        var idx = Array.IndexOf(evType.GetGenericArguments(), entType);
+        return eventDataType.GenericTypeArguments[idx];
+    }
 
 
     private void UpdateEventData()
     private void UpdateEventData()
     {
     {

+ 35 - 0
prs.shared/Grids/EventGrid.cs

@@ -21,6 +21,7 @@ public class EventGrid : DynamicDataGrid<Event>
 {
 {
     private readonly BitmapImage _email = InABox.Wpf.Resources.email.AsBitmapImage();
     private readonly BitmapImage _email = InABox.Wpf.Resources.email.AsBitmapImage();
     private readonly BitmapImage _notification = InABox.Wpf.Resources.notification.AsBitmapImage();
     private readonly BitmapImage _notification = InABox.Wpf.Resources.notification.AsBitmapImage();
+    private readonly BitmapImage _edit = InABox.Wpf.Resources.pencil.AsBitmapImage();
 
 
     private Button? EnableButton = null;
     private Button? EnableButton = null;
 
 
@@ -40,6 +41,8 @@ public class EventGrid : DynamicDataGrid<Event>
 
 
         if (Security.IsAllowed<CanManageEvents>())
         if (Security.IsAllowed<CanManageEvents>())
         {
         {
+            ActionColumns.Add(new DynamicImageColumn(_edit, Edit_Click));
+
             EnableButton = AddButton("Disable", null, Enable_Click);
             EnableButton = AddButton("Disable", null, Enable_Click);
             EnableButton.Visibility = Visibility.Collapsed;
             EnableButton.Visibility = Visibility.Collapsed;
         }
         }
@@ -227,6 +230,38 @@ public class EventGrid : DynamicDataGrid<Event>
         }
         }
     }
     }
 
 
+    private bool Edit_Click(CoreRow? row)
+    {
+        if (row is null) return false;
+
+        var ev = row.ToObject<Event>();
+
+        IEventData? data = null;
+        if(ev.Data is not null && ev.Data.Length != 0)
+        {
+            data = EventUtils.Deserialize(ev.Data);
+        }
+
+        var type = ev.EventType;
+        if(EventEditor.Run(ref type, ref data))
+        {
+            ev.EventType = type;
+            if(data is not null)
+            {
+                ev.Data = EventUtils.Serialize(data);
+            }
+            else
+            {
+                ev.Data = "";
+            }
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
     #endregion
     #endregion
 
 
     private readonly Column<Event> EventTypeColumn = new(x => x.EventType);
     private readonly Column<Event> EventTypeColumn = new(x => x.EventType);