start creating API for renderers
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
{
|
||||
public const string ErrorFieldNone = "__zero_no_field";
|
||||
|
||||
public static class Tabs
|
||||
{
|
||||
public const string General = "general";
|
||||
}
|
||||
|
||||
public static class Auth
|
||||
{
|
||||
public const string Scheme = "zeroCookies";
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using FluentValidation;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public abstract class AbstractRenderer<T> : IRenderer<T>
|
||||
{
|
||||
protected string LabelTemplate = null;
|
||||
|
||||
protected string DescriptionTemplate = null;
|
||||
|
||||
protected IValidator<T> Validator = null;
|
||||
|
||||
protected virtual IRendererFieldBuilder Field(ConstructorField field)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected virtual IRendererFieldBuilder Field(Expression<Func<T, object>> mapExpression, string label = null, string description = null, bool required = false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected virtual IRenderer<T> Tab(string name, Action builder)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected virtual IRenderer<T> Box(string name, string description, Action builder)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public class ConstructorField
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Alias { get; set; }
|
||||
|
||||
public ConstructorField(string alias, string name)
|
||||
{
|
||||
Alias = alias;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public class ConstructorTab
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Alias { get; set; }
|
||||
|
||||
public ConstructorTab(string alias, string name)
|
||||
{
|
||||
Alias = alias;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public interface IRenderer<T>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public interface IRendererFieldBuilder
|
||||
{
|
||||
IRendererFieldBuilder Required();
|
||||
|
||||
IRendererFieldBuilder Text();
|
||||
|
||||
IRendererFieldBuilder Textarea();
|
||||
|
||||
IRendererFieldBuilder Rte();
|
||||
|
||||
IRendererFieldBuilder IconPicker();
|
||||
|
||||
IRendererFieldBuilder Toggle();
|
||||
|
||||
IRendererFieldBuilder State(Action<StateOptions> optionsBuilder = null);
|
||||
|
||||
IRendererFieldBuilder Media(Action<MediaOptions> optionsBuilder = null);
|
||||
|
||||
IRendererFieldBuilder Custom(string path, Func<object> optionsBuilder = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public interface IRendererOptions
|
||||
{
|
||||
string ComponentPath { get; set; }
|
||||
|
||||
IList<ConstructorTab> Tabs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public class MediaOptions
|
||||
{
|
||||
public MediaOptionsType Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public enum MediaOptionsType
|
||||
{
|
||||
All,
|
||||
Image,
|
||||
Video
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace zero.Core.Renderer
|
||||
{
|
||||
public class StateOptions
|
||||
{
|
||||
public void Add(string label, object value) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using FluentValidation;
|
||||
using zero.Core.Renderer;
|
||||
|
||||
namespace zero.TestData.Lists
|
||||
{
|
||||
public class TeamMemberRenderer : AbstractRenderer<TeamMember>
|
||||
{
|
||||
public TeamMemberRenderer()
|
||||
{
|
||||
LabelTemplate = "@team.fields.{0}";
|
||||
DescriptionTemplate = "@team.fields.{0}_text";
|
||||
|
||||
Validator = new TeamMemberValidator();
|
||||
|
||||
Field(x => x.Name, required: true).Text();
|
||||
|
||||
Tab("@team.tab.extras", () =>
|
||||
{
|
||||
Field(x => x.Position, required: true).Text();
|
||||
Field(x => x.Image).Media(opts =>
|
||||
{
|
||||
opts.Type = MediaOptionsType.Image;
|
||||
});
|
||||
Field(x => x.Email, required: true).Text();
|
||||
Field(x => x.VideoUri).Text();
|
||||
});
|
||||
|
||||
Tab("@team.tab.permissions", () =>
|
||||
{
|
||||
Box("Acess to sections", null, () =>
|
||||
{
|
||||
Field(x => x.Alias).Toggle();
|
||||
Field(x => x.AppId).Toggle();
|
||||
Field(x => x.CreatedDate).State(opts =>
|
||||
{
|
||||
opts.Add("None", "none");
|
||||
opts.Add("View", "view");
|
||||
opts.Add("Edit", "edit");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class TeamMemberValidator : AbstractValidator<TeamMember>
|
||||
{
|
||||
public TeamMemberValidator()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,15 +58,6 @@
|
||||
{
|
||||
this.lists = response;
|
||||
});
|
||||
//this.tableConfig = {
|
||||
// labelPrefix: '@lists.fields.',
|
||||
// allowOrder: false,
|
||||
// search: null,
|
||||
// columns: {
|
||||
// name: 'text'
|
||||
// },
|
||||
// items: ListsApi.getCollections
|
||||
//};
|
||||
},
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user