diff --git a/website/MyWebApp/Controllers/AdminContentController.cs b/website/MyWebApp/Controllers/AdminContentController.cs index 094c672..8c6b058 100644 --- a/website/MyWebApp/Controllers/AdminContentController.cs +++ b/website/MyWebApp/Controllers/AdminContentController.cs @@ -17,12 +17,14 @@ public class AdminContentController : Controller private readonly ApplicationDbContext _db; private readonly LayoutService _layout; private readonly ContentProcessingService _content; + private readonly TokenRenderService _tokens; - public AdminContentController(ApplicationDbContext db, LayoutService layout, ContentProcessingService content) + public AdminContentController(ApplicationDbContext db, LayoutService layout, ContentProcessingService content, TokenRenderService tokens) { _db = db; _layout = layout; _content = content; + _tokens = tokens; } private async Task LoadTemplatesAsync() @@ -99,6 +101,21 @@ public async Task Create(Page model) return RedirectToAction(nameof(Index)); } + [HttpPost] + public async Task Preview([FromBody] PreviewRequest model) + { + var zones = new Dictionary(); + foreach (var kv in model.Zones ?? new Dictionary()) + { + zones[kv.Key] = await _tokens.RenderAsync(_db, kv.Value ?? string.Empty); + } + ViewBag.HeaderHtml = await _layout.GetHeaderAsync(_db); + ViewBag.FooterHtml = await _layout.GetFooterAsync(_db); + ViewBag.PageLayout = string.IsNullOrWhiteSpace(model.Layout) ? "single-column" : model.Layout; + ViewBag.ZoneHtml = zones; + return View("~/Views/Pages/Show.cshtml", new Page { Title = model.Title }); + } + public async Task Edit(int id) { var page = await _db.Pages.FindAsync(id); diff --git a/website/MyWebApp/Models/PreviewRequest.cs b/website/MyWebApp/Models/PreviewRequest.cs new file mode 100644 index 0000000..d918565 --- /dev/null +++ b/website/MyWebApp/Models/PreviewRequest.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace MyWebApp.Models; + +public class PreviewRequest +{ + public string Layout { get; set; } = "single-column"; + public string Title { get; set; } = string.Empty; + public Dictionary Zones { get; set; } = new(); +} + diff --git a/website/MyWebApp/Views/AdminContent/PageEditor.cshtml b/website/MyWebApp/Views/AdminContent/PageEditor.cshtml index 1a50ac9..bd8c89b 100644 --- a/website/MyWebApp/Views/AdminContent/PageEditor.cshtml +++ b/website/MyWebApp/Views/AdminContent/PageEditor.cshtml @@ -8,6 +8,15 @@ ViewData["Title"] = isNew ? "Create Page" : "Edit Page"; }

@ViewData["Title"]

+
+ + +
+ + + +
+
+
+
+ +
+
@section Scripts {