Skip to content

Commit

Permalink
Category and Landing
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish committed Dec 2, 2024
1 parent 6695fc1 commit 19168da
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 117 deletions.
4 changes: 4 additions & 0 deletions src/Page/RecipeCategoryPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function getCMSFields(): FieldList
->setTitle(_t(__CLASS__ . '.RecipesPerPage', 'Recipes Per Page')),
'Content'
);

$fields->dataFieldByName('Content')
->setTitle('Summary')
->setRows(5);
});

$fields = parent::getCMSFields();
Expand Down
4 changes: 4 additions & 0 deletions src/Page/RecipeLanding.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class RecipeLanding extends \Page
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->dataFieldByName('Content')
->setTitle('Summary')
->setRows(5);

if ($this->ID) {
$config = GridFieldConfig_RelationEditor::create()
->addComponent(new GridFieldOrderableRows('SortOrder'))
Expand Down
10 changes: 10 additions & 0 deletions src/Page/RecipePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ class RecipePage extends \Page
'Image',
];

/**
* @var array
* @config
*/
private static $cascade_duplicates = [
'Image',
'Ingredients',
'Directions',
];

/**
* @var array
*/
Expand Down
125 changes: 57 additions & 68 deletions templates/Dynamic/RecipeBook/Page/Layout/RecipeCategoryPage.ss
Original file line number Diff line number Diff line change
@@ -1,83 +1,72 @@
<div class="container mt-4">
<div class="row">
<% loop $paginatedList %>
<div class="card col-md-4">
<div class="recipe-img-holder">
<a href="$Link" title="Go to the $Title.XML page">
<% if $Image %>
<img src="$Image.URL" alt="$Image.Title" class="img-fluid recipe-img" />
<% else %>
<img src="_resources/themes/cheesesociety/images/recipe-default.jpg" class="img-fluid recipe-img">
<% end_if %>
<% if $Servings || $PrepTime || $CookTime || $Difficulty %>
<div class="recipe-overlay">
<div class="inner">
<div class="container">
<!-- Category Title -->
<div class="row mb-4">
<div class="col-12">
<h1 class="mb-3">$Title</h1>
<% if $Content %>
<p class="lead">$Content</p>
<% end_if %>
</div>
</div>

<!-- Recipes List -->
<% if $RecipeList.Sort('Title') %>
<div class="row">
<% loop $RecipeList.Sort('Title') %>
<div class="col-md-4 mb-4">
<div class="card h-100">
<a href="$Link" class="text-decoration-none">
<% if $Image %>
<img src="$Image.URL" class="card-img-top" alt="$Image.Title">
<% else %>
<img src="https://via.placeholder.com/150" class="card-img-top" alt="No Image">
<% end_if %>
</a>
<div class="card-body">
<% if $PrimaryCategory %>
<p class="text-uppercase text-muted small mb-1">$PrimaryCategory.Title</p>
<% end_if %>
<h5 class="card-title">
<a href="$Link" class="text-decoration-none">$Title</a>
</h5>
<div class="d-flex align-items-center text-muted">
<% if $PrepTime %>
<div class="pb-1">
<i class="far fa-clock p-1"></i>
Prep Time: $PrepTime
<div class="me-4">
<i class="bi bi-alarm"></i> Prep: $PrepTime
</div>
<% end_if %>
<% if $CookTime %>
<div class="pb-1">
<i class="far fa-clock p-1"></i>
Cook Time: $CookTime
<div class="me-4">
<i class="bi bi-clock"></i> Cook: $CookTime
</div>
<% end_if %>
<% if $Servings %>
<div class="pb-1">
<i class="fas fa-utensils p-1"></i>
Servings: $Servings
</div>
<% end_if %>
<% if $Difficulty %>
<div class="pb-1">
<i class="fas fa-tachometer-alt p-1"></i>
Difficulty: $Difficulty
<div>
<i class="bi bi-people"></i> Servings: $Servings
</div>
<% end_if %>
</div>
<% if $Summary %>
<p class="card-text mt-2">$Summary.LimitCharacters(100)</p>
<% end_if %>
</div>
<% end_if %>
</a>
</div>
<div class="card-body">
<h4 class="recipe-title text-center">$Title</h4>
</div>
<div class="card-body text-center pt-0">
<a href="$Link" class="btn recipe-link btn-primary">View Recipe</a>
<div class="card-footer">
<a href="$Link" class="btn btn-primary btn-block">View Recipe</a>
</div>
</div>
</div>
<% end_loop %>
</div>
<% else %>
<div class="row">
<div class="col-12">
<p>No recipes found in this category.</p>
</div>
</div>
<% end_loop %>
</div>
<% end_if %>
</div>

<% if $paginatedList.MoreThanOnePage %>
<nav aria-label="Recipe Category Navigation">
<ul class="pagination justify-content-center">
<% if $paginatedList.NotFirstPage %>
<li class="page-item disabled">
<a class="page-link" href="$paginatedList.PrevLink" tabindex="-1">Previous</a>
</li>
<% end_if %>
<% loop $paginatedList.PaginationSummary %>
<% if $CurrentBool %>
<li class="page-item active">
<span class="page-link">$PageNum<span class="sr-only">(current)</span></span>
</li>
<% else %>
<% if $Link %>
<li class="page-item"><a class="page-link" href="$Link">$PageNum</a></li>
<% else %>
...
<% end_if %>
<% end_if %>
<% end_loop %>
<% if $paginatedList.NotLastPage %>
<li class="page-item">
<a class="page-link" href="$paginatedList.NextLink">Next</a>
</li>
<% end_if %>
</ul>
</nav>
<% end_if %>
<!-- Elemental Area -->
<div>
$ElementalArea
</div>
111 changes: 68 additions & 43 deletions templates/Dynamic/RecipeBook/Page/Layout/RecipeLanding.ss
Original file line number Diff line number Diff line change
@@ -1,50 +1,75 @@
<div class="container mt-4">
<div class="row">
<% loop $paginatedList %>
<div class="card col-md-4">
<% if $CategoryImage %>
<img src="$CategoryImage.URL" class="img-fluid" />
<% else %>
<img src="_resources/themes/cheesesociety/images/recipe-default.jpg" class="img-fluid">
<% base_tag %>
<div class="container">
<!-- Page Title and Content -->
<div class="row mb-4">
<div class="col-12">
<h1 class="mb-3">$Title</h1>
<% if $Content %>
<p class="lead">$Content</p>
<% end_if %>
<div class="card-body apply-font">
<h3 class="text-center recipe-title">$Title</h3>
<% if $Content %><p class="card-text">$Content</p><% end_if %>
</div>
</div>

<!-- Top-Level Recipe Categories -->
<% loop $Children %>
<div class="row mb-5">
<!-- Category Title -->
<div class="col-12">
<h2 class="mb-4">$Title</h2>
</div>
<div class="card-body text-center pt-0">
<a href="$Link" class="btn recipe-link btn-primary">View All</a>

<!-- Recipes in Category -->
<% loop $RecipeList.Limit(3).Sort('Title') %>
<div class="col-md-4 mb-4">
<div class="card h-100">
<a href="$Link" class="text-decoration-none">
<% if $Image %>
<img src="$Image.URL" class="card-img-top" alt="$Image.Title">
<% else %>
<img src="https://via.placeholder.com/150" class="card-img-top" alt="No Image">
<% end_if %>
</a>
<div class="card-body">
<% if $PrimaryCategory %>
<p class="text-uppercase text-muted small mb-1">$PrimaryCategory.Title</p>
<% end_if %>
<h5 class="card-title">
<a href="$Link" class="text-decoration-none">$Title</a>
</h5>
<div class="d-flex align-items-center text-muted">
<% if $PrepTime %>
<div class="me-4">
<i class="bi bi-alarm"></i> Prep: $PrepTime
</div>
<% end_if %>
<% if $CookTime %>
<div class="me-4">
<i class="bi bi-clock"></i> Cook: $CookTime
</div>
<% end_if %>
<% if $Servings %>
<div>
<i class="bi bi-people"></i> Servings: $Servings
</div>
<% end_if %>
</div>
</div>
<div class="card-footer">
<a href="$Link" class="btn btn-primary btn-block">View Recipe</a>
</div>
</div>
</div>
<% end_loop %>

<!-- View All Button -->
<div class="col-12 text-center">
<a href="$Link" class="btn btn-secondary mt-3">View All $Title</a>
</div>
</div>
<% end_loop %>
</div>
</div>

<% if $paginatedList.MoreThanOnePage %>
<nav aria-label="Recipe Category Navigation">
<ul class="pagination justify-content-center">
<% if $paginatedList.NotFirstPage %>
<li class="page-item disabled">
<a class="page-link" href="$paginatedList.PrevLink" tabindex="-1">Previous</a>
</li>
<% end_if %>
<% loop $paginatedList.PaginationSummary %>
<% if $CurrentBool %>
<li class="page-item active">
<span class="page-link">$PageNum<span class="sr-only">(current)</span></span>
</li>
<% else %>
<% if $Link %>
<li class="page-item"><a class="page-link" href="$Link">$PageNum</a></li>
<% else %>
...
<% end_if %>
<% end_if %>
<% end_loop %>
<% if $paginatedList.NotLastPage %>
<li class="page-item">
<a class="page-link" href="$paginatedList.NextLink">Next</a>
</li>
<% end_if %>
</ul>
</nav>
<% end_if %>
<!-- Elemental Area -->
<div>
$ElementalArea
</div>
17 changes: 11 additions & 6 deletions templates/Dynamic/RecipeBook/Page/Layout/RecipePage.ss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<!-- Title and Recipe Info -->
<div class="row">
<div class="col-12">
<% if $PrimaryCategory %>
<p class="text-uppercase text-muted small mb-1">$PrimaryCategory.Title</p>
<% end_if %>
<h1 class="card-title">$Title</h1>
<div class="d-flex align-items-center text-muted mb-3">
<div class="me-4">
Expand Down Expand Up @@ -71,12 +74,14 @@
</div>
<div class="col-md-8">
<h2>Instructions</h2>
<% loop $Directions.Sort('Sort') %>
<div class="mb-3 d-flex align-items-center">
<span class="me-2">$Pos.</span>
<span>$Title</span>
</div>
<% end_loop %>
<ul class="list-group">
<% loop $Directions.Sort('Sort') %>
<li class="list-group-item d-flex align-items-center">
<span class="me-2">$Pos.</span>
<span>$Title</span>
</li>
<% end_loop %>
</ul>
</div>
</div>
</div>
Expand Down

0 comments on commit 19168da

Please sign in to comment.