vue plugin system somehow works

This commit is contained in:
2021-12-29 01:25:35 +01:00
parent 1954659a82
commit ee20eb16e1
30 changed files with 136 additions and 51 deletions
@@ -10,5 +10,6 @@ public class CommunicationModule : ZeroModule
services.AddScoped<IInterceptors, Interceptors>();
services.AddSingleton<IMessageAggregator, MessageAggregator>();
services.AddTransient<IHandlerHolder, HandlerHolder>();
services.AddTransient(typeof(Lazy<>), typeof(LazilyResolved<>));
}
}
@@ -16,7 +16,7 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
protected IZeroContext Context { get; private set; }
protected IEnumerable<IInterceptor> Interceptors { get; private set; }
protected Lazy<IEnumerable<IInterceptor>> Interceptors { get; private set; }
protected Dictionary<IInterceptor, InterceptorParameters> InterceptorCache { get; private set; } = new();
@@ -27,7 +27,7 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
protected Func<IInterceptor, bool> InterceptorFilter { get; private set; } = x => true;
internal InterceptorInstruction(IInterceptors interceptors, IZeroContext context, IEnumerable<IInterceptor> registrations, ILogger<IInterceptor> logger, InterceptorRunType runtype, T model)
internal InterceptorInstruction(IInterceptors interceptors, IZeroContext context, Lazy<IEnumerable<IInterceptor>> registrations, ILogger<IInterceptor> logger, InterceptorRunType runtype, T model)
{
InterceptorHandler = interceptors;
Context = context;
@@ -37,7 +37,6 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
Model = model;
ModelType = model.GetType();
Interceptors = registrations.OrderByDescending(x => x.Gravity);
}
@@ -115,7 +114,7 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
protected IEnumerable<IInterceptor> GetInterceptors()
{
return Interceptors.Where(InterceptorFilter).OrderByDescending(x => x.Gravity);
return Interceptors.Value.Where(InterceptorFilter).OrderByDescending(x => x.Gravity);
}
@@ -6,12 +6,12 @@ public class Interceptors : IInterceptors
{
protected IZeroContext Context { get; set; }
protected IEnumerable<IInterceptor> Registrations { get; set; }
protected Lazy<IEnumerable<IInterceptor>> Registrations { get; set; }
protected ILogger<IInterceptor> Logger { get; set; }
public Interceptors(IZeroContext context, IEnumerable<IInterceptor> registrations, ILogger<IInterceptor> logger)
public Interceptors(IZeroContext context, Lazy<IEnumerable<IInterceptor>> registrations, ILogger<IInterceptor> logger)
{
Context = context;
Registrations = registrations;
+11
View File
@@ -0,0 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
namespace zero.Communication;
public class LazilyResolved<T> : Lazy<T>
{
public LazilyResolved(IServiceProvider serviceProvider): base(serviceProvider.GetRequiredService<T>)
{
}
}
+1 -4
View File
@@ -4,10 +4,7 @@ namespace zero.Media;
public class MediaStore : TreeEntityStore<Media>, IMediaStore
{
public MediaStore(IStoreContext context) : base(context)
{
Config.IncludeInactive = true;
}
public MediaStore(IStoreContext context) : base(context) { }
/// <summary>
/// A media (either file or folder) can only be saved for the following circumstances:
+1 -1
View File
@@ -4,7 +4,7 @@
/// A media file (can contain an image or other media like videos and documents)
/// </summary>
[RavenCollection("Media")]
public class Media : ZeroEntity, ISupportsTrees
public class Media : ZeroEntity, ISupportsTrees, IAlwaysActive
{
public Media()
{
+12
View File
@@ -0,0 +1,12 @@
namespace zero.Models;
/// <summary>
/// Entities decorated with this interface are always set to IsActive=true
/// </summary>
public interface IAlwaysActive
{
/// <summary>
/// Whether the entity is visible in the frontend
/// </summary>
bool IsActive { get; set; }
}
+2
View File
@@ -9,6 +9,8 @@ public class Paged<T> : Paged
Items = items;
}
public Paged(long totalItems, long pageNumber, long pageSize) : base(totalItems, pageNumber, pageSize) { }
public Paged<TTarget> MapTo<TTarget>(Func<T, TTarget> convertItem)
{
return new Paged<TTarget>(Items.Select(x => convertItem(x)).Where(x => x != null).ToList(), TotalItems, Page, PageSize);
+7 -4
View File
@@ -72,10 +72,8 @@ public partial class StoreOperations :
// set IDs
AutoSetIds(model);
if (model is ZeroEntity)
if (model is ZeroEntity zeroModel)
{
ZeroEntity zeroModel = model as ZeroEntity;
// get current user
string userId = Context.BackofficeUser.FindFirstValue(Constants.Auth.Claims.UserId);
@@ -101,6 +99,11 @@ public partial class StoreOperations :
zeroModel.Hash ??= IdGenerator.Create();
}
if (model is IAlwaysActive activeModel)
{
activeModel.IsActive = true;
}
return model;
}
@@ -110,7 +113,7 @@ public partial class StoreOperations :
/// </summary>
protected virtual T WhenActive<T>(T model) where T : ZeroIdEntity, new()
{
return model != null && (Config.IncludeInactive || model is not ZeroEntity || (model as ZeroEntity).IsActive) ? model : default;
return model != null && (Config.IncludeInactive || model is IAlwaysActive || model is not ZeroEntity || (model as ZeroEntity).IsActive) ? model : default;
}
}