|
@@ -11,6 +11,7 @@ namespace InABox.Core
|
|
|
public List<string> GetVariables(object?[] items);
|
|
|
}
|
|
|
|
|
|
+ public delegate DataModel GetVariables();
|
|
|
public class ExpressionEditor : BaseEditor
|
|
|
{
|
|
|
/// <summary>
|
|
@@ -18,10 +19,12 @@ namespace InABox.Core
|
|
|
/// </summary>
|
|
|
public Type? ModelType { get; set; }
|
|
|
|
|
|
- private IExpressionModelGenerator? _modelGenerator;
|
|
|
+ private IExpressionModelGenerator? _modelGenerator;
|
|
|
|
|
|
public Type? ModelGenerator { get; }
|
|
|
|
|
|
+ public event GetVariables OnGetVariables;
|
|
|
+
|
|
|
[DoNotSerialize]
|
|
|
[JsonIgnore]
|
|
|
public List<string>? VariableNames { get; set; }
|
|
@@ -29,7 +32,7 @@ namespace InABox.Core
|
|
|
public ExpressionEditor(Type? modelType, Type? modelGenerator = null)
|
|
|
{
|
|
|
ModelType = modelType;
|
|
|
- if(modelGenerator != null)
|
|
|
+ if (modelGenerator != null)
|
|
|
{
|
|
|
if (!typeof(IExpressionModelGenerator).IsAssignableFrom(modelGenerator))
|
|
|
{
|
|
@@ -48,7 +51,7 @@ namespace InABox.Core
|
|
|
}
|
|
|
|
|
|
public List<string> GetVariables(object?[] items)
|
|
|
- {
|
|
|
+ {
|
|
|
if (VariableNames != null)
|
|
|
return VariableNames;
|
|
|
if (ModelGenerator != null)
|
|
@@ -56,9 +59,28 @@ namespace InABox.Core
|
|
|
_modelGenerator ??= (Activator.CreateInstance(ModelGenerator) as IExpressionModelGenerator)!;
|
|
|
return _modelGenerator.GetVariables(items);
|
|
|
}
|
|
|
- if(ModelType != null)
|
|
|
+ if (ModelType != null)
|
|
|
return CoreExpression.GetModelVariables(ModelType);
|
|
|
+
|
|
|
+ var model = OnGetVariables?.Invoke();
|
|
|
+ if (model != null)
|
|
|
+ return GetVariablesFromDataModel(model);
|
|
|
return new List<string>();
|
|
|
}
|
|
|
+
|
|
|
+ private List<string> GetVariablesFromDataModel(DataModel model)
|
|
|
+ {
|
|
|
+ List<string> list = new List<string>();
|
|
|
+ foreach (var table in model.DefaultTables)
|
|
|
+ {
|
|
|
+ foreach (var col in table.Columns)
|
|
|
+ {
|
|
|
+ if (col.ToString() != "ID")
|
|
|
+ list.Add(table.ToString() + "." + col.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list.Sort();
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|
|
|
}
|