Ver código fonte

Fixed errors with notifications and prevented sending if either Sender or Employee is empty.

Kenric Nugteren 2 anos atrás
pai
commit
79ecc446ec

+ 1 - 0
prs.classes/Entities/Job/JobBillOfMaterialsItem.cs

@@ -101,4 +101,5 @@ namespace Comal.Classes
         }
         
     }
+
 }

+ 8 - 0
prs.classes/Entities/Notification/NotificationLink.cs

@@ -18,5 +18,13 @@ namespace Comal.Classes
 
         [EditorSequence(4)]
         public EmployeeLink Employee { get; set; }
+
+        protected override void Init()
+        {
+            base.Init();
+
+            Sender = new EmployeeLink();
+            Employee = new EmployeeLink();
+        }
     }
 }

+ 4 - 0
prs.desktop/MainWindow.xaml.cs

@@ -2586,6 +2586,10 @@ namespace PRSDesktop
             {
                 Notifications.AddNotification(notification);
             }
+            if(CurrentPanel is NotificationPanel panel)
+            {
+                panel.AddNotification(notification);
+            }
         }
 
         private void Notifications_Tick(object? sender, EventArgs e)

+ 48 - 6
prs.desktop/Panels/Notifications/NotificationPanel.xaml.cs

@@ -11,7 +11,9 @@ using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.WPF;
+using sun.net.www;
 using Syncfusion.Windows.Controls.RichTextBoxAdv;
+using static ICSharpCode.AvalonEdit.Document.TextDocumentWeakEventManager;
 using SelectionChangedEventArgs = System.Windows.Controls.SelectionChangedEventArgs;
 
 namespace PRSDesktop;
@@ -76,6 +78,8 @@ public partial class NotificationPanel : UserControl, IPanel<Notification>
         Notifications.Margin = new Thickness(0);
         Notifications.OnReload += Notifications_OnReload;
         Notifications.OnSelectItem += Notifications_OnSelectItem;
+        Notifications.OnValidate += Notifications_OnValidate;
+        Notifications.OnCreateItem += Notifications_OnCreateItem;
 
         //WriteNew = CreateButton("Write New", null, WriteNewClick);
         //WriteNew.Visibility = Visibility.Visible;
@@ -105,6 +109,29 @@ public partial class NotificationPanel : UserControl, IPanel<Notification>
         Folders.ItemsSource = folders;
     }
 
+    private void Notifications_OnCreateItem(object sender, object item)
+    {
+        if (item is not Notification notification)
+            return;
+
+        notification.Sender.ID = me.ID;
+    }
+
+    private void Notifications_OnValidate(object sender, Notification[] items, List<string> errors)
+    {
+        foreach(var item in items)
+        {
+            if(!item.Sender.IsValid())
+            {
+                errors.Add("[Sender] may not be blank!");
+            }
+            if(!item.Employee.IsValid())
+            {
+                errors.Add("[Employee] may not be blank!");
+            }
+        }
+    }
+
     public bool IsReady { get; set; }
 
     public event DataModelUpdateEvent OnUpdateDataModel;
@@ -156,8 +183,8 @@ public partial class NotificationPanel : UserControl, IPanel<Notification>
                 null,
                 (table, error) =>
                 {
-                    var drow = table != null ? table.Rows.FirstOrDefault() : null;
-                    var desc = drow != null ? drow.Get<Notification, string>(x => x.Description).Replace("background:NoColor;", "") : "";
+                    var drow = table?.Rows.FirstOrDefault();
+                    var desc = drow?.Get<Notification, string>(x => x.Description)?.Replace("background:NoColor;", "") ?? "";
                     var ms = new MemoryStream(Encoding.ASCII.GetBytes(desc));
                     Dispatcher.Invoke(() =>
                     {
@@ -192,17 +219,32 @@ public partial class NotificationPanel : UserControl, IPanel<Notification>
         }
     }
 
+    public void AddNotification(Notification notification)
+    {
+        Dispatcher.Invoke(() =>
+        {
+            if (IsInbox)
+            {
+                Notifications.AddRow(notification);
+            }
+        });
+    }
+
+    private bool IsInbox => Folders.SelectedIndex == 0;
+    private bool IsOutbox => Folders.SelectedIndex == 1;
+    private bool IsArchive => Folders.SelectedIndex == 2;
+
     private void Notifications_OnReload(object sender, Filters<Notification> criteria, Columns<Notification> columns,
-        ref SortOrder<Notification> sortby)
+        ref SortOrder<Notification>? sortby)
     {
         var filter = new Filter<Notification>(x => x.ID).IsEqualTo(Guid.Empty);
         if (me != null)
         {
-            if (Folders.SelectedIndex == 0)
+            if (IsInbox)
                 filter = new Filter<Notification>(x => x.Employee.ID).IsEqualTo(me.ID).And(x => x.Closed).IsEqualTo(DateTime.MinValue);
-            else if (Folders.SelectedIndex == 1)
+            else if (IsOutbox)
                 filter = new Filter<Notification>(x => x.Sender.ID).IsEqualTo(me.ID);
-            else if (Folders.SelectedIndex == 2)
+            else if (IsArchive)
                 filter = new Filter<Notification>(x => x.Employee.ID).IsEqualTo(me.ID).And(x => x.Closed).IsNotEqualTo(DateTime.MinValue);
         }
 

+ 1 - 1
prs.desktop/Panels/Notifications/NotificationsDock.xaml.cs

@@ -152,7 +152,7 @@ namespace PRSDesktop
                 (table, error) =>
                 {
                     var drow = table != null ? table.Rows.FirstOrDefault() : null;
-                    var desc = drow != null ? drow.Get<Notification, string>(x => x.Description)?.Replace("background:NoColor;", "") : "";
+                    var desc = drow?.Get<Notification, string>(x => x.Description)?.Replace("background:NoColor;", "") ?? "";
                     var ms = new MemoryStream(Encoding.ASCII.GetBytes(desc));
                     Dispatcher.Invoke(() =>
                     {