Skip to content

Commit

Permalink
Adding landing page (#104)
Browse files Browse the repository at this point in the history
* Created temp home page

* updated is Preview to true for home page

* Preview mode bug fixes for home page

---------

Co-authored-by: Tom Whittington <[email protected]>
  • Loading branch information
simonjfirth and Tom Whittington authored Jun 27, 2024
1 parent 2a3b497 commit 75e2ebd
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 9 deletions.
22 changes: 20 additions & 2 deletions src/Dfe.ContentSupport.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@ namespace Dfe.ContentSupport.Web.Controllers;
public class HomeController(IContentService contentService)
: Controller
{

public async Task<IActionResult> Home()
{
var defaultModel = new ContentSupportPage
{
Heading = new Models.Heading
{
Title = "Department for Education",
Subtitle = "Content and Support",
}
};
var resp = await contentService.GetContentSupportPages(nameof(ContentSupportPage.IsSitemap), "true", true);
ViewBag.pages = resp;

return View(defaultModel);
}

[HttpGet("{slug}")]
public async Task<IActionResult> Index(string slug, bool isPreview = false)
{
if (string.IsNullOrEmpty(slug)) return RedirectToAction("error");

var resp = await contentService.GetContent(slug, isPreview);
if(resp is null) return RedirectToAction("error");
if (resp is null) return RedirectToAction("error");
return View(resp);
}

Expand All @@ -26,6 +44,6 @@ public IActionResult Privacy()
public IActionResult Error()
{
return View(new ErrorViewModel
{ RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
{ RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
4 changes: 2 additions & 2 deletions src/Dfe.ContentSupport.Web/Http/HttpContentfulClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace Dfe.ContentSupport.Web.Http;
public class HttpContentfulClient(HttpClient httpClient, CsContentfulOptions options)
: ContentfulClient(httpClient, options), IHttpContentfulClient
{
public Task<ContentfulCollection<T>> Query<T>(QueryBuilder<T> queryBuilder,
public async Task<ContentfulCollection<T>> Query<T>(QueryBuilder<T> queryBuilder,
CancellationToken cancellationToken = default)
{
queryBuilder = queryBuilder.Include(options.IncludeDepth);
return GetEntries(queryBuilder, cancellationToken);
return await GetEntries(queryBuilder, cancellationToken);
}
}
12 changes: 8 additions & 4 deletions src/Dfe.ContentSupport.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ public static void Main(string[] args)
);

app.MapControllerRoute(
"default/{slug}",
"{slug?}",
new { controller = "Home", action = "Index" }
);
name: "home",
pattern: "{controller=Home}/{action=Home}");

app.MapControllerRoute(
name: "slug",
pattern: "{slug}",
defaults: new { controller = "Home", action = "Index" });


app.Run();
}
Expand Down
3 changes: 2 additions & 1 deletion src/Dfe.ContentSupport.Web/Services/ContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ from url in resp
return sitemap.ToString();
}

private async Task<ContentfulCollection<ContentSupportPage>> GetContentSupportPages(
public async Task<ContentfulCollection<ContentSupportPage>> GetContentSupportPages(
string field, string value, bool isPreview)
{
var builder = QueryBuilder<ContentSupportPage>.New.ContentTypeIs(nameof(ContentSupportPage))
.FieldEquals($"fields.{field}", value);

return await contentfulService.ContentfulClient(isPreview).Query(builder);
}

}
3 changes: 3 additions & 0 deletions src/Dfe.ContentSupport.Web/Services/IContentService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Contentful.Core.Models;
using Dfe.ContentSupport.Web.ViewModels;

namespace Dfe.ContentSupport.Web.Services;
Expand All @@ -6,4 +7,6 @@ public interface IContentService
{
Task<ContentSupportPage?> GetContent(string slug, bool isPreview);
Task<string> GenerateSitemap(string baseUrl);

Task<ContentfulCollection<ContentSupportPage>> GetContentSupportPages(string field, string value, bool isPreview);
}
24 changes: 24 additions & 0 deletions src/Dfe.ContentSupport.Web/Views/Home/Home.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@model ContentSupportPage

<h1>@ViewData["Title"]</h1>


@{
if (ViewBag?.Pages?.Items != null)
{
<div class="dfe-grid-container">
@for (var i = 0; i < ViewBag.Pages.Items.Count; i++)
{
var url = ViewBag.Pages.Items[i].Slug + "?isPreview=true";
<div class="dfe-card">
<div class="dfe-card-container">
<h3 class="govuk-heading-m">
<a href="@url" class="govuk-link govuk-link--no-visited-state dfe-card-link--header">@ViewBag.Pages.Items[i].Heading.Title</a>
</h3>
<p>@ViewBag.Pages.Items[i].Heading.Subtitle</p>
</div>
</div>
}
</div>
}
}
1 change: 1 addition & 0 deletions src/Dfe.ContentSupport.Web/Views/Shared/_Header.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
</a>
</div>
</div>
</div>
</div>

0 comments on commit 75e2ebd

Please sign in to comment.