|
@@ -11,6 +11,8 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
namespace PRS.Shared;
|
|
@@ -20,6 +22,8 @@ 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();
|
|
|
|
|
|
public Guid EmployeeID { get; set; }
|
|
@@ -29,10 +33,83 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
base.Init();
|
|
|
|
|
|
HiddenColumns.Add(x => x.Data);
|
|
|
+ HiddenColumns.Add(x => x.Enabled);
|
|
|
|
|
|
ActionColumns.Add(new DynamicImageColumn(Subscribed_Image, Subscribed_Click) { ToolTip = Subscribed_ToolTip });
|
|
|
+
|
|
|
+ if (Security.IsAllowed<CanManageEvents>())
|
|
|
+ {
|
|
|
+ EnableButton = AddButton("Disable", null, Enable_Click);
|
|
|
+ EnableButton.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ OnSelectItem += EventGrid_OnSelectItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void EventGrid_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
|
|
|
+ {
|
|
|
+ if(EnableButton is not null)
|
|
|
+ {
|
|
|
+ if(e.Rows is not null && e.Rows.Length > 0)
|
|
|
+ {
|
|
|
+ EnableButton.Visibility = Visibility.Visible;
|
|
|
+ EnableButton.Content = e.Rows.Any(x => !x.Get<Event, bool>(x => x.Enabled))
|
|
|
+ ? "Enable" : "Disable";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ EnableButton.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool Enable_Click(Button button, CoreRow[] rows)
|
|
|
+ {
|
|
|
+ var items = LoadItems(rows);
|
|
|
+ if(items.Any(x => !x.Enabled))
|
|
|
+ {
|
|
|
+ foreach(var item in items)
|
|
|
+ {
|
|
|
+ item.Enabled = true;
|
|
|
+ }
|
|
|
+ Client.Save(items, "Event enabled.");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach(var item in items)
|
|
|
+ {
|
|
|
+ item.Enabled = false;
|
|
|
+ }
|
|
|
+ Client.Save(items, "Event disabled.");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ #region UIComponent
|
|
|
+
|
|
|
+ private class UIComponent : DynamicGridGridUIComponent<Event>
|
|
|
+ {
|
|
|
+ protected override Brush? GetCellBackground(CoreRow row, DynamicColumnBase column)
|
|
|
+ {
|
|
|
+ if(row.Get<Event, bool>(x => x.Enabled))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Colors.Gainsboro.ToBrush(0.5);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override IDynamicGridUIComponent CreateUIComponent()
|
|
|
+ {
|
|
|
+ return new UIComponent { Parent = this };
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
{
|
|
|
base.DoReconfigure(options);
|
|
@@ -191,6 +268,10 @@ public class EventGrid : DynamicDataGrid<Event>
|
|
|
|
|
|
protected override void Reload(Filters<Event> criteria, Columns<Event> columns, ref SortOrder<Event>? sort, CancellationToken token, Action<CoreTable?, Exception?> action)
|
|
|
{
|
|
|
+ if (!Security.IsAllowed<CanManageEvents>())
|
|
|
+ {
|
|
|
+ criteria.Add(new Filter<Event>(x => x.Enabled).IsEqualTo(true));
|
|
|
+ }
|
|
|
base.Reload(criteria, columns, ref sort, token, (data, error) =>
|
|
|
{
|
|
|
if(data is not null)
|