|
@@ -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);
|
|
|
}
|
|
|
|