|
@@ -1,6 +1,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using InABox.Core;
|
|
|
using NPOI.Util.Collections;
|
|
@@ -9,9 +10,68 @@ namespace InABox.DynamicGrid
|
|
|
{
|
|
|
internal class DynamicVariableGrid : DynamicOneToManyGrid<DigitalForm, DigitalFormVariable>
|
|
|
{
|
|
|
+ private bool ShowHidden = false;
|
|
|
+ private Button ShowHiddenButton;
|
|
|
+ private Button HideButton;
|
|
|
+
|
|
|
public DynamicVariableGrid()
|
|
|
{
|
|
|
Options.Add(DynamicGridOption.MultiSelect);
|
|
|
+
|
|
|
+ ShowHiddenButton = AddButton("Show Hidden", null, ToggleHidden_Click);
|
|
|
+ HideButton = AddButton("Hide Variable", null, Hide_Click);
|
|
|
+ HideButton.IsEnabled = false;
|
|
|
+
|
|
|
+ HiddenColumns.Add(x => x.Hidden);
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool ShouldHide(CoreRow[] rows)
|
|
|
+ {
|
|
|
+ return rows.Any(x => !x.Get<DigitalFormVariable, bool>(x => x.Hidden));
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool Hide_Click(Button btn, CoreRow[] rows)
|
|
|
+ {
|
|
|
+ if(rows.Length == 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("No rows selected");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var hide = ShouldHide(rows);
|
|
|
+ var items = LoadItems(rows);
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ item.Hidden = hide;
|
|
|
+ }
|
|
|
+ if(items.Length > 0)
|
|
|
+ {
|
|
|
+ SaveItems(items);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void SelectItems(CoreRow[]? rows)
|
|
|
+ {
|
|
|
+ base.SelectItems(rows);
|
|
|
+
|
|
|
+ if(rows is null)
|
|
|
+ {
|
|
|
+ HideButton.IsEnabled = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HideButton.IsEnabled = true;
|
|
|
+ HideButton.Content = (ShouldHide(rows) ? "Hide Variable" : "Un-hide Variable") + (rows.Length > 1 ? "s" : "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool ToggleHidden_Click(Button btn, CoreRow[] rows)
|
|
|
+ {
|
|
|
+ ShowHidden = !ShowHidden;
|
|
|
+ ShowHiddenButton.Content = ShowHidden ? "Hide Hidden" : "Show Hidden";
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
public bool EditProperties(Type type, DFLayoutFieldProperties item)
|
|
@@ -163,5 +223,26 @@ namespace InABox.DynamicGrid
|
|
|
Refresh(false, true);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ protected override void DoDelete()
|
|
|
+ {
|
|
|
+ var rows = SelectedRows.ToArray();
|
|
|
+
|
|
|
+ if (rows.Any())
|
|
|
+ if (CanDeleteItems(rows))
|
|
|
+ if (MessageBox.Show("Are you sure you want to delete this variable? This will all cause data associated with this variable to be lost.\n(If you want to just hide the variable, set it to 'Hidden' instead.)", "Confirm Deletion", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ DeleteItems(rows);
|
|
|
+ SelectedRows = Array.Empty<CoreRow>();
|
|
|
+ OnChanged?.Invoke(this);
|
|
|
+ Refresh(false, true);
|
|
|
+ SelectItems(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override bool FilterRecord(CoreRow row)
|
|
|
+ {
|
|
|
+ return ShowHidden || !row.Get<DigitalFormVariable, bool>(x => x.Hidden);
|
|
|
+ }
|
|
|
}
|
|
|
}
|