|
@@ -17,7 +17,8 @@ namespace PRS.Shared;
|
|
|
|
|
|
public class EventGrid : DynamicDataGrid<Event>
|
|
|
{
|
|
|
- private readonly BitmapImage _tick = InABox.Wpf.Resources.Bullet_Tick.AsBitmapImage();
|
|
|
+ private readonly BitmapImage _tick = InABox.Wpf.Resources.tick.AsBitmapImage();
|
|
|
+ private readonly BitmapImage _disabled = InABox.Wpf.Resources.disabled.AsBitmapImage();
|
|
|
|
|
|
private HashSet<Guid> _subscribedSet = new();
|
|
|
|
|
@@ -29,8 +30,25 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
|
|
|
HiddenColumns.Add(x => x.Data);
|
|
|
|
|
|
- ActionColumns.Add(new DynamicImageColumn(Subscribed_Image) { ToolTip = Subscribed_ToolTip });
|
|
|
- ActionColumns.Add(new DynamicMenuColumn(BuildMenu));
|
|
|
+ ActionColumns.Add(new DynamicImageColumn(Subscribed_Image, Subscribed_Click) { ToolTip = Subscribed_ToolTip });
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
+ {
|
|
|
+ base.DoReconfigure(options);
|
|
|
+
|
|
|
+ if (Security.IsAllowed<CanManageEvents>())
|
|
|
+ {
|
|
|
+ options.AddRows = true;
|
|
|
+ options.EditRows = true;
|
|
|
+ options.DeleteRows = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ options.AddRows = false;
|
|
|
+ options.EditRows = false;
|
|
|
+ options.DeleteRows = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#region Action Columns
|
|
@@ -57,28 +75,27 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return _subscribedSet.Contains(row.Get<Event, Guid>(x => x.ID)) ? _tick : null;
|
|
|
+ return _subscribedSet.Contains(row.Get<Event, Guid>(x => x.ID)) ? _tick : _disabled;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
|
|
|
+ private bool Subscribed_Click(CoreRow? row)
|
|
|
{
|
|
|
- if (row is null) return;
|
|
|
+ if (row is null) return false;
|
|
|
|
|
|
var eventID = row.Get<Event, Guid>(x => x.ID);
|
|
|
-
|
|
|
- var menu = column.GetMenu();
|
|
|
if(_subscribedSet.Contains(eventID))
|
|
|
{
|
|
|
- menu.AddItem("Unsubscribe from event", null, row, Unsubscribe_Click);
|
|
|
+ Unsubscribe(row);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- menu.AddItem("Subscribe to event", null, row, Subscribe_Click);
|
|
|
+ Subscribe(row);
|
|
|
}
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- private void Unsubscribe_Click(CoreRow row)
|
|
|
+ private void Unsubscribe(CoreRow row)
|
|
|
{
|
|
|
var eventID = row.Get<Event, Guid>(x => x.ID);
|
|
|
|
|
@@ -93,11 +110,9 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
}
|
|
|
|
|
|
_subscribedSet.Remove(eventID);
|
|
|
-
|
|
|
- InvalidateRow(row);
|
|
|
}
|
|
|
|
|
|
- private void Subscribe_Click(CoreRow row)
|
|
|
+ private void Subscribe(CoreRow row)
|
|
|
{
|
|
|
var ev = row.ToObject<Event>();
|
|
|
var subscriber = new EventSubscriber();
|
|
@@ -105,13 +120,32 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
subscriber.Employee.ID = EmployeeID;
|
|
|
Client.Save(subscriber, "");
|
|
|
_subscribedSet.Add(ev.ID);
|
|
|
-
|
|
|
- InvalidateRow(row);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
private readonly Column<Event> EventTypeColumn = new(x => x.EventType);
|
|
|
+ private readonly Column<Event> NotificationExpressionColumn = new(x => x.NotificationExpression);
|
|
|
+
|
|
|
+ private IEventData? EventData;
|
|
|
+
|
|
|
+ protected override void BeforeLoad(IDynamicEditorForm form, Event[] items)
|
|
|
+ {
|
|
|
+ base.BeforeLoad(form, items);
|
|
|
+
|
|
|
+ form.ReadOnly = Security.IsAllowed<CanManageEvents>();
|
|
|
+
|
|
|
+ var ev = items.First();
|
|
|
+
|
|
|
+ IEventData? data = null;
|
|
|
+ if(ev.Data is not null && ev.Data.Length != 0)
|
|
|
+ {
|
|
|
+ using var stream = new MemoryStream(ev.Data);
|
|
|
+ var reader = new CoreBinaryReader(stream, BinarySerializationSettings.Latest);
|
|
|
+ data = EventUtils.Deserialize(reader);
|
|
|
+ }
|
|
|
+ EventData = data;
|
|
|
+ }
|
|
|
|
|
|
protected override void CustomiseEditor(Event[] items, DynamicGridColumn column, BaseEditor editor)
|
|
|
{
|
|
@@ -124,6 +158,15 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
var editButton = new EditorButton(ev, "Edit Event", 100, EditEvent_Click, false);
|
|
|
enumEditor.Buttons = [editButton];
|
|
|
}
|
|
|
+ else if(NotificationExpressionColumn.IsEqualTo(column.ColumnName) && editor is ExpressionEditor exprEditor)
|
|
|
+ {
|
|
|
+ exprEditor.OnGetVariables += ExprEditor_OnGetVariables;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private IEnumerable<string> ExprEditor_OnGetVariables()
|
|
|
+ {
|
|
|
+ return EventData?.Event.DataModelDefinition().GetVariables().Select(x => x.Name) ?? [];
|
|
|
}
|
|
|
|
|
|
private void EditEvent_Click(object editor, object? item)
|
|
@@ -132,15 +175,10 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
|
|
|
var type = ev.EventType;
|
|
|
|
|
|
- IEventData? data = null;
|
|
|
- if(ev.Data is not null && ev.Data.Length != 0)
|
|
|
- {
|
|
|
- using var stream = new MemoryStream(ev.Data);
|
|
|
- var reader = new CoreBinaryReader(stream, BinarySerializationSettings.Latest);
|
|
|
- data = EventUtils.Deserialize(reader);
|
|
|
- }
|
|
|
+ var data = EventData;
|
|
|
if(EventEditor.Run(ref type, ref data))
|
|
|
{
|
|
|
+ EventData = data;
|
|
|
ev.EventType = type;
|
|
|
if(data is not null)
|
|
|
{
|