Skip to content

Commit

Permalink
FEATURE Initial templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish committed Dec 2, 2024
1 parent 554b52d commit 6695fc1
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 12 deletions.
51 changes: 39 additions & 12 deletions src/Page/RecipePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

namespace Dynamic\RecipeBook\Page;

use Dynamic\RecipeBook\Model\RecipeDirection;
use Dynamic\RecipeBook\Model\RecipeIngredient;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DB;
use SilverStripe\Assets\Image;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\HasManyList;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\GridField\GridField;
use Dynamic\RecipeBook\Model\RecipeDirection;
use Dynamic\RecipeBook\Model\RecipeIngredient;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Versioned\GridFieldArchiveAction;
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;

/**
* Class RecipePage
Expand Down Expand Up @@ -60,6 +62,13 @@ class RecipePage extends \Page
'Difficulty' => 'Varchar(255)',
];

/**
* @var array
*/
private static $has_one = [
'Image' => Image::class,
];

/**
* @var array
*/
Expand All @@ -84,6 +93,13 @@ class RecipePage extends \Page
],
];

/**
* @var string[]
*/
private static $owns = [
'Image',
];

/**
* @var array
*/
Expand Down Expand Up @@ -113,6 +129,13 @@ class RecipePage extends \Page
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->insertAfter(
'Title',
UploadField::create('Image')
->setAllowedMaxFileNumber(1)
->setAllowedFileCategories('image')
->setFolderName('Uploads/Recipe/Image')
);

$fields->addFieldsToTab(
'Root.Main',
Expand All @@ -134,6 +157,10 @@ public function getCMSFields(): FieldList
'Content'
);

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

if ($this->exists()) {
$fields->addFieldToTab(
'Root.Ingredients',
Expand Down
83 changes: 83 additions & 0 deletions templates/Dynamic/RecipeBook/Page/Layout/RecipeCategoryPage.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<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">
<% if $PrepTime %>
<div class="pb-1">
<i class="far fa-clock p-1"></i>
Prep Time: $PrepTime
</div>
<% end_if %>
<% if $CookTime %>
<div class="pb-1">
<i class="far fa-clock p-1"></i>
Cook Time: $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>
<% end_if %>
</div>
</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>
</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 %>
50 changes: 50 additions & 0 deletions templates/Dynamic/RecipeBook/Page/Layout/RecipeLanding.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<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">
<% 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 class="card-body text-center pt-0">
<a href="$Link" class="btn recipe-link btn-primary">View All</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 %>
87 changes: 87 additions & 0 deletions templates/Dynamic/RecipeBook/Page/Layout/RecipePage.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<div class="container">
<!-- Full-Width Recipe Image -->
<div class="row">
<div class="col-12">
<img src="$Image.URL" class="img-fluid mb-4" alt="$Image.Title">
</div>
</div>

<!-- Title and Recipe Info -->
<div class="row">
<div class="col-12">
<h1 class="card-title">$Title</h1>
<div class="d-flex align-items-center text-muted mb-3">
<div class="me-4">
<i class="bi bi-alarm"></i> Prep: $PreparationTime minutes
</div>
<div class="me-4">
<i class="bi bi-clock"></i> Cook: $CookTime minutes
</div>
<div>
<i class="bi bi-people"></i> Servings: $Servings
</div>
</div>
</div>
</div>

<!-- Social Sharing -->
<div class="row mb-4">
<div class="col-12">
<div class="d-flex align-items-center">
<h3 class="me-3 text-muted" style="font-size: 1.25rem;">Share This Recipe:</h3>
<a href="https://www.facebook.com/sharer/sharer.php?u=$AbsoluteLink" class="me-2 text-decoration-none" target="_blank" rel="noopener noreferrer">
<i class="bi bi-facebook"></i>
</a>
<a href="https://twitter.com/intent/tweet?url=$AbsoluteLink&text=$Title" class="me-2 text-decoration-none" target="_blank" rel="noopener noreferrer">
<i class="bi bi-twitter"></i>
</a>
<a href="https://www.instagram.com" class="me-2 text-decoration-none" target="_blank" rel="noopener noreferrer">
<i class="bi bi-instagram"></i>
</a>
<a href="https://www.pinterest.com/pin/create/button/?url=$AbsoluteLink&description=$Title" class="me-2 text-decoration-none" target="_blank" rel="noopener noreferrer">
<i class="bi bi-pinterest"></i>
</a>
<a href="mailto:?subject=Check%20out%20this%20recipe!&body=Hi,%0A%0ACheck%20out%20this%20recipe%20I%20found:%20$AbsoluteLink%0A%0AEnjoy!" class="text-decoration-none">
<i class="bi bi-envelope"></i>
</a>
</div>
</div>
</div>

<!-- Recipe Info and About -->
<div class="row">
<div class="col-12">
<h3>About this Recipe</h3>
<p>$Content</p>
</div>
</div>

<!-- Ingredients and Directions -->
<div class="row mt-4">
<div class="col-md-4">
<h2>Ingredients</h2>
<ul class="list-group mb-4">
<% loop $Ingredients.Sort('Sort') %>
<li class="list-group-item">
<input type="checkbox" id="ingredient-$ID">
<label for="ingredient-$ID">$Title.Plain</label>
</li>
<% end_loop %>
</ul>
</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 %>
</div>
</div>
</div>

<!-- Elemental Area -->
<div>
$ElementalArea
</div>

0 comments on commit 6695fc1

Please sign in to comment.