edit, remove + toggle page modules
This commit is contained in:
@@ -57,17 +57,15 @@ namespace zero.Web.Controllers
|
||||
/// <summary>
|
||||
/// Creates an edit model with appropriate options and permissions
|
||||
/// </summary>
|
||||
public JsonResult Edit<T>(T data, bool typed = true, Action<dynamic> transform = null) where T : IZeroIdEntity
|
||||
public JsonResult Edit<T>(T data, bool typed = true, Action<EditModel<T>> transform = null) where T : IZeroIdEntity
|
||||
{
|
||||
Type type = typeof(T);
|
||||
bool canBeShared = AppAwareShareableType.IsAssignableFrom(type);
|
||||
|
||||
//ControllerContext.ActionDescriptor.FilterDescriptors[0].
|
||||
|
||||
dynamic model = new ExpandoObject();
|
||||
EditModel<T> model = new EditModel<T>();
|
||||
model.Entity = data;
|
||||
|
||||
model.Meta = new ExpandoObject();
|
||||
model.Meta.Token = Token.Get(data);
|
||||
model.Meta.IsAppAware = AppAwareType.IsAssignableFrom(type);
|
||||
model.Meta.CanBeShared = canBeShared;
|
||||
@@ -82,6 +80,32 @@ namespace zero.Web.Controllers
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates an edit model with appropriate options and permissions
|
||||
/// </summary>
|
||||
public JsonResult Edit<T, TWrapper>(TWrapper data, bool typed = true, Action<EditModel<T>> transform = null)
|
||||
where T : IZeroIdEntity
|
||||
where TWrapper : EditModel<T>, new()
|
||||
{
|
||||
Type type = typeof(T);
|
||||
bool canBeShared = AppAwareShareableType.IsAssignableFrom(type);
|
||||
|
||||
//ControllerContext.ActionDescriptor.FilterDescriptors[0].
|
||||
|
||||
data.Meta.Token = Token.Get(data.Entity);
|
||||
data.Meta.IsAppAware = AppAwareType.IsAssignableFrom(type);
|
||||
data.Meta.CanBeShared = canBeShared;
|
||||
data.Meta.CanCreate = true;
|
||||
data.Meta.CanCreateShared = canBeShared;
|
||||
data.Meta.CanEdit = true;
|
||||
data.Meta.CanDelete = true;
|
||||
|
||||
transform?.Invoke(data);
|
||||
|
||||
return Json(data, typed);
|
||||
}
|
||||
|
||||
|
||||
public IActionResult JsonPreviews<T>(Dictionary<string, T> items, Func<T, PreviewModel> transform)
|
||||
{
|
||||
IList<PreviewModel> previews = new List<PreviewModel>();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using zero.Core.Api;
|
||||
using zero.Core.Entities;
|
||||
using zero.Web.Models;
|
||||
|
||||
namespace zero.Web.Controllers
|
||||
{
|
||||
@@ -22,7 +23,17 @@ namespace zero.Web.Controllers
|
||||
|
||||
public IActionResult GetPageType([FromQuery] string alias) => Json(Api.GetPageType(alias));
|
||||
|
||||
public async Task<IActionResult> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
|
||||
public async Task<IActionResult> GetById([FromQuery] string id)
|
||||
{
|
||||
T entity = await Api.GetById(id);
|
||||
|
||||
return Edit<T, PageEditModel<T>>(new PageEditModel<T>()
|
||||
{
|
||||
Entity = entity,
|
||||
Revisions = await RevisionsApi.GetPaged<T>(id),
|
||||
PageType = Api.GetPageType(entity.PageTypeAlias)
|
||||
});
|
||||
}
|
||||
|
||||
public IActionResult GetEmpty(string type, string parent = null) => Edit(new T()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user