DynamicIssuesColumn.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Media.Imaging;
  8. using InABox.Clients;
  9. using InABox.Core;
  10. using InABox.WPF;
  11. namespace InABox.DynamicGrid;
  12. // public interface IDynamicIssuesColumn
  13. // {
  14. // Func<IIssues[], FrameworkElement?>? CustomiseEditor { get; set; }
  15. // Action<IIssues[], FrameworkElement?>? IssuesUpdated { get; set; }
  16. // }
  17. //
  18. // public class DynamicIssuesColumn<TIssues> : DynamicImageColumn, IDynamicIssuesColumn
  19. // where TIssues : Entity, IRemotable, IPersistent, IIssues, new()
  20. // {
  21. // private static readonly BitmapImage _warning = Wpf.Resources.warning.AsBitmapImage();
  22. // private static readonly BitmapImage _graywarning = Wpf.Resources.warning.AsGrayScale().AsBitmapImage();
  23. //
  24. // private readonly IDynamicGrid _parent;
  25. //
  26. // public string IssuesProperty;
  27. // public string IssuesResolvedProperty;
  28. // public Func<CoreRow[], TIssues[]> LoadIssues;
  29. //
  30. // public Func<IIssues[], FrameworkElement?>? CustomiseEditor { get; set; }
  31. //
  32. // public Action<IIssues[], FrameworkElement?>? IssuesUpdated { get; set; }
  33. //
  34. // public DynamicIssuesColumn(IDynamicGrid parent, string issuesProperty, string issuesResolvedProperty, Func<CoreRow[], TIssues[]> loadIssues)
  35. // {
  36. // Image = IssuesImage;
  37. // Filters = new[] { "Active Issues", "No Issues" };
  38. // FilterRecord = DoFilterIssues;
  39. // ContextMenu = CreateIssuesMenu;
  40. // ToolTip = CreateIssuesToolTip;
  41. // _parent = parent;
  42. // Position = DynamicActionColumnPosition.Start;
  43. //
  44. // IssuesProperty = issuesProperty;
  45. // IssuesResolvedProperty = issuesResolvedProperty;
  46. // LoadIssues = loadIssues;
  47. // }
  48. //
  49. // public DynamicIssuesColumn(IDynamicGrid parent):
  50. // this(parent, CoreUtils.GetFullPropertyName<TIssues, string>(x => x.Issues, ""), CoreUtils.GetFullPropertyName<TIssues, DateTime>(x => x.IssuesResolved, ""), (rows) => rows.ToObjects<TIssues>().ToArray())
  51. // {
  52. // }
  53. //
  54. // private string? GetIssues(CoreRow? row)
  55. // {
  56. // return row?.Get<string>(IssuesProperty);
  57. // }
  58. //
  59. // private DateTime GetIssuesResolved(CoreRow? row)
  60. // {
  61. // return row?.Get<DateTime>(IssuesResolvedProperty) ?? DateTime.MinValue;
  62. // }
  63. //
  64. // private BitmapImage? IssuesImage(CoreRow? row)
  65. // {
  66. // if (GetIssues(row).IsNullOrWhiteSpace())
  67. // return null;
  68. // return GetIssuesResolved(row).IsEmpty()
  69. // ? _warning
  70. // : _graywarning;
  71. // }
  72. //
  73. // private FrameworkElement? CreateIssuesToolTip(DynamicActionColumn column, CoreRow? row)
  74. // {
  75. // var text = GetIssues(row);
  76. // if (text.IsNullOrWhiteSpace())
  77. // text = "No Issues Found";
  78. // return TextToolTip(text);
  79. // }
  80. //
  81. // private bool DoFilterIssues(CoreRow row, string[] filter)
  82. // {
  83. // var noissues = GetIssues(row).IsNullOrWhiteSpace();
  84. // if (filter.Contains("No Issues") && noissues)
  85. // return true;
  86. // if (filter.Contains("Active Issues") && !noissues)
  87. // return true;
  88. // return false;
  89. // }
  90. //
  91. // private MenuItem CreateMenu(string caption, RoutedEventHandler click)
  92. // {
  93. // var item = new MenuItem();
  94. // item.Header = caption;
  95. // item.Click += click;
  96. // return item;
  97. // }
  98. //
  99. // private ContextMenu? CreateIssuesMenu(CoreRow[]? rows)
  100. // {
  101. // if (!Security.CanManageIssues<TIssues>())
  102. // return null;
  103. //
  104. // var issues = rows?.Select(GetIssues).Where(x => !string.IsNullOrWhiteSpace(x)).Any();
  105. // var result = new ContextMenu();
  106. //
  107. // if (issues != true)
  108. // {
  109. // result.Items.Add(CreateMenu("Create Issue", (o, e) => EditIssues(rows)));
  110. // }
  111. // else
  112. // {
  113. // result.Items.Add(CreateMenu("Update Issues", (o, e) => EditIssues(rows)));
  114. // result.Items.Add(CreateMenu("Clear Issues", (o, e) => ClearIssues(rows)));
  115. // }
  116. //
  117. // return result;
  118. // }
  119. //
  120. // private void ClearIssues(CoreRow[]? rows)
  121. // {
  122. // if (rows is null)
  123. // {
  124. // return;
  125. // }
  126. // if (MessageBox.Show("This will clear the flagged issues for these items!\n\nAre you sure you wish to continue?", "Confirm",
  127. // MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  128. // {
  129. // var _updates = LoadIssues(rows).ToArray();
  130. // foreach (var update in _updates)
  131. // {
  132. // update.Issues = "";
  133. // }
  134. // using (new WaitCursor())
  135. // {
  136. // Client.Save(_updates, "Clearing Issues", (o, e) => { });
  137. // }
  138. //
  139. // // False here to prevent Refreshing and losing the selected row record
  140. // foreach (var row in rows)
  141. // _parent.UpdateRow(row, IssuesProperty, "");
  142. // }
  143. // }
  144. //
  145. // private void EditIssues(CoreRow[]? rows)
  146. // {
  147. // var _objects = LoadIssues(rows ?? Array.Empty<CoreRow>());
  148. //
  149. // var _map = new Dictionary<CoreRow, TIssues>();
  150. // if (rows is not null)
  151. // {
  152. // var i = 0;
  153. // foreach (var row in rows)
  154. // {
  155. // _map[row] = _objects[i];
  156. // ++i;
  157. // }
  158. // }
  159. //
  160. // var _values = _map.Values.OfType<IIssues>().ToArray();
  161. // var _editor = new DynamicIssuesEditor(_values);
  162. // var _custom = CustomiseEditor?.Invoke(_values);
  163. // if (_custom != null)
  164. // _editor.SetCustom(_custom);
  165. // if (_editor.ShowDialog() == true)
  166. // {
  167. // using (new WaitCursor())
  168. // {
  169. // if (_custom != null)
  170. // IssuesUpdated?.Invoke(_values, _custom);
  171. // Client.Save(_map.Values, "Updating Issues", (o, e) => { });
  172. // }
  173. //
  174. // foreach (var _row in _map.Keys)
  175. // _parent.UpdateRow(_row, IssuesProperty, _map[_row].Issues);
  176. // }
  177. // }
  178. // }