mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Conditions - Finished migration to new API
Conditions UI - Updated for new API, needs simplifying before I'm happy with it
This commit is contained in:
1 parent
725bb2a128
commit
805cdc6782
10 files changed
+91
-75
No files matched your search
@@ -96,8 +96,8 @@ namespace Artemis.Core
|
||||
throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a list at path '{newPath}'");
|
||||
|
||||
ListPath = newPath;
|
||||
ListType = listType;
|
||||
IsPrimitiveList = listType.IsPrimitive || listType.IsEnum || listType == typeof(string);
|
||||
ListType = listType.GetGenericArguments()[0];
|
||||
IsPrimitiveList = ListType.IsPrimitive || ListType.IsEnum || ListType == typeof(string);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -182,10 +182,13 @@ namespace Artemis.Core
|
||||
|
||||
// Ensure the list path is valid and points to a list
|
||||
DataModelPath listPath = new DataModelPath(null, Entity.ListPath);
|
||||
if (!listPath.IsValid || !typeof(IList).IsAssignableFrom(listPath.GetPropertyType()))
|
||||
Type listType = listPath.GetPropertyType()!;
|
||||
if (!listPath.IsValid || !typeof(IList).IsAssignableFrom(listType))
|
||||
return;
|
||||
|
||||
ListPath = listPath;
|
||||
ListType = listType.GetGenericArguments()[0];
|
||||
IsPrimitiveList = ListType.IsPrimitive || ListType.IsEnum || ListType == typeof(string);
|
||||
|
||||
// There should only be one child and it should be a group
|
||||
if (Entity.Children.SingleOrDefault() is DataModelConditionGroupEntity rootGroup)
|
||||
|
||||
@@ -70,18 +70,17 @@ namespace Artemis.Core
|
||||
/// Updates the left side of the predicate
|
||||
/// </summary>
|
||||
/// <param name="path">The path pointing to the left side value inside the list</param>
|
||||
public void UpdateLeftSide(string path)
|
||||
public void UpdateLeftSide(string? path)
|
||||
{
|
||||
if (DataModelConditionList.IsPrimitiveList)
|
||||
throw new ArtemisCoreException("Cannot apply a left side to a predicate inside a primitive list");
|
||||
if (!ListContainsInnerPath(path))
|
||||
throw new ArtemisCoreException($"List type {DataModelConditionList.ListType.Name} does not contain path {path}");
|
||||
|
||||
LeftPath?.Dispose();
|
||||
LeftPath = DataModelConditionList.ListType != null
|
||||
? new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), path)
|
||||
: null;
|
||||
|
||||
if (path != null && DataModelConditionList.ListType != null)
|
||||
LeftPath = new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), path);
|
||||
else
|
||||
LeftPath = null;
|
||||
|
||||
ValidateOperator();
|
||||
ValidateRightSide();
|
||||
}
|
||||
@@ -91,16 +90,15 @@ namespace Artemis.Core
|
||||
/// and re-compiles the expression
|
||||
/// </summary>
|
||||
/// <param name="path">The path pointing to the right side value inside the list</param>
|
||||
public void UpdateRightSideDynamic(string path)
|
||||
public void UpdateRightSideDynamic(string? path)
|
||||
{
|
||||
if (!ListContainsInnerPath(path))
|
||||
throw new ArtemisCoreException($"List type {DataModelConditionList.ListType.Name} does not contain path {path}");
|
||||
RightPath?.Dispose();
|
||||
if (path != null && DataModelConditionList.ListType != null)
|
||||
RightPath = new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), path);
|
||||
else
|
||||
RightPath = null;
|
||||
|
||||
PredicateType = ListRightSideType.DynamicList;
|
||||
RightPath?.Dispose();
|
||||
RightPath = DataModelConditionList.ListType != null
|
||||
? new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), path)
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -109,20 +107,27 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
/// <param name="dataModel"></param>
|
||||
/// <param name="path">The path pointing to the right side value inside the list</param>
|
||||
public void UpdateRightSideDynamic(DataModel dataModel, string path)
|
||||
public void UpdateRightSideDynamic(DataModel? dataModel, string? path)
|
||||
{
|
||||
if (dataModel != null && path == null)
|
||||
throw new ArtemisCoreException("If a data model is provided, a path is also required");
|
||||
if (dataModel == null && path != null)
|
||||
throw new ArtemisCoreException("If path is provided, a data model is also required");
|
||||
|
||||
RightPath?.Dispose();
|
||||
if (dataModel != null)
|
||||
if (!dataModel.ContainsPath(path))
|
||||
throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a property at path '{path}'");
|
||||
{
|
||||
DataModelPath newPath = new DataModelPath(dataModel, path);
|
||||
if (!newPath.IsValid)
|
||||
throw new ArtemisCoreException($"New right path '{newPath}' is invalid");
|
||||
RightPath = newPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
RightPath = null;
|
||||
}
|
||||
|
||||
PredicateType = ListRightSideType.Dynamic;
|
||||
RightPath?.Dispose();
|
||||
RightPath = new DataModelPath(dataModel, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Artemis.Core
|
||||
throw new ArtemisCoreException("If path is provided, a data model is also required");
|
||||
|
||||
LeftPath?.Dispose();
|
||||
if (dataModel != null && path != null)
|
||||
if (dataModel != null)
|
||||
{
|
||||
DataModelPath newPath = new DataModelPath(dataModel, path);
|
||||
if (!newPath.IsValid)
|
||||
@@ -105,7 +105,7 @@ namespace Artemis.Core
|
||||
throw new ArtemisCoreException("If path is provided, a data model is also required");
|
||||
|
||||
RightPath?.Dispose();
|
||||
if (dataModel != null && path != null)
|
||||
if (dataModel != null)
|
||||
{
|
||||
DataModelPath newPath = new DataModelPath(dataModel, path);
|
||||
if (!newPath.IsValid)
|
||||
|
||||
@@ -10,6 +10,12 @@ namespace Artemis.Core
|
||||
|
||||
public abstract class ListPredicateWrapperDataModel : DataModel
|
||||
{
|
||||
internal ListPredicateWrapperDataModel()
|
||||
{
|
||||
PluginInfo = Constants.CorePluginInfo;
|
||||
}
|
||||
|
||||
[DataModelIgnore]
|
||||
public object? UntypedValue { get; set; }
|
||||
|
||||
public static ListPredicateWrapperDataModel Create(Type type)
|
||||
|
||||
Reference in new issue
Block a user