using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; using InABox.Clients; using InABox.Core; using InABox.WPF; namespace InABox.DynamicGrid; // public interface IDynamicIssuesColumn // { // Func? CustomiseEditor { get; set; } // Action? IssuesUpdated { get; set; } // } // // public class DynamicIssuesColumn : DynamicImageColumn, IDynamicIssuesColumn // where TIssues : Entity, IRemotable, IPersistent, IIssues, new() // { // private static readonly BitmapImage _warning = Wpf.Resources.warning.AsBitmapImage(); // private static readonly BitmapImage _graywarning = Wpf.Resources.warning.AsGrayScale().AsBitmapImage(); // // private readonly IDynamicGrid _parent; // // public string IssuesProperty; // public string IssuesResolvedProperty; // public Func LoadIssues; // // public Func? CustomiseEditor { get; set; } // // public Action? IssuesUpdated { get; set; } // // public DynamicIssuesColumn(IDynamicGrid parent, string issuesProperty, string issuesResolvedProperty, Func loadIssues) // { // Image = IssuesImage; // Filters = new[] { "Active Issues", "No Issues" }; // FilterRecord = DoFilterIssues; // ContextMenu = CreateIssuesMenu; // ToolTip = CreateIssuesToolTip; // _parent = parent; // Position = DynamicActionColumnPosition.Start; // // IssuesProperty = issuesProperty; // IssuesResolvedProperty = issuesResolvedProperty; // LoadIssues = loadIssues; // } // // public DynamicIssuesColumn(IDynamicGrid parent): // this(parent, CoreUtils.GetFullPropertyName(x => x.Issues, ""), CoreUtils.GetFullPropertyName(x => x.IssuesResolved, ""), (rows) => rows.ToObjects().ToArray()) // { // } // // private string? GetIssues(CoreRow? row) // { // return row?.Get(IssuesProperty); // } // // private DateTime GetIssuesResolved(CoreRow? row) // { // return row?.Get(IssuesResolvedProperty) ?? DateTime.MinValue; // } // // private BitmapImage? IssuesImage(CoreRow? row) // { // if (GetIssues(row).IsNullOrWhiteSpace()) // return null; // return GetIssuesResolved(row).IsEmpty() // ? _warning // : _graywarning; // } // // private FrameworkElement? CreateIssuesToolTip(DynamicActionColumn column, CoreRow? row) // { // var text = GetIssues(row); // if (text.IsNullOrWhiteSpace()) // text = "No Issues Found"; // return TextToolTip(text); // } // // private bool DoFilterIssues(CoreRow row, string[] filter) // { // var noissues = GetIssues(row).IsNullOrWhiteSpace(); // if (filter.Contains("No Issues") && noissues) // return true; // if (filter.Contains("Active Issues") && !noissues) // return true; // return false; // } // // private MenuItem CreateMenu(string caption, RoutedEventHandler click) // { // var item = new MenuItem(); // item.Header = caption; // item.Click += click; // return item; // } // // private ContextMenu? CreateIssuesMenu(CoreRow[]? rows) // { // if (!Security.CanManageIssues()) // return null; // // var issues = rows?.Select(GetIssues).Where(x => !string.IsNullOrWhiteSpace(x)).Any(); // var result = new ContextMenu(); // // if (issues != true) // { // result.Items.Add(CreateMenu("Create Issue", (o, e) => EditIssues(rows))); // } // else // { // result.Items.Add(CreateMenu("Update Issues", (o, e) => EditIssues(rows))); // result.Items.Add(CreateMenu("Clear Issues", (o, e) => ClearIssues(rows))); // } // // return result; // } // // private void ClearIssues(CoreRow[]? rows) // { // if (rows is null) // { // return; // } // if (MessageBox.Show("This will clear the flagged issues for these items!\n\nAre you sure you wish to continue?", "Confirm", // MessageBoxButton.YesNo) == MessageBoxResult.Yes) // { // var _updates = LoadIssues(rows).ToArray(); // foreach (var update in _updates) // { // update.Issues = ""; // } // using (new WaitCursor()) // { // Client.Save(_updates, "Clearing Issues", (o, e) => { }); // } // // // False here to prevent Refreshing and losing the selected row record // foreach (var row in rows) // _parent.UpdateRow(row, IssuesProperty, ""); // } // } // // private void EditIssues(CoreRow[]? rows) // { // var _objects = LoadIssues(rows ?? Array.Empty()); // // var _map = new Dictionary(); // if (rows is not null) // { // var i = 0; // foreach (var row in rows) // { // _map[row] = _objects[i]; // ++i; // } // } // // var _values = _map.Values.OfType().ToArray(); // var _editor = new DynamicIssuesEditor(_values); // var _custom = CustomiseEditor?.Invoke(_values); // if (_custom != null) // _editor.SetCustom(_custom); // if (_editor.ShowDialog() == true) // { // using (new WaitCursor()) // { // if (_custom != null) // IssuesUpdated?.Invoke(_values, _custom); // Client.Save(_map.Values, "Updating Issues", (o, e) => { }); // } // // foreach (var _row in _map.Keys) // _parent.UpdateRow(_row, IssuesProperty, _map[_row].Issues); // } // } // }