2020-05-19 15:53:01 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
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-08-27 14:22:13 +02:00
|
|
|
IPage Blueprint;
|
2020-05-19 15:53:01 +02:00
|
|
|
|
2020-08-27 14:22:13 +02:00
|
|
|
public PagesController(IPagesApi api, IRevisionsApi revisionsApi, IPage blueprint)
|
2020-05-19 15:53:01 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
2020-08-17 14:46:13 +02:00
|
|
|
RevisionsApi = revisionsApi;
|
2020-08-27 14:22:13 +02:00
|
|
|
Blueprint = blueprint;
|
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-27 14:22:13 +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-08-27 16:12:47 +02:00
|
|
|
// TODO this will return an instance of Page, but the subclass with type=$type is needed
|
2020-08-27 14:22:13 +02:00
|
|
|
IPage entity = Blueprint.Clone();
|
|
|
|
|
entity.PageTypeAlias = type;
|
|
|
|
|
entity.ParentId = parent;
|
2020-08-12 14:16:28 +02:00
|
|
|
|
2020-08-27 14:22:13 +02:00
|
|
|
return Edit(entity);
|
|
|
|
|
}
|
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-08-14 13:26:48 +02:00
|
|
|
public async Task<IActionResult> Move([FromBody] CopyModel model) => Json(await Api.Move(model.Id, model.DestinationId));
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Copy([FromBody] CopyModel 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]
|
|
|
|
|
public async Task<IActionResult> Restore([FromBody] CopyModel 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-08-14 13:26:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public class CopyModel
|
|
|
|
|
{
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
public string DestinationId { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IncludeDescendants { get; set; }
|
|
|
|
|
}
|
2020-05-19 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
}
|