|
@@ -15,6 +15,7 @@ using InABox.Scripting;
|
|
|
using InABox.Wpf;
|
|
|
using InABox.WPF;
|
|
|
using Microsoft.Win32;
|
|
|
+using NPOI.HPSF;
|
|
|
|
|
|
namespace InABox.DynamicGrid
|
|
|
{
|
|
@@ -175,6 +176,8 @@ namespace InABox.DynamicGrid
|
|
|
{
|
|
|
CopyForm.Visibility = Visibility.Collapsed;
|
|
|
}
|
|
|
+
|
|
|
+ OnCustomiseEditor += DigitalFormGrid_OnCustomiseEditor;
|
|
|
}
|
|
|
|
|
|
protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
@@ -356,6 +359,44 @@ namespace InABox.DynamicGrid
|
|
|
return pages;
|
|
|
}
|
|
|
|
|
|
+ private DynamicVariableGrid? GetVariableGrid(IDynamicEditorForm sender)
|
|
|
+ => sender.Pages?.FirstOrDefault(x => x is DynamicVariableGrid)
|
|
|
+ as DynamicVariableGrid;
|
|
|
+
|
|
|
+ private List<DigitalFormVariable> GetVariables(IDynamicEditorForm sender)
|
|
|
+ => GetVariableGrid(sender)?.Items.ToList() ?? new List<DigitalFormVariable>();
|
|
|
+
|
|
|
+ // Using the event because it also has the editor form 'sender'.
|
|
|
+ private void DigitalFormGrid_OnCustomiseEditor(IDynamicEditorForm sender, DigitalForm[]? items, DynamicGridColumn column, BaseEditor editor)
|
|
|
+ {
|
|
|
+ if(new Column<DigitalForm>(x => x.DescriptionExpression).IsEqualTo(column.ColumnName) && editor is ExpressionEditor exp)
|
|
|
+ {
|
|
|
+ exp.OnGetVariables += () =>
|
|
|
+ {
|
|
|
+ var variables = new List<string>();
|
|
|
+ foreach (var variable in GetVariables(sender))
|
|
|
+ {
|
|
|
+ foreach (var col in variable.GetVariableColumns())
|
|
|
+ {
|
|
|
+ variables.Add($"Form_Data.{col.ColumnName}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var appliesTo = items?.Select(x => x.AppliesTo).Distinct().SingleOrDefault();
|
|
|
+ if (!appliesTo.IsNullOrWhiteSpace() && DFUtils.GetFormInstanceType(appliesTo) is Type formType)
|
|
|
+ {
|
|
|
+ foreach(var property in DatabaseSchema.Properties(formType))
|
|
|
+ {
|
|
|
+ variables.Add(property.Name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ variables.Sort();
|
|
|
+ return variables;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public override bool EditItems(DigitalForm[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false)
|
|
|
{
|
|
|
// Need to do this to make sure that the variables are available to the layouts (and vice versa?)
|