|
@@ -0,0 +1,178 @@
|
|
|
+using Comal.Classes;
|
|
|
+using InABox.Clients;
|
|
|
+using InABox.Configuration;
|
|
|
+using InABox.Core;
|
|
|
+using InABox.DynamicGrid;
|
|
|
+using InABox.WPF;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Security.Cryptography;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Windows.Controls;
|
|
|
+
|
|
|
+namespace PRSDesktop;
|
|
|
+
|
|
|
+public abstract class BaseKanbanGrid : DynamicDataGrid<Kanban>
|
|
|
+{
|
|
|
+ protected abstract TaskPanelProperties Properties { get; }
|
|
|
+
|
|
|
+ public BaseKanbanGrid()
|
|
|
+ {
|
|
|
+ ActionColumns.Add(new DynamicImageColumn(PRSDesktop.Resources.menu.AsBitmapImage(), FormMenuClick));
|
|
|
+
|
|
|
+ HiddenColumns.Add(x => x.EmployeeLink.ID);
|
|
|
+
|
|
|
+ OnCustomiseEditor += CustomiseEditor;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void DoValidate(Kanban[] items, List<string> errors)
|
|
|
+ {
|
|
|
+ base.DoValidate(items, errors);
|
|
|
+
|
|
|
+ if (Properties.RequireTaskTypes && items.Any(x => x.Type.ID == Guid.Empty))
|
|
|
+ {
|
|
|
+ errors.Add("[Task Type] may not be blank!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
+ {
|
|
|
+ base.DoReconfigure(options);
|
|
|
+
|
|
|
+ options.SelectColumns = true;
|
|
|
+ options.FilterRows = true;
|
|
|
+ options.RecordCount = true;
|
|
|
+ options.PageSize = 1000;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool FormMenuClick(CoreRow? row)
|
|
|
+ {
|
|
|
+ if (row is null)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ var kanbanID = row.Get<Kanban, Guid>(x => x.ID);
|
|
|
+
|
|
|
+ var menu = new ContextMenu();
|
|
|
+
|
|
|
+ var digitalForms = menu.AddItem("Digital Forms", null, null);
|
|
|
+
|
|
|
+ DynamicGridUtils.PopulateFormMenu<KanbanForm, Kanban, KanbanLink>(digitalForms, kanbanID, () => row.ToObject<Kanban>());
|
|
|
+
|
|
|
+ menu.AddItem("Manage Subscribers", null, row, Subscribers_Click);
|
|
|
+
|
|
|
+ menu.IsOpen = true;
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Subscribers_Click(CoreRow row)
|
|
|
+ {
|
|
|
+ var kanban = row.ToObject<Kanban>();
|
|
|
+ TaskPanel.ManageSubscribers(kanban);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CustomiseEditor(IDynamicEditorForm sender, Kanban[]? items, DynamicGridColumn column, BaseEditor editor)
|
|
|
+ {
|
|
|
+ var kanban = items?.FirstOrDefault();
|
|
|
+ if (kanban is null) return;
|
|
|
+
|
|
|
+ var bFullControl = IsFullControl(new[] { kanban });
|
|
|
+ bool? enabled = null;
|
|
|
+ switch (column.ColumnName)
|
|
|
+ {
|
|
|
+ case "Private":
|
|
|
+ enabled = kanban.EmployeeLink.ID == App.EmployeeID && kanban.ManagerLink.ID == App.EmployeeID;
|
|
|
+ break;
|
|
|
+ case "Description":
|
|
|
+ enabled = kanban.ID == Guid.Empty || (bFullControl && !kanban.Private);
|
|
|
+ break;
|
|
|
+ case "EmployeeLink.ID":
|
|
|
+ enabled = bFullControl && !kanban.Private;
|
|
|
+ break;
|
|
|
+ case "ManagerLink.ID":
|
|
|
+ enabled = bFullControl && !kanban.Private;
|
|
|
+ break;
|
|
|
+ case "Category":
|
|
|
+ enabled = bFullControl && !kanban.Private;
|
|
|
+ break;
|
|
|
+ case "Closed":
|
|
|
+ enabled = bFullControl || Security.IsAllowed<CanCloseOthersTasks>();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(enabled != null)
|
|
|
+ {
|
|
|
+ editor.Editable = enabled.Value ? Editable.Enabled : Editable.Disabled;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool IsFullControl(Kanban[] kanbans)
|
|
|
+ {
|
|
|
+ foreach (var kanban in kanbans)
|
|
|
+ {
|
|
|
+ if (!App.EmployeeID.Equals(kanban.ManagerLink.ID) && !App.EmployeeID.Equals(kanban.EmployeeLink.ID))
|
|
|
+ {
|
|
|
+ // If you can change others tasks, IsFullControl is true - but we don't check at the beginning of the function
|
|
|
+ // to save checking security tokens every time.
|
|
|
+ return Security.IsAllowed<CanChangeOthersTasks>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, Kanban[] items, string name, object value)
|
|
|
+ {
|
|
|
+ var result = base.EditorValueChanged(editor, items, name, value);
|
|
|
+
|
|
|
+ if (name == "Type.ID")
|
|
|
+ {
|
|
|
+ //ReloadForms<Kanban, KanbanForm, KanbanTypeForm>(editor, items.FirstOrDefault(), x => x.Type.ID,
|
|
|
+ // value != null ? (Guid)value : Guid.Empty);
|
|
|
+ }
|
|
|
+ else if (name == "EmployeeLink.ID")
|
|
|
+ {
|
|
|
+ var enabled = items.FirstOrDefault()?.ManagerLink.UserLink.ID == ClientFactory.UserGuid &&
|
|
|
+ (Guid)(value ?? Guid.Empty) == items.FirstOrDefault()?.ManagerLink.ID;
|
|
|
+ editor.FindEditor("Private").IsEnabled = enabled;
|
|
|
+ }
|
|
|
+ else if (name == "ManagerLink.ID")
|
|
|
+ {
|
|
|
+ var enabled = items.FirstOrDefault()?.EmployeeLink.UserLink.ID == ClientFactory.UserGuid &&
|
|
|
+ (Guid)(value ?? Guid.Empty) == items.FirstOrDefault()?.EmployeeLink.ID;
|
|
|
+ editor.FindEditor("Private").IsEnabled = enabled;
|
|
|
+ }
|
|
|
+ else if (name == "Private")
|
|
|
+ {
|
|
|
+ var enabled = !Equals(value, true);
|
|
|
+ var employeeEditor = editor.FindEditor("EmployeeLink.ID");
|
|
|
+ var managerEditor = editor.FindEditor("ManagerLink.ID");
|
|
|
+ employeeEditor.IsEnabled = enabled;
|
|
|
+ managerEditor.IsEnabled = enabled;
|
|
|
+ if (!enabled)
|
|
|
+ {
|
|
|
+ employeeEditor.SetValue(employeeEditor.ColumnName, App.EmployeeID);
|
|
|
+ managerEditor.SetValue(managerEditor.ColumnName, App.EmployeeID);
|
|
|
+
|
|
|
+ foreach(var item in items)
|
|
|
+ {
|
|
|
+ item.EmployeeLink.ID = App.EmployeeID;
|
|
|
+ item.ManagerLink.ID = App.EmployeeID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+public class KanbanGrid : BaseKanbanGrid, IDefaultGrid
|
|
|
+{
|
|
|
+ private TaskPanelProperties _properties;
|
|
|
+ protected override TaskPanelProperties Properties => _properties;
|
|
|
+
|
|
|
+ public KanbanGrid()
|
|
|
+ {
|
|
|
+ _properties = new GlobalConfiguration<TaskPanelProperties>().Load();
|
|
|
+ }
|
|
|
+}
|