2020-05-19 15:53:01 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-09-02 11:52:33 +02:00
|
|
|
using System;
|
2020-05-19 15:53:01 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using zero.Core.Api;
|
2020-05-25 11:27:23 +02:00
|
|
|
using zero.Core.Entities;
|
2020-08-27 14:22:13 +02:00
|
|
|
using zero.Core.Extensions;
|
2020-08-20 14:35:08 +02:00
|
|
|
using zero.Web.Models;
|
2020-05-19 15:53:01 +02:00
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
2020-08-27 14:22:13 +02:00
|
|
|
public class PagesController : BackofficeController
|
2020-05-19 15:53:01 +02:00
|
|
|
{
|
2020-08-27 14:22:13 +02:00
|
|
|
IPagesApi Api;
|
2020-08-17 14:46:13 +02:00
|
|
|
IRevisionsApi RevisionsApi;
|
2020-05-19 15:53:01 +02:00
|
|
|
|
2020-09-02 11:52:33 +02:00
|
|
|
public PagesController(IPagesApi api, IRevisionsApi revisionsApi)
|
2020-05-19 15:53:01 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
2020-08-17 14:46:13 +02:00
|
|
|
RevisionsApi = revisionsApi;
|
2020-05-19 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-07-08 13:59:46 +02:00
|
|
|
public async Task<ActionResult> GetAllowedPageTypes([FromQuery] string parent = null) => Json(await Api.GetAllowedPageTypes(parent));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IActionResult GetPageType([FromQuery] string alias) => Json(Api.GetPageType(alias));
|
2020-05-25 11:27:23 +02:00
|
|
|
|
2020-08-20 14:35:08 +02:00
|
|
|
public async Task<IActionResult> GetById([FromQuery] string id)
|
|
|
|
|
{
|
2020-08-27 14:22:13 +02:00
|
|
|
IPage entity = await Api.GetById(id);
|
2020-08-20 14:35:08 +02:00
|
|
|
|
2020-08-27 14:22:13 +02:00
|
|
|
return Edit<IPage, PageEditModel<IPage>>(new PageEditModel<IPage>()
|
2020-08-20 14:35:08 +02:00
|
|
|
{
|
|
|
|
|
Entity = entity,
|
2020-08-28 14:26:26 +02:00
|
|
|
//Revisions = await RevisionsApi.GetPaged<IPage>(id),
|
2020-08-20 14:35:08 +02:00
|
|
|
PageType = Api.GetPageType(entity.PageTypeAlias)
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-08-27 14:22:13 +02:00
|
|
|
public IActionResult GetEmpty(string type, string parent = null)
|
2020-08-12 14:16:28 +02:00
|
|
|
{
|
2020-09-02 11:52:33 +02:00
|
|
|
PageType pageType = Api.GetPageType(type);
|
|
|
|
|
IPage model = Activator.CreateInstance(pageType.ContentType) as IPage;
|
2020-08-12 14:16:28 +02:00
|
|
|
|
2020-09-02 11:52:33 +02:00
|
|
|
model.PageTypeAlias = type;
|
|
|
|
|
model.ParentId = parent;
|
|
|
|
|
|
|
|
|
|
return Edit(model);
|
2020-08-27 14:22:13 +02:00
|
|
|
}
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-08-27 14:22:13 +02:00
|
|
|
public async Task<IActionResult> GetRevisions([FromQuery] string id, [FromQuery] int page = 1) => Json(await RevisionsApi.GetPaged<IPage>(id, page));
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> Save([FromBody] IPage model) => Json(await Api.Save(model));
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-08-13 14:58:01 +02:00
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> SaveSorting([FromBody] string[] ids) => Json(await Api.SaveSorting(ids));
|
|
|
|
|
|
2020-08-13 15:55:59 +02:00
|
|
|
[HttpPost]
|
2020-09-03 14:50:41 +02:00
|
|
|
public async Task<IActionResult> Move([FromBody] ActionCopyModel model) => Json(await Api.Move(model.Id, model.DestinationId));
|
2020-08-14 13:26:48 +02:00
|
|
|
|
|
|
|
|
[HttpPost]
|
2020-09-03 14:50:41 +02:00
|
|
|
public async Task<IActionResult> Copy([FromBody] ActionCopyModel model) => Json(await Api.Copy(model.Id, model.DestinationId, model.IncludeDescendants));
|
2020-08-13 15:55:59 +02:00
|
|
|
|
2020-08-27 11:41:40 +02:00
|
|
|
[HttpPost]
|
2020-09-03 14:50:41 +02:00
|
|
|
public async Task<IActionResult> Restore([FromBody] ActionCopyModel model) => Json(await Api.Restore(model.Id, model.IncludeDescendants));
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-08-26 11:10:52 +02:00
|
|
|
public async Task<IActionResult> Delete([FromQuery] string id) => Json(await Api.Delete(id, true));
|
2020-05-19 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
}
|