protected override async Task RenderContentAsync(TagHelperOutput output) { output.TagMode = TagMode.StartTagAndEndTag; if (Field.IsListValue) { var list = Field.GetModelValue(Content) as IList; if (Field.HasValue(list)) { for (var i = 0; i < list.Count; i++) { var itemContentContext = ContentContext.Navigate($"{FieldName.Name}[{i}]"); var itemHtml = await viewRenderService.RenderToStringAsync(itemContentContext); output.Content.AppendHtmlLine(itemHtml); } } } else { var value = Field.GetModelValue(Content); if (Field.HasValue(value)) { var itemContentContext = ContentContext.Navigate(FieldName.Name); var itemHtml = await viewRenderService.RenderToStringAsync(itemContentContext); output.Content.AppendHtmlLine(itemHtml); } } }
public async Task <IActionResult> ViewAsync([FromServices] IViewRenderService viewRenderService, [FromQuery] int itemIndex = -1) { var contentPath = Field.Name; if (Field.IsListValue) { if (itemIndex < 0) { return(BadRequest()); } contentPath += $"[{itemIndex}]"; } var contentContext = ContentContext.Navigate(contentPath); if (contentContext == null) { return(NotFound()); } var html = await viewRenderService.RenderToStringAsync(contentContext); return(new ContentResult { ContentType = "text/html", StatusCode = 200, Content = html }); }
async Task IAsyncActionFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { pageService = HttpContext.RequestServices.GetRequiredService <IPageService>(); pageEditingService = HttpContext.RequestServices.GetRequiredService <IPageContentService>(); if (!Request.Query.TryGetValue("editId", out Microsoft.Extensions.Primitives.StringValues editIdValue) || !Guid.TryParse(editIdValue[0], out Guid editId)) { context.Result = BadRequest(); return; } editSession = await pageEditingService.FindEditByIdAsync(editId, HttpContext.RequestAborted); if (editSession == null) { context.Result = BadRequest(); return; } page = await pageService.FindPageByIdAsync(editSession.PageId); if (page == null) { context.Result = BadRequest(); return; } var content = await pageEditingService.GetContentAsync(editSession, HttpContext.RequestAborted); rootContentContext = new ContentContext(page, content, HttpContext.RequestServices, true); string modelPath = string.Empty; if (Request.Query.TryGetValue("path", out Microsoft.Extensions.Primitives.StringValues pathValue)) { modelPath = pathValue[0]; } contentContext = rootContentContext.Navigate(modelPath); if (contentContext == null) { context.Result = BadRequest(); return; } if (!Request.Query.TryGetValue("field", out Microsoft.Extensions.Primitives.StringValues fieldNameValue)) { context.Result = BadRequest(); return; } string fieldName = fieldNameValue[0]; if (!contentContext.Explorer.Metadata.TryGetField(fieldName, out field)) { context.Result = BadRequest(); return; } await next(); }
public IActionResult GetData([FromQuery] int itemIndex = -1) { var contentPath = Field.Name; if (Field.IsListValue) { if (itemIndex < 0) { return(BadRequest()); } contentPath += $"[{itemIndex}]"; } var contentContext = ContentContext.Navigate(contentPath); if (contentContext == null) { return(NotFound()); } var contentExplorer = contentContext.Explorer; var result = new ContentItem { Title = contentExplorer.Title, Type = new ContentItemType { Name = contentExplorer.Metadata.Name, Title = contentExplorer.Metadata.Title } }; return(Ok(result)); }
public async Task <IActionResult> GetFormAsync([FromQuery] Guid editId, [FromQuery] string modelPath) { var editSession = await pageContentService.FindEditByIdAsync(editId); if (editSession == null) { return(BadRequest()); } var page = await pageService.FindPageByIdAsync(editSession.PageId); if (page == null) { return(BadRequest()); } if (modelPath == null) { modelPath = string.Empty; } var pageContent = await pageContentService.GetContentAsync(editSession); var pageContentContext = new ContentContext(page, pageContent, HttpContext.RequestServices, true); var contentContext = pageContentContext.Navigate(modelPath); if (contentContext == null) { return(BadRequest()); } var formModel = new Models.PageContentForm { Path = new Models.PageContentPath { Name = contentContext.Explorer.Metadata.Name, Title = contentContext.Explorer.Metadata.Title, Index = contentContext.Explorer.Index, ModelPath = contentContext.Explorer.ModelPath } }; var path = formModel.Path; var explorer = contentContext.Explorer.Parent; while (explorer != null) { path.Parent = new Models.PageContentPath { Name = explorer.Metadata.Name, Title = explorer.Metadata.Title, Index = explorer.Index, ModelPath = explorer.ModelPath }; explorer = explorer.Parent; path = path.Parent; } var fields = contentContext.Explorer.Metadata.Fields.ToList(); foreach (var field in fields) { formModel.Fields.Add(new Models.ContentFieldModel { Type = field.Type, Name = field.Name, Title = field.Title, Options = field.GetFormOptions(contentContext.Services) }); var modelValue = field.GetModelValue(contentContext.Content); var formValue = await field.GetFormValueAsync(modelValue, contentContext.Services); formModel.Values.Add(field.Name, formValue); } return(Ok(formModel)); }