|
|
@@ -12,6 +12,8 @@ namespace InABox.Core
|
|
|
public abstract Entity NewEntity(DigitalForm form);
|
|
|
|
|
|
public abstract void OnSave(IDigitalFormInstance form, Entity entity);
|
|
|
+
|
|
|
+ public abstract IColumns? RequiredEntityColumns();
|
|
|
}
|
|
|
|
|
|
public abstract class EntityFormUtils<TForm, TEntity, TEntityLink> : IEntityFormUtils
|
|
|
@@ -23,11 +25,15 @@ namespace InABox.Core
|
|
|
public abstract TEntity NewEntity(DigitalForm form);
|
|
|
public abstract void OnSave(TForm form, TEntity entity);
|
|
|
|
|
|
+ public abstract Columns<TEntity>? RequiredEntityColumns();
|
|
|
+
|
|
|
void IEntityFormUtils.OnSave(IDigitalFormInstance form, Entity entity) => OnSave((TForm)form, (TEntity)entity);
|
|
|
|
|
|
bool IEntityFormUtils.CanEditForm(IDigitalFormInstance form, Entity entity) => CanEditForm((form as TForm)!, (entity as TEntity)!);
|
|
|
|
|
|
Entity IEntityFormUtils.NewEntity(DigitalForm form) => NewEntity(form);
|
|
|
+
|
|
|
+ IColumns? IEntityFormUtils.RequiredEntityColumns() => RequiredEntityColumns();
|
|
|
}
|
|
|
|
|
|
public class DelegateEntityFormUtils<TForm, TEntity, TEntityLink> : EntityFormUtils<TForm, TEntity, TEntityLink>
|
|
|
@@ -38,16 +44,19 @@ namespace InABox.Core
|
|
|
public delegate bool CanEditEvent(TForm form, TEntity entity);
|
|
|
public delegate TEntity NewEntityEvent(DigitalForm form);
|
|
|
public delegate void OnSaveEvent(TForm form, TEntity entity);
|
|
|
+ public delegate Columns<TEntity> RequiredColumnsEvent();
|
|
|
|
|
|
public CanEditEvent OnCanEdit;
|
|
|
public NewEntityEvent? OnNewEntity;
|
|
|
public OnSaveEvent? SaveEvent;
|
|
|
+ public RequiredColumnsEvent? RequiredColumns;
|
|
|
|
|
|
- public DelegateEntityFormUtils(CanEditEvent canEditForm, NewEntityEvent? onNewEntity = null, OnSaveEvent? onSave = null)
|
|
|
+ public DelegateEntityFormUtils(CanEditEvent canEditForm, NewEntityEvent? onNewEntity = null, OnSaveEvent? onSave = null, RequiredColumnsEvent? requiredColumns = null)
|
|
|
{
|
|
|
OnCanEdit = canEditForm;
|
|
|
OnNewEntity = onNewEntity;
|
|
|
SaveEvent = onSave;
|
|
|
+ RequiredColumns = requiredColumns;
|
|
|
}
|
|
|
|
|
|
public override bool CanEditForm(TForm form, TEntity entity) => OnCanEdit(form, entity);
|
|
|
@@ -55,7 +64,8 @@ namespace InABox.Core
|
|
|
public override TEntity NewEntity(DigitalForm form) => OnNewEntity?.Invoke(form) ?? new TEntity();
|
|
|
|
|
|
public override void OnSave(TForm form, TEntity entity) => SaveEvent?.Invoke(form, entity);
|
|
|
-
|
|
|
+
|
|
|
+ public override Columns<TEntity>? RequiredEntityColumns() => RequiredColumns?.Invoke();
|
|
|
}
|
|
|
|
|
|
public static class DFUtils
|
|
|
@@ -151,12 +161,13 @@ namespace InABox.Core
|
|
|
public static void AddFormUtils<TForm, TEntity, TEntityLink>(
|
|
|
DelegateEntityFormUtils<TForm, TEntity, TEntityLink>.CanEditEvent editFormFunc,
|
|
|
DelegateEntityFormUtils<TForm, TEntity, TEntityLink>.NewEntityEvent? newEntityFunc = null,
|
|
|
- DelegateEntityFormUtils<TForm, TEntity, TEntityLink>.OnSaveEvent? beforeSaveFunc = null)
|
|
|
+ DelegateEntityFormUtils<TForm, TEntity, TEntityLink>.OnSaveEvent? beforeSaveFunc = null,
|
|
|
+ DelegateEntityFormUtils<TForm, TEntity, TEntityLink>.RequiredColumnsEvent? requiredColumnsFunc = null)
|
|
|
where TForm : BaseEntityForm<TEntity, TEntityLink, TForm>
|
|
|
where TEntity : Entity, new()
|
|
|
where TEntityLink : EntityLink<TEntity>, new()
|
|
|
{
|
|
|
- _formUtils.Add(typeof(TForm), new DelegateEntityFormUtils<TForm, TEntity, TEntityLink>(editFormFunc, newEntityFunc, beforeSaveFunc));
|
|
|
+ _formUtils.Add(typeof(TForm), new DelegateEntityFormUtils<TForm, TEntity, TEntityLink>(editFormFunc, newEntityFunc, beforeSaveFunc, requiredColumnsFunc));
|
|
|
}
|
|
|
|
|
|
public static void AddFormUtils<TForm, TEntity, TEntityLink>(EntityFormUtils<TForm, TEntity, TEntityLink> formUtils)
|
|
|
@@ -217,6 +228,23 @@ namespace InABox.Core
|
|
|
OnSave(typeof(TForm), form, entity);
|
|
|
}
|
|
|
|
|
|
+ public static IColumns? RequiredEntityColumns(Type TForm)
|
|
|
+ {
|
|
|
+ if(_formUtils.TryGetValue(TForm, out var utils))
|
|
|
+ {
|
|
|
+ return utils.RequiredEntityColumns();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Columns<TEntity>? RequiredEntityColumns<TForm, TEntity, TEntityLink>()
|
|
|
+ where TForm : BaseEntityForm<TEntity, TEntityLink, TForm>
|
|
|
+ where TEntity : Entity, new()
|
|
|
+ where TEntityLink : EntityLink<TEntity>, new()
|
|
|
+ {
|
|
|
+ return RequiredEntityColumns(typeof(TForm)) as Columns<TEntity>;
|
|
|
+ }
|
|
|
+
|
|
|
public static Type? FormEntityType(DigitalForm form)
|
|
|
{
|
|
|
return FormEntityType(form.AppliesTo);
|
|
|
@@ -248,7 +276,7 @@ namespace InABox.Core
|
|
|
: null;
|
|
|
}*/
|
|
|
|
|
|
- public static IColumns RequiredEntityColumns(Type TEntity, IEnumerable<DigitalFormVariable> variables)
|
|
|
+ public static IColumns RequiredEntityColumns(Type TForm, Type TEntity, IEnumerable<DigitalFormVariable> variables)
|
|
|
{
|
|
|
var entityColumns = LookupFactory.RequiredColumns(TEntity);
|
|
|
foreach(var variable in variables)
|
|
|
@@ -259,9 +287,20 @@ namespace InABox.Core
|
|
|
entityColumns.Add(property);
|
|
|
}
|
|
|
}
|
|
|
+ var others = RequiredEntityColumns(TForm);
|
|
|
+ if(others != null)
|
|
|
+ {
|
|
|
+ foreach(var column in others)
|
|
|
+ {
|
|
|
+ entityColumns.Add(column);
|
|
|
+ }
|
|
|
+ }
|
|
|
return entityColumns;
|
|
|
}
|
|
|
- public static Columns<TEntity> EntityColumns<TEntity>(IEnumerable<DigitalFormVariable> variables) =>
|
|
|
- (RequiredEntityColumns(typeof(TEntity), variables) as Columns<TEntity>)!;
|
|
|
+ public static Columns<TEntity> EntityColumns<TForm, TEntity, TEntityLink>(IEnumerable<DigitalFormVariable> variables)
|
|
|
+ where TForm : IDigitalFormInstance<TEntityLink>
|
|
|
+ where TEntity : Entity, new()
|
|
|
+ where TEntityLink : EntityLink<TEntity>
|
|
|
+ => (RequiredEntityColumns(typeof(TForm), typeof(TEntity), variables) as Columns<TEntity>)!;
|
|
|
}
|
|
|
}
|