|
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
+using System.Threading;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using InABox.Core;
|
|
|
@@ -13,430 +14,478 @@ using NPOI.OpenXmlFormats;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using NPOI.Util.Collections;
|
|
|
|
|
|
-namespace InABox.DynamicGrid
|
|
|
+namespace InABox.DynamicGrid;
|
|
|
+
|
|
|
+public class DynamicVariableGrid : DynamicDataGrid<DigitalFormVariable>
|
|
|
{
|
|
|
- internal class DynamicVariableGrid : DynamicOneToManyGrid<DigitalForm, DigitalFormVariable>
|
|
|
- {
|
|
|
- private bool ShowHidden = false;
|
|
|
- private Button ShowHiddenButton;
|
|
|
- private Button HideButton;
|
|
|
+ private bool ShowHidden = false;
|
|
|
+ private Button ShowHiddenButton;
|
|
|
+ private Button HideButton;
|
|
|
+
|
|
|
+ public DigitalForm? Form { get; set; }
|
|
|
|
|
|
- protected override void Init()
|
|
|
+ private DigitalFormVariable[]? _variables;
|
|
|
+ public DigitalFormVariable[] Variables
|
|
|
+ {
|
|
|
+ get
|
|
|
{
|
|
|
- base.Init();
|
|
|
+ _variables ??= Data.ToArray<DigitalFormVariable>();
|
|
|
+ return _variables;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- ShowHiddenButton = AddButton("Show Hidden", null, ToggleHidden_Click);
|
|
|
- HideButton = AddEditButton("Hide Variable", null, Hide_Click);
|
|
|
- HideButton.IsEnabled = false;
|
|
|
+ protected override void Init()
|
|
|
+ {
|
|
|
+ base.Init();
|
|
|
+
|
|
|
+ ShowHiddenButton = AddButton("Show Hidden", null, ToggleHidden_Click);
|
|
|
+ HideButton = AddEditButton("Hide Variable", null, Hide_Click);
|
|
|
+ HideButton.IsEnabled = false;
|
|
|
+
|
|
|
+ HiddenColumns.Add(x => x.Hidden);
|
|
|
+ HiddenColumns.Add(x => x.Code);
|
|
|
+ HiddenColumns.Add(x => x.VariableType);
|
|
|
+ HiddenColumns.Add(x => x.Parameters);
|
|
|
+ HiddenColumns.Add(x => x.Required);
|
|
|
+ HiddenColumns.Add(x => x.Secure);
|
|
|
+ HiddenColumns.Add(x => x.Retain);
|
|
|
+ }
|
|
|
|
|
|
- HiddenColumns.Add(x => x.Hidden);
|
|
|
- HiddenColumns.Add(x => x.Code);
|
|
|
- HiddenColumns.Add(x => x.VariableType);
|
|
|
- HiddenColumns.Add(x => x.Parameters);
|
|
|
- HiddenColumns.Add(x => x.Required);
|
|
|
- HiddenColumns.Add(x => x.Secure);
|
|
|
- HiddenColumns.Add(x => x.Retain);
|
|
|
- }
|
|
|
+ protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
+ {
|
|
|
+ base.DoReconfigure(options);
|
|
|
|
|
|
- protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
- {
|
|
|
- base.DoReconfigure(options);
|
|
|
+ options.MultiSelect = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DigitalFormVariable? GetVariable(string code)
|
|
|
+ {
|
|
|
+ return Data.Rows
|
|
|
+ .Where(x => x.Get<DigitalFormVariable, string>(x => x.Code) == code)
|
|
|
+ .FirstOrDefault()
|
|
|
+ ?.ToObject<DigitalFormVariable>();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static bool ShouldHide(CoreRow[] rows)
|
|
|
+ {
|
|
|
+ return rows.Any(x => !x.Get<DigitalFormVariable, bool>(x => x.Hidden));
|
|
|
+ }
|
|
|
|
|
|
- options.MultiSelect = true;
|
|
|
+ private bool Hide_Click(Button btn, CoreRow[] rows)
|
|
|
+ {
|
|
|
+ if(rows.Length == 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("No rows selected");
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- public DigitalFormVariable? GetVariable(string code)
|
|
|
+ var hide = ShouldHide(rows);
|
|
|
+ var items = rows.ToArray<DigitalFormVariable>();
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ item.Hidden = hide;
|
|
|
+ }
|
|
|
+ if(items.Length > 0)
|
|
|
{
|
|
|
- return Items.Where(x => x.Code == code).FirstOrDefault();
|
|
|
+ SaveItems(items);
|
|
|
+ return true;
|
|
|
}
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void SelectItems(CoreRow[]? rows)
|
|
|
+ {
|
|
|
+ base.SelectItems(rows);
|
|
|
|
|
|
- private static bool ShouldHide(CoreRow[] rows)
|
|
|
+ if(rows is null)
|
|
|
+ {
|
|
|
+ HideButton.IsEnabled = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- return rows.Any(x => !x.Get<DigitalFormVariable, bool>(x => x.Hidden));
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CreateMenu(ContextMenu parent, string header, Type type)
|
|
|
+ {
|
|
|
+ if (Form is null) return;
|
|
|
|
|
|
- private bool Hide_Click(Button btn, CoreRow[] rows)
|
|
|
+ parent.AddItem(header, null, type, (itemtype) =>
|
|
|
{
|
|
|
- if(rows.Length == 0)
|
|
|
+ if(DynamicVariableUtils.CreateAndEdit(Form, Data.ToArray<DigitalFormVariable>(), itemtype, out var variable))
|
|
|
{
|
|
|
- MessageBox.Show("No rows selected");
|
|
|
- return false;
|
|
|
+ SaveItem(variable);
|
|
|
+ Refresh(false, true);
|
|
|
}
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- 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 DoAdd(bool openEditorOnDirectEdit = false)
|
|
|
+ {
|
|
|
+ var menu = new ContextMenu();
|
|
|
|
|
|
- protected override void SelectItems(CoreRow[]? rows)
|
|
|
+ foreach(var fieldType in DFUtils.GetFieldTypes())
|
|
|
{
|
|
|
- base.SelectItems(rows);
|
|
|
-
|
|
|
- if(rows is null)
|
|
|
- {
|
|
|
- HideButton.IsEnabled = false;
|
|
|
- }
|
|
|
- else
|
|
|
+ var caption = fieldType.GetCaption();
|
|
|
+ if (string.IsNullOrWhiteSpace(caption))
|
|
|
{
|
|
|
- HideButton.IsEnabled = true;
|
|
|
- HideButton.Content = (ShouldHide(rows) ? "Hide Variable" : "Un-hide Variable") + (rows.Length > 1 ? "s" : "");
|
|
|
+ caption = CoreUtils.Neatify(fieldType.Name);
|
|
|
}
|
|
|
+ CreateMenu(menu, caption, fieldType);
|
|
|
}
|
|
|
|
|
|
- private bool ToggleHidden_Click(Button btn, CoreRow[] rows)
|
|
|
- {
|
|
|
- ShowHidden = !ShowHidden;
|
|
|
- ShowHiddenButton.Content = ShowHidden ? "Hide Hidden" : "Show Hidden";
|
|
|
- return true;
|
|
|
- }
|
|
|
+ menu.IsOpen = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override bool CanCreateItems()
|
|
|
+ {
|
|
|
+ return base.CanCreateItems() && Form is not null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override DigitalFormVariable CreateItem()
|
|
|
+ {
|
|
|
+ var item = base.CreateItem();
|
|
|
+ item.Form.ID = Form?.ID ?? Guid.Empty;
|
|
|
+ return item;
|
|
|
+ }
|
|
|
|
|
|
- private void CreateMenu(ContextMenu parent, string header, Type type)
|
|
|
+ protected override void DoEdit()
|
|
|
+ {
|
|
|
+ if (!SelectedRows.Any() || Form is null)
|
|
|
+ return;
|
|
|
+ var variable = SelectedRows.First().ToObject<DigitalFormVariable>();
|
|
|
+ var properties = variable.CreateProperties();
|
|
|
+ if (DynamicVariableUtils.EditProperties(Form, Variables, properties.GetType(), properties, !Security.CanEdit<DigitalFormVariable>()))
|
|
|
{
|
|
|
- parent.AddItem(header, null, type, (itemtype) =>
|
|
|
- {
|
|
|
- if(DynamicVariableUtils.CreateAndEdit(Item, Items, itemtype, out var variable))
|
|
|
- {
|
|
|
- SaveItem(variable);
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
- });
|
|
|
+ variable.SaveProperties(properties);
|
|
|
+ SaveItem(variable);
|
|
|
+ Refresh(false, true);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- protected override void DoAdd(bool openEditorOnDirectEdit = false)
|
|
|
- {
|
|
|
- var menu = new ContextMenu();
|
|
|
+ protected override void DoDelete()
|
|
|
+ {
|
|
|
+ var rows = SelectedRows.ToArray();
|
|
|
|
|
|
- foreach(var fieldType in DFUtils.GetFieldTypes())
|
|
|
- {
|
|
|
- var caption = fieldType.GetCaption();
|
|
|
- if (string.IsNullOrWhiteSpace(caption))
|
|
|
+ if (rows.Length != 0)
|
|
|
+ if (CanDeleteItems(rows))
|
|
|
+ if (MessageWindow.ShowYesNo(
|
|
|
+ "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"))
|
|
|
{
|
|
|
- caption = CoreUtils.Neatify(fieldType.Name);
|
|
|
+ DeleteItems(rows);
|
|
|
+ SelectedRows = Array.Empty<CoreRow>();
|
|
|
+ DoChanged();
|
|
|
+ Refresh(false, true);
|
|
|
+ SelectItems(null);
|
|
|
}
|
|
|
- CreateMenu(menu, caption, fieldType);
|
|
|
- }
|
|
|
-
|
|
|
- menu.IsOpen = true;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- /*public override DigitalFormVariable LoadItem(CoreRow row)
|
|
|
- {
|
|
|
- return Items.FirstOrDefault(r => r.ID.Equals(row.Get<DigitalFormVariable, Guid>(c => c.ID)));
|
|
|
- }*/
|
|
|
+ protected override bool FilterRecord(CoreRow row)
|
|
|
+ {
|
|
|
+ return ShowHidden || !row.Get<DigitalFormVariable, bool>(x => x.Hidden);
|
|
|
+ }
|
|
|
|
|
|
- protected override void DoEdit()
|
|
|
- {
|
|
|
- if (!SelectedRows.Any())
|
|
|
- return;
|
|
|
- var variable = LoadItem(SelectedRows.First());
|
|
|
- var properties = variable.CreateProperties();
|
|
|
- if (DynamicVariableUtils.EditProperties(Item, Items, properties.GetType(), properties, ReadOnly))
|
|
|
- {
|
|
|
- variable.SaveProperties(properties);
|
|
|
- SaveItem(variable);
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
- }
|
|
|
+ protected override void OnAfterRefresh()
|
|
|
+ {
|
|
|
+ base.OnAfterRefresh();
|
|
|
+ _variables = null;
|
|
|
+ }
|
|
|
|
|
|
- protected override void DoDelete()
|
|
|
+ protected override void Reload(Filters<DigitalFormVariable> criteria, Columns<DigitalFormVariable> columns, ref SortOrder<DigitalFormVariable>? sort, CancellationToken token, Action<CoreTable?, Exception?> action)
|
|
|
+ {
|
|
|
+ if(Form is null)
|
|
|
{
|
|
|
- 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>();
|
|
|
- DoChanged();
|
|
|
- Refresh(false, true);
|
|
|
- SelectItems(null);
|
|
|
- }
|
|
|
+ criteria.Add(Filter.None<DigitalFormVariable>());
|
|
|
}
|
|
|
-
|
|
|
- protected override bool FilterRecord(CoreRow row)
|
|
|
+ else
|
|
|
{
|
|
|
- return ShowHidden || !row.Get<DigitalFormVariable, bool>(x => x.Hidden);
|
|
|
+ criteria.Add(Filter<DigitalFormVariable>.Where(x => x.Form.ID).IsEqualTo(Form.ID));
|
|
|
}
|
|
|
+ base.Reload(criteria, columns, ref sort, token, action);
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- public class DFLookupFilterNode : ComboBox, ICustomValueNode
|
|
|
+public class DFLookupFilterNode : ComboBox, ICustomValueNode
|
|
|
+{
|
|
|
+ public DFLookupFilterNode(Type entityType, CustomFilterValue? selectedValue)
|
|
|
{
|
|
|
- public DFLookupFilterNode(Type entityType, CustomFilterValue? selectedValue)
|
|
|
+ var properties = CoreUtils.PropertyList(entityType, x => x.GetCustomAttribute<DoNotSerialize>() == null, true).Keys.ToList();
|
|
|
+ properties.Sort();
|
|
|
+ Items.Add("");
|
|
|
+ foreach (var property in properties)
|
|
|
{
|
|
|
- var properties = CoreUtils.PropertyList(entityType, x => x.GetCustomAttribute<DoNotSerialize>() == null, true).Keys.ToList();
|
|
|
- properties.Sort();
|
|
|
- Items.Add("");
|
|
|
- foreach (var property in properties)
|
|
|
- {
|
|
|
- Items.Add(property);
|
|
|
- }
|
|
|
+ Items.Add(property);
|
|
|
+ }
|
|
|
|
|
|
- Value = selectedValue;
|
|
|
+ Value = selectedValue;
|
|
|
|
|
|
- SelectionChanged += DFLookupFilterNode_SelectionChanged;
|
|
|
+ SelectionChanged += DFLookupFilterNode_SelectionChanged;
|
|
|
|
|
|
- VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
|
|
|
- VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
|
|
|
- MinWidth = 50;
|
|
|
+ VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
|
|
|
+ VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
|
|
|
+ MinWidth = 50;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DFLookupFilterNode_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ {
|
|
|
+ var text = SelectedItem as string;
|
|
|
+ if (text.IsNullOrWhiteSpace())
|
|
|
+ {
|
|
|
+ _value = null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _value = new CustomFilterValue(System.Text.Encoding.UTF8.GetBytes(text));
|
|
|
}
|
|
|
+ ValueChanged?.Invoke(this, Value);
|
|
|
+ }
|
|
|
|
|
|
- private void DFLookupFilterNode_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ private CustomFilterValue? _value;
|
|
|
+ public CustomFilterValue? Value
|
|
|
+ {
|
|
|
+ get => _value;
|
|
|
+ set
|
|
|
{
|
|
|
- var text = SelectedItem as string;
|
|
|
- if (text.IsNullOrWhiteSpace())
|
|
|
+ if(value is not null)
|
|
|
{
|
|
|
- _value = null;
|
|
|
+ var text = System.Text.Encoding.UTF8.GetString(value.Data);
|
|
|
+ SelectedItem = text;
|
|
|
+ _value = value;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- _value = new CustomFilterValue(System.Text.Encoding.UTF8.GetBytes(text));
|
|
|
- }
|
|
|
- ValueChanged?.Invoke(this, Value);
|
|
|
- }
|
|
|
-
|
|
|
- private CustomFilterValue? _value;
|
|
|
- public CustomFilterValue? Value
|
|
|
- {
|
|
|
- get => _value;
|
|
|
- set
|
|
|
- {
|
|
|
- if(value is not null)
|
|
|
- {
|
|
|
- var text = System.Text.Encoding.UTF8.GetString(value.Data);
|
|
|
- SelectedItem = text;
|
|
|
- _value = value;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- SelectedItem = null;
|
|
|
- _value = null;
|
|
|
- }
|
|
|
+ SelectedItem = null;
|
|
|
+ _value = null;
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- public FrameworkElement FrameworkElement => this;
|
|
|
+ public FrameworkElement FrameworkElement => this;
|
|
|
|
|
|
- public event ICustomValueNode.ValueChangedHandler? ValueChanged;
|
|
|
- }
|
|
|
+ public event ICustomValueNode.ValueChangedHandler? ValueChanged;
|
|
|
+}
|
|
|
|
|
|
- public static class DynamicVariableUtils
|
|
|
+public static class DynamicVariableUtils
|
|
|
+{
|
|
|
+ public static bool CreateAndEdit(
|
|
|
+ DigitalForm form, IList<DigitalFormVariable> variables,
|
|
|
+ Type fieldType,
|
|
|
+ [NotNullWhen(true)] out DigitalFormVariable? variable)
|
|
|
{
|
|
|
- public static bool CreateAndEdit(
|
|
|
- DigitalForm form, IList<DigitalFormVariable> variables,
|
|
|
- Type fieldType,
|
|
|
- [NotNullWhen(true)] out DigitalFormVariable? variable)
|
|
|
+ var fieldBaseType = fieldType.GetSuperclassDefinition(typeof(DFLayoutField<>));
|
|
|
+ if (fieldBaseType != null)
|
|
|
{
|
|
|
- var fieldBaseType = fieldType.GetSuperclassDefinition(typeof(DFLayoutField<>));
|
|
|
- if (fieldBaseType != null)
|
|
|
+ var propertiesType = fieldBaseType.GetGenericArguments()[0];
|
|
|
+ var properties = (Activator.CreateInstance(propertiesType) as DFLayoutFieldProperties)!;
|
|
|
+ if (DynamicVariableUtils.EditProperties(form, variables, propertiesType, properties, readOnly: false))
|
|
|
{
|
|
|
- var propertiesType = fieldBaseType.GetGenericArguments()[0];
|
|
|
- var properties = (Activator.CreateInstance(propertiesType) as DFLayoutFieldProperties)!;
|
|
|
- if (DynamicVariableUtils.EditProperties(form, variables, propertiesType, properties, readOnly: false))
|
|
|
- {
|
|
|
- variable = new DigitalFormVariable();
|
|
|
- variable.SaveProperties(fieldType, properties);
|
|
|
- return true;
|
|
|
- }
|
|
|
+ variable = new DigitalFormVariable();
|
|
|
+ variable.Form.CopyFrom(form);
|
|
|
+ variable.SaveProperties(fieldType, properties);
|
|
|
+ return true;
|
|
|
}
|
|
|
- variable = null;
|
|
|
- return false;
|
|
|
}
|
|
|
+ variable = null;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- public static bool EditProperties(DigitalForm form, IList<DigitalFormVariable> variables, Type type, DFLayoutFieldProperties item, bool readOnly)
|
|
|
+ public static bool EditProperties(DigitalForm form, IList<DigitalFormVariable> variables, Type type, DFLayoutFieldProperties item, bool readOnly)
|
|
|
+ {
|
|
|
+ var editor = new DynamicEditorForm(type);
|
|
|
+ editor.ReadOnly = readOnly;
|
|
|
+ if (item is DFLayoutLookupFieldProperties)
|
|
|
{
|
|
|
- var editor = new DynamicEditorForm(type);
|
|
|
- editor.ReadOnly = readOnly;
|
|
|
- if (item is DFLayoutLookupFieldProperties)
|
|
|
+ var appliesToType = DFUtils.FormEntityType(form);
|
|
|
+ editor.OnReconfigureEditors = grid =>
|
|
|
{
|
|
|
- var appliesToType = DFUtils.FormEntityType(form);
|
|
|
- editor.OnReconfigureEditors = grid =>
|
|
|
+ var filter = grid.FindEditor("Filter");
|
|
|
+ if(filter is FilterEditorControl filterEditor)
|
|
|
{
|
|
|
- var filter = grid.FindEditor("Filter");
|
|
|
- if(filter is FilterEditorControl filterEditor)
|
|
|
- {
|
|
|
- var config = new FilterEditorConfiguration();
|
|
|
+ var config = new FilterEditorConfiguration();
|
|
|
|
|
|
- config.OnCreateCustomValueNode += (type, prop, op, value) =>
|
|
|
- {
|
|
|
- if (appliesToType is not null)
|
|
|
- {
|
|
|
- return new DFLookupFilterNode(appliesToType, value);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return null;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- filterEditor.Configuration = config;
|
|
|
- }
|
|
|
- };
|
|
|
- editor.OnFormCustomiseEditor += (sender, items, column, editor) => LookupEditor_OnFormCustomiseEditor(sender, variables, items, column, editor);
|
|
|
- editor.OnEditorValueChanged += (sender, name, value) =>
|
|
|
- {
|
|
|
- var result = DynamicGridUtils.UpdateEditorValue(new[] { item }, name, value);
|
|
|
- if (name == "LookupType")
|
|
|
+ config.OnCreateCustomValueNode += (type, prop, op, value) =>
|
|
|
{
|
|
|
- var grid = (sender as EmbeddedDynamicEditorForm)?.Editor!;
|
|
|
- var edit = grid.FindEditor("Filter");
|
|
|
- if (edit is FilterEditorControl filter)
|
|
|
+ if (appliesToType is not null)
|
|
|
{
|
|
|
- filter.FilterType = value is string str ?
|
|
|
- CoreUtils.GetEntityOrNull(str) :
|
|
|
- null;
|
|
|
+ return new DFLookupFilterNode(appliesToType, value);
|
|
|
}
|
|
|
-
|
|
|
- var propertiesEditor = grid.FindEditor(nameof(DFLayoutLookupFieldProperties.AdditionalProperties));
|
|
|
- if (propertiesEditor is MultiLookupEditorControl multi && multi.EditorDefinition is MultiLookupEditor combo)
|
|
|
+ else
|
|
|
{
|
|
|
- combo.Clear();
|
|
|
- multi.Configure();
|
|
|
+ return null;
|
|
|
}
|
|
|
+ };
|
|
|
+
|
|
|
+ filterEditor.Configuration = config;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ editor.OnFormCustomiseEditor += (sender, items, column, editor) => LookupEditor_OnFormCustomiseEditor(sender, variables, items, column, editor);
|
|
|
+ editor.OnEditorValueChanged += (sender, name, value) =>
|
|
|
+ {
|
|
|
+ var result = DynamicGridUtils.UpdateEditorValue(new[] { item }, name, value);
|
|
|
+ if (name == "LookupType")
|
|
|
+ {
|
|
|
+ var grid = (sender as EmbeddedDynamicEditorForm)?.Editor!;
|
|
|
+ var edit = grid.FindEditor("Filter");
|
|
|
+ if (edit is FilterEditorControl filter)
|
|
|
+ {
|
|
|
+ filter.FilterType = value is string str ?
|
|
|
+ CoreUtils.GetEntityOrNull(str) :
|
|
|
+ null;
|
|
|
+ }
|
|
|
+
|
|
|
+ var propertiesEditor = grid.FindEditor(nameof(DFLayoutLookupFieldProperties.AdditionalProperties));
|
|
|
+ if (propertiesEditor is MultiLookupEditorControl multi && multi.EditorDefinition is MultiLookupEditor combo)
|
|
|
+ {
|
|
|
+ combo.Clear();
|
|
|
+ multi.Configure();
|
|
|
}
|
|
|
- OnEditorValueChanged(sender, name, value);
|
|
|
- return new();
|
|
|
- };
|
|
|
+ }
|
|
|
+ OnEditorValueChanged(sender, name, value);
|
|
|
+ return new();
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ editor.OnFormCustomiseEditor += (sender, items, column, editor) => Editor_OnFormCustomiseEditor(sender, variables, column, editor);
|
|
|
+ editor.OnEditorValueChanged += (sender, name, value) =>
|
|
|
+ {
|
|
|
+ var result = DynamicGridUtils.UpdateEditorValue(new[] { item }, name, value);
|
|
|
+ OnEditorValueChanged(sender, name, value);
|
|
|
+ return result;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ editor.OnCreateEditorControl += Editor_OnCreateEditorControl;
|
|
|
+
|
|
|
+ editor.OnDefineLookups += o =>
|
|
|
+ {
|
|
|
+ var def = (o.EditorDefinition as ILookupEditor)!;
|
|
|
+ var colname = o.ColumnName;
|
|
|
+ // Nope, there is nothing dodgy about this at all
|
|
|
+ // I am not breaking any rules by passing in the QA Form instance, rather than the Field instance
|
|
|
+ // so that I can get access to the "AppliesTo" property, and thus the list of properties that can be updated
|
|
|
+ // Nothing to see here, I promise!
|
|
|
+ CoreTable? values;
|
|
|
+ if (o.ColumnName == "Property")
|
|
|
+ {
|
|
|
+ values = def.Values(colname, new[] { form });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- editor.OnFormCustomiseEditor += (sender, items, column, editor) => Editor_OnFormCustomiseEditor(sender, variables, column, editor);
|
|
|
- editor.OnEditorValueChanged += (sender, name, value) =>
|
|
|
- {
|
|
|
- var result = DynamicGridUtils.UpdateEditorValue(new[] { item }, name, value);
|
|
|
- OnEditorValueChanged(sender, name, value);
|
|
|
- return result;
|
|
|
- };
|
|
|
+ values = def.Values(colname, new[] { item });
|
|
|
}
|
|
|
- editor.OnCreateEditorControl += Editor_OnCreateEditorControl;
|
|
|
|
|
|
- editor.OnDefineLookups += o =>
|
|
|
+ o.LoadLookups(values);
|
|
|
+ };
|
|
|
+
|
|
|
+ var thisVariable = variables.Where(x => x.Code == item.Code).ToList();
|
|
|
+
|
|
|
+ editor.OnValidateData += (sender, items) =>
|
|
|
+ {
|
|
|
+ var errors = new List<string>();
|
|
|
+ foreach(var item in items.Cast<DFLayoutFieldProperties>())
|
|
|
{
|
|
|
- var def = (o.EditorDefinition as ILookupEditor)!;
|
|
|
- var colname = o.ColumnName;
|
|
|
- // Nope, there is nothing dodgy about this at all
|
|
|
- // I am not breaking any rules by passing in the QA Form instance, rather than the Field instance
|
|
|
- // so that I can get access to the "AppliesTo" property, and thus the list of properties that can be updated
|
|
|
- // Nothing to see here, I promise!
|
|
|
- CoreTable? values;
|
|
|
- if (o.ColumnName == "Property")
|
|
|
+ // Check Codes
|
|
|
+ if (string.IsNullOrWhiteSpace(item.Code))
|
|
|
{
|
|
|
- values = def.Values(colname, new[] { form });
|
|
|
+ errors.Add("[Code] may not be blank!");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- values = def.Values(colname, new[] { item });
|
|
|
- }
|
|
|
-
|
|
|
- o.LoadLookups(values);
|
|
|
- };
|
|
|
-
|
|
|
- var thisVariable = variables.Where(x => x.Code == item.Code).ToList();
|
|
|
-
|
|
|
- editor.OnValidateData += (sender, items) =>
|
|
|
- {
|
|
|
- var errors = new List<string>();
|
|
|
- foreach(var item in items.Cast<DFLayoutFieldProperties>())
|
|
|
- {
|
|
|
- // Check Codes
|
|
|
- if (string.IsNullOrWhiteSpace(item.Code))
|
|
|
+ var codeVars = variables.Where(x => x.Code == item.Code).ToList();
|
|
|
+ if(codeVars.Count > 1)
|
|
|
{
|
|
|
- errors.Add("[Code] may not be blank!");
|
|
|
+ errors.Add($"Duplicate code [{item.Code}]");
|
|
|
}
|
|
|
- else
|
|
|
+ else if(codeVars.Count == 1)
|
|
|
{
|
|
|
- var codeVars = variables.Where(x => x.Code == item.Code).ToList();
|
|
|
- if(codeVars.Count > 1)
|
|
|
- {
|
|
|
- errors.Add($"Duplicate code [{item.Code}]");
|
|
|
- }
|
|
|
- else if(codeVars.Count == 1)
|
|
|
+ if (!thisVariable.Contains(codeVars.First()))
|
|
|
{
|
|
|
- if (!thisVariable.Contains(codeVars.First()))
|
|
|
- {
|
|
|
- errors.Add($"There is already a variable with code [{item.Code}]");
|
|
|
- }
|
|
|
+ errors.Add($"There is already a variable with code [{item.Code}]");
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // Check Read-Only property
|
|
|
- if(item.ReadOnlyProperty && item.Property.IsNullOrWhiteSpace() && item.Expression.IsNullOrWhiteSpace())
|
|
|
- {
|
|
|
- errors.Add("A field cannot be read-only if [Property] or [Expression] have not been set.");
|
|
|
- }
|
|
|
+ // Check Read-Only property
|
|
|
+ if(item.ReadOnlyProperty && item.Property.IsNullOrWhiteSpace() && item.Expression.IsNullOrWhiteSpace())
|
|
|
+ {
|
|
|
+ errors.Add("A field cannot be read-only if [Property] or [Expression] have not been set.");
|
|
|
}
|
|
|
- return errors;
|
|
|
- };
|
|
|
- editor.Items = new BaseObject[] { item };
|
|
|
- return editor.ShowDialog() == true;
|
|
|
- }
|
|
|
+ }
|
|
|
+ return errors;
|
|
|
+ };
|
|
|
+ editor.Items = new BaseObject[] { item };
|
|
|
+ return editor.ShowDialog() == true;
|
|
|
+ }
|
|
|
|
|
|
- private static void Editor_OnCreateEditorControl(string column, BaseEditor editor, IDynamicEditorControl control)
|
|
|
+ private static void Editor_OnCreateEditorControl(string column, BaseEditor editor, IDynamicEditorControl control)
|
|
|
+ {
|
|
|
+ var properties = (control.Host.GetItems()[0] as DFLayoutFieldProperties)!;
|
|
|
+ if(column == nameof(DFLayoutFieldProperties.ReadOnlyProperty))
|
|
|
{
|
|
|
- var properties = (control.Host.GetItems()[0] as DFLayoutFieldProperties)!;
|
|
|
- if(column == nameof(DFLayoutFieldProperties.ReadOnlyProperty))
|
|
|
+ if (properties.Property.IsNullOrWhiteSpace())
|
|
|
{
|
|
|
- if (properties.Property.IsNullOrWhiteSpace())
|
|
|
- {
|
|
|
- control.IsEnabled = false;
|
|
|
- }
|
|
|
+ control.IsEnabled = false;
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private static void Editor_OnFormCustomiseEditor(IDynamicEditorForm sender, IList<DigitalFormVariable> vars, DynamicGridColumn column, BaseEditor editor)
|
|
|
+ private static void Editor_OnFormCustomiseEditor(IDynamicEditorForm sender, IList<DigitalFormVariable> vars, DynamicGridColumn column, BaseEditor editor)
|
|
|
+ {
|
|
|
+ var properties = (sender.Items[0] as DFLayoutFieldProperties)!;
|
|
|
+ if ((column.ColumnName == "Expression" || column.ColumnName == "ColourExpression") && editor is ExpressionEditor exp)
|
|
|
{
|
|
|
- var properties = (sender.Items[0] as DFLayoutFieldProperties)!;
|
|
|
- if ((column.ColumnName == "Expression" || column.ColumnName == "ColourExpression") && editor is ExpressionEditor exp)
|
|
|
+ var variables = new List<string>();
|
|
|
+ foreach (var variable in vars)
|
|
|
{
|
|
|
- var variables = new List<string>();
|
|
|
- foreach (var variable in vars)
|
|
|
+ //variables.Add(variable.Code);
|
|
|
+ foreach (var col in variable.GetVariableColumns())
|
|
|
{
|
|
|
- //variables.Add(variable.Code);
|
|
|
- foreach (var col in variable.GetVariableColumns())
|
|
|
- {
|
|
|
- variables.Add(col.ColumnName);
|
|
|
- }
|
|
|
+ variables.Add(col.ColumnName);
|
|
|
}
|
|
|
+ }
|
|
|
+ if(column.ColumnName == "Expression")
|
|
|
+ {
|
|
|
variables.Remove(properties.Code);
|
|
|
- variables.Sort();
|
|
|
- exp.VariableNames = variables;
|
|
|
}
|
|
|
+ variables.Sort();
|
|
|
+ exp.VariableNames = variables;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private static void LookupEditor_OnFormCustomiseEditor(IDynamicEditorForm sender, IList<DigitalFormVariable> vars, object[] items, DynamicGridColumn column, BaseEditor editor)
|
|
|
+ private static void LookupEditor_OnFormCustomiseEditor(IDynamicEditorForm sender, IList<DigitalFormVariable> vars, object[] items, DynamicGridColumn column, BaseEditor editor)
|
|
|
+ {
|
|
|
+ if (column.ColumnName == "Filter" && editor is FilterEditor fe)
|
|
|
{
|
|
|
- if (column.ColumnName == "Filter" && editor is FilterEditor fe)
|
|
|
- {
|
|
|
- var properties = (items[0] as DFLayoutLookupFieldProperties)!;
|
|
|
- var lookupType = properties.LookupType;
|
|
|
- var entityType = CoreUtils.GetEntityOrNull(lookupType);
|
|
|
- fe.Type = entityType;
|
|
|
- }
|
|
|
- Editor_OnFormCustomiseEditor(sender, vars, column, editor);
|
|
|
+ var properties = (items[0] as DFLayoutLookupFieldProperties)!;
|
|
|
+ var lookupType = properties.LookupType;
|
|
|
+ var entityType = CoreUtils.GetEntityOrNull(lookupType);
|
|
|
+ fe.Type = entityType;
|
|
|
}
|
|
|
+ Editor_OnFormCustomiseEditor(sender, vars, column, editor);
|
|
|
+ }
|
|
|
|
|
|
- private static void OnEditorValueChanged(IDynamicEditorForm sender, string name, object value)
|
|
|
+ private static void OnEditorValueChanged(IDynamicEditorForm sender, string name, object value)
|
|
|
+ {
|
|
|
+ if(name == nameof(DFLayoutFieldProperties.Property))
|
|
|
{
|
|
|
- if(name == nameof(DFLayoutFieldProperties.Property))
|
|
|
+ var properties = (sender.Items[0] as DFLayoutFieldProperties)!;
|
|
|
+ var grid = (sender as EmbeddedDynamicEditorForm)?.Editor!;
|
|
|
+ var edit = grid.FindEditor(nameof(DFLayoutFieldProperties.ReadOnlyProperty));
|
|
|
+ if (edit is not null)
|
|
|
{
|
|
|
- var properties = (sender.Items[0] as DFLayoutFieldProperties)!;
|
|
|
- var grid = (sender as EmbeddedDynamicEditorForm)?.Editor!;
|
|
|
- var edit = grid.FindEditor(nameof(DFLayoutFieldProperties.ReadOnlyProperty));
|
|
|
- if (edit is not null)
|
|
|
- {
|
|
|
- edit.IsEnabled = !properties.Property.IsNullOrWhiteSpace() && !grid.ReadOnly && edit.EditorDefinition.Editable.IsEditable();
|
|
|
- }
|
|
|
+ edit.IsEnabled = !properties.Property.IsNullOrWhiteSpace() && !grid.ReadOnly && edit.EditorDefinition.Editable.IsEditable();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
}
|