|
@@ -19,12 +19,9 @@ namespace PRS.Shared;
|
|
|
|
|
|
public class EventGrid : DynamicDataGrid<Event>
|
|
|
{
|
|
|
- private readonly BitmapImage _tick = InABox.Wpf.Resources.tick.AsBitmapImage();
|
|
|
- private readonly BitmapImage _disabled = InABox.Wpf.Resources.disabled.AsBitmapImage();
|
|
|
-
|
|
|
private Button? EnableButton = null;
|
|
|
|
|
|
- private HashSet<Guid> _subscribedSet = new();
|
|
|
+ private Dictionary<Guid, EventSubscriberType> _subscribedSet = new();
|
|
|
|
|
|
public Guid EmployeeID { get; set; }
|
|
|
|
|
@@ -36,7 +33,7 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
HiddenColumns.Add(x => x.Enabled);
|
|
|
HiddenColumns.Add(x => x.Visible);
|
|
|
|
|
|
- ActionColumns.Add(new DynamicImageColumn(Subscribed_Image, Subscribed_Click) { ToolTip = Subscribed_ToolTip });
|
|
|
+ ActionColumns.Add(new DynamicMenuColumn(BuildMenu) { ToolTip = Subscribed_ToolTip });
|
|
|
|
|
|
if (Security.IsAllowed<CanManageEvents>())
|
|
|
{
|
|
@@ -138,38 +135,54 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return _subscribedSet.Contains(row.Get<Event, Guid>(x => x.ID))
|
|
|
+ return _subscribedSet.ContainsKey(row.Get<Event, Guid>(x => x.ID))
|
|
|
? column.TextToolTip("You are subscribed to this event.")
|
|
|
: null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private BitmapImage? Subscribed_Image(CoreRow? row)
|
|
|
+ private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
|
|
|
{
|
|
|
- if(row is null)
|
|
|
+ if (row is null) return;
|
|
|
+
|
|
|
+ var menu = column.GetMenu();
|
|
|
+
|
|
|
+ var eventID = row.Get<Event, Guid>(x => x.ID);
|
|
|
+
|
|
|
+ if (_subscribedSet.TryGetValue(eventID, out var type))
|
|
|
{
|
|
|
- return _tick;
|
|
|
+ menu.AddItem("Unsubscribe", null, row, Unsubscribe);
|
|
|
+ if(type == EventSubscriberType.Notification)
|
|
|
+ {
|
|
|
+ menu.AddItem("Subscribe by Email", null, (row, EventSubscriberType.Email), ChangeSubscription);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ menu.AddItem("Subscribe by Notification", null, (row, EventSubscriberType.Notification), ChangeSubscription);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return _subscribedSet.Contains(row.Get<Event, Guid>(x => x.ID)) ? _tick : _disabled;
|
|
|
+ menu.AddItem("Subscribe by Notification", null, (row, EventSubscriberType.Notification), Subscribe);
|
|
|
+ menu.AddItem("Subscribe by Email", null, (row, EventSubscriberType.Email), Subscribe);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private bool Subscribed_Click(CoreRow? row)
|
|
|
+ private void ChangeSubscription((CoreRow row, EventSubscriberType Notification) tuple)
|
|
|
{
|
|
|
- if (row is null) return false;
|
|
|
+ Unsubscribe(tuple.row);
|
|
|
+ Subscribe(tuple);
|
|
|
+ }
|
|
|
|
|
|
- var eventID = row.Get<Event, Guid>(x => x.ID);
|
|
|
- if(_subscribedSet.Contains(eventID))
|
|
|
- {
|
|
|
- Unsubscribe(row);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Subscribe(row);
|
|
|
- }
|
|
|
- return true;
|
|
|
+ private void Subscribe((CoreRow row, EventSubscriberType type) tuple)
|
|
|
+ {
|
|
|
+ var ev = tuple.row.ToObject<Event>();
|
|
|
+ var subscriber = new EventSubscriber();
|
|
|
+ subscriber.Event.CopyFrom(ev);
|
|
|
+ subscriber.Employee.ID = EmployeeID;
|
|
|
+ subscriber.SubscriberType = tuple.type;
|
|
|
+ Client.Save(subscriber, "");
|
|
|
+ _subscribedSet.Add(ev.ID, subscriber.SubscriberType);
|
|
|
}
|
|
|
|
|
|
private void Unsubscribe(CoreRow row)
|
|
@@ -189,14 +202,8 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
_subscribedSet.Remove(eventID);
|
|
|
}
|
|
|
|
|
|
- private void Subscribe(CoreRow row)
|
|
|
+ private void Subscribe_(CoreRow row)
|
|
|
{
|
|
|
- var ev = row.ToObject<Event>();
|
|
|
- var subscriber = new EventSubscriber();
|
|
|
- subscriber.Event.CopyFrom(ev);
|
|
|
- subscriber.Employee.ID = EmployeeID;
|
|
|
- Client.Save(subscriber, "");
|
|
|
- _subscribedSet.Add(ev.ID);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -289,8 +296,8 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
_subscribedSet = Client.Query(
|
|
|
new Filter<EventSubscriber>(x => x.Employee.ID).IsEqualTo(EmployeeID)
|
|
|
.And(x => x.Event.ID).InList(ids),
|
|
|
- Columns.None<EventSubscriber>().Add(x => x.Event.ID))
|
|
|
- .ToObjects<EventSubscriber>().Select(x => x.Event.ID).ToHashSet();
|
|
|
+ Columns.None<EventSubscriber>().Add(x => x.Event.ID).Add(x => x.SubscriberType))
|
|
|
+ .ToObjects<EventSubscriber>().ToDictionary(x => x.Event.ID, x => x.SubscriberType);
|
|
|
}
|
|
|
action(data, error);
|
|
|
});
|