|
@@ -19,6 +19,9 @@ namespace PRS.Shared;
|
|
|
|
|
|
public class EventGrid : DynamicDataGrid<Event>
|
|
|
{
|
|
|
+ private readonly BitmapImage _email = InABox.Wpf.Resources.email.AsBitmapImage();
|
|
|
+ private readonly BitmapImage _notification = InABox.Wpf.Resources.notification.AsBitmapImage();
|
|
|
+
|
|
|
private Button? EnableButton = null;
|
|
|
|
|
|
private Dictionary<Guid, EventSubscriberType> _subscribedSet = new();
|
|
@@ -33,7 +36,7 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
HiddenColumns.Add(x => x.Enabled);
|
|
|
HiddenColumns.Add(x => x.Visible);
|
|
|
|
|
|
- ActionColumns.Add(new DynamicMenuColumn(BuildMenu) { ToolTip = Subscribed_ToolTip });
|
|
|
+ ActionColumns.Add(new DynamicMenuColumn(BuildMenu, getImage: Menu_GetImage) { ToolTip = Subscribed_ToolTip });
|
|
|
|
|
|
if (Security.IsAllowed<CanManageEvents>())
|
|
|
{
|
|
@@ -135,8 +138,10 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return _subscribedSet.ContainsKey(row.Get<Event, Guid>(x => x.ID))
|
|
|
- ? column.TextToolTip("You are subscribed to this event.")
|
|
|
+ return _subscribedSet.TryGetValue(row.Get<Event, Guid>(x => x.ID), out var type)
|
|
|
+ ? (type == EventSubscriberType.Notification
|
|
|
+ ? column.TextToolTip("You are subscribed to this event by notification.")
|
|
|
+ : column.TextToolTip("You are subscribed to this event by email."))
|
|
|
: null;
|
|
|
}
|
|
|
}
|
|
@@ -168,9 +173,18 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private BitmapImage? Menu_GetImage(CoreRow? row)
|
|
|
+ {
|
|
|
+ if (row is null) return _notification;
|
|
|
+
|
|
|
+ return _subscribedSet.TryGetValue(row.Get<Event, Guid>(x => x.ID), out var type)
|
|
|
+ ? (type == EventSubscriberType.Notification ? _notification : _email)
|
|
|
+ : null;
|
|
|
+ }
|
|
|
+
|
|
|
private void ChangeSubscription((CoreRow row, EventSubscriberType Notification) tuple)
|
|
|
{
|
|
|
- Unsubscribe(tuple.row);
|
|
|
+ Unsubscribe(tuple.row, false);
|
|
|
Subscribe(tuple);
|
|
|
}
|
|
|
|
|
@@ -183,9 +197,15 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
subscriber.SubscriberType = tuple.type;
|
|
|
Client.Save(subscriber, "");
|
|
|
_subscribedSet.Add(ev.ID, subscriber.SubscriberType);
|
|
|
+
|
|
|
+ Refresh(false, true);
|
|
|
}
|
|
|
|
|
|
private void Unsubscribe(CoreRow row)
|
|
|
+ {
|
|
|
+ Unsubscribe(row, true);
|
|
|
+ }
|
|
|
+ private void Unsubscribe(CoreRow row, bool refresh)
|
|
|
{
|
|
|
var eventID = row.Get<Event, Guid>(x => x.ID);
|
|
|
|
|
@@ -200,10 +220,11 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
}
|
|
|
|
|
|
_subscribedSet.Remove(eventID);
|
|
|
- }
|
|
|
|
|
|
- private void Subscribe_(CoreRow row)
|
|
|
- {
|
|
|
+ if (refresh)
|
|
|
+ {
|
|
|
+ Refresh(false, true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endregion
|