From d9599f6904528484c8e657156741cc5ad86eafa3 Mon Sep 17 00:00:00 2001 From: nikhil trivedi Date: Thu, 11 Jul 2024 13:40:48 -0500 Subject: [PATCH 1/2] Refactor table of contents to use Eloquent models instead of array copies [PUB-206] --- .../Admin/DigitalPublicationPresenter.php | 73 +------------------ ...e-actions----digital-publication.blade.php | 6 +- .../organisms/_o-table-of-contents.blade.php | 16 ++-- 3 files changed, 13 insertions(+), 82 deletions(-) diff --git a/app/Presenters/Admin/DigitalPublicationPresenter.php b/app/Presenters/Admin/DigitalPublicationPresenter.php index b821ce929..67c6146b6 100644 --- a/app/Presenters/Admin/DigitalPublicationPresenter.php +++ b/app/Presenters/Admin/DigitalPublicationPresenter.php @@ -7,11 +7,6 @@ class DigitalPublicationPresenter extends BasePresenter { - /** - * Formatted specifically for `_o-accordion`. - */ - private $articlesForSidebar = []; - /** * This is an associative array, keyed by article type. * It will also have an `all` key, containing all articles. @@ -69,73 +64,9 @@ protected function isDscStub() return $this->entity->is_dsc_stub ? 'Yes' : 'No'; } - public function articlesForSidebar($currentArticle = null) - { - if (!$this->articlesForSidebar) { - foreach (DigitalPublicationArticleType::cases() as $type) { - if (!$this->hasArticles($type->value)) { - continue; - } - - $this->articlesForSidebar[] = [ - 'title' => $type->name, - 'active' => !isset($currentArticle) || $currentArticle->type === $type, - 'blocks' => [ - [ - 'type' => 'link-list', - 'links' => $this - ->getArticles($type->value) - ->map(function ($article) use ($currentArticle) { - $sublabel = $article->type === DigitalPublicationArticleType::Contributions - ? $article->showAuthors() - : null; - return [ - 'label' => $article->title_display ?? $article->title, - 'sublabel' => $sublabel, - 'href' => $article->present()->getArticleUrl($this->entity), - 'active' => isset($currentArticle) && $article->id === $currentArticle->id, - ]; - }), - ], - ], - ]; - } - } - - return $this->articlesForSidebar; - } - - public function nestedArticlesForSidebar() - { - // Root articles will have no parent_id so let's start building from there - - $articles = $this->entity->articles()->published()->ordered()->whereNull('parent_id')->get(); - - return $this->buildNestedArticlesArray($articles); - } - - private function buildNestedArticlesArray($articles) + public function topLevelArticles() { - $articlesList = []; - - foreach ($articles as $article) { - // Build the article array for use on the FE - - $articleArray = [ - 'title' => $article->title, - 'url' => $article->present()->getArticleUrl($this->entity), - ]; - - // Recursively build nested articles since children can have children - - if ($article->children) { - $articleArray['items'] = $this->buildNestedArticlesArray($article->children); - } - - $articlesList[] = $articleArray; - } - - return $articlesList; + return $this->entity->articles()->published()->ordered()->whereNull('parent_id')->get(); } public function headerTitle() diff --git a/resources/views/components/molecules/_m-article-actions----digital-publication.blade.php b/resources/views/components/molecules/_m-article-actions----digital-publication.blade.php index 365f3b75d..e72f206cf 100644 --- a/resources/views/components/molecules/_m-article-actions----digital-publication.blade.php +++ b/resources/views/components/molecules/_m-article-actions----digital-publication.blade.php @@ -11,14 +11,14 @@ @php - $articlesForSidebar = $digitalPublication->present()->nestedArticlesForSidebar($digitalPublication); + $topLevelArticles = $digitalPublication->present()->topLevelArticles(); @endphp - @if (!empty($articlesForSidebar)) + @if (!empty($topLevelArticles)) @component('components.organisms._o-table-of-contents') @slot('variation', 'o-accordion--publication-sidebar') @slot('titleFont', 'f-tag-2') - @slot('items', $articlesForSidebar) + @slot('items', $topLevelArticles) @endcomponent @endif diff --git a/resources/views/components/organisms/_o-table-of-contents.blade.php b/resources/views/components/organisms/_o-table-of-contents.blade.php index cc909366a..25b959979 100644 --- a/resources/views/components/organisms/_o-table-of-contents.blade.php +++ b/resources/views/components/organisms/_o-table-of-contents.blade.php @@ -1,9 +1,9 @@
@foreach ($items as $item) - @if (count($item['items']) > 0) + @if (count($item->children) > 0)

-

@else - - {!! $item['title'] !!} + gtmAttributes)) ? ' '.$item->gtmAttributes.'' : '' !!}> + {!! $item->title !!} @endif - @if (count($item['items']) > 0) -
+ @if (count($item->children) > 0) +
{{-- In the same tune of the build nested articles we can just recursively call the same component to build the table of contents. --}} - @include('components.organisms._o-table-of-contents', ['items' => $item['items']]) + @include('components.organisms._o-table-of-contents', ['items' => $item->children])
@endif @endforeach From a49563845a51107ea407ecd3da2b06b2c684990e Mon Sep 17 00:00:00 2001 From: nikhil trivedi Date: Thu, 11 Jul 2024 13:42:15 -0500 Subject: [PATCH 2/2] Update publication landing to show basic heirarchy layout [PUB-206] --- .../molecules/_m-listing----article.blade.php | 4 +- .../site/digitalPublicationDetail.blade.php | 98 ++++++------------- 2 files changed, 31 insertions(+), 71 deletions(-) diff --git a/resources/views/components/molecules/_m-listing----article.blade.php b/resources/views/components/molecules/_m-listing----article.blade.php index 5f0ffbd2d..d3e130142 100644 --- a/resources/views/components/molecules/_m-listing----article.blade.php +++ b/resources/views/components/molecules/_m-listing----article.blade.php @@ -1,5 +1,5 @@ <{{ $tag ?? 'li' }} class="m-listing m-listing--article{{ (isset($variation)) ? ' '.$variation : '' }}"{!! (isset($variation) and strrpos($variation, "--hero") > -1 and !$item->videoFront) ? ' data-behavior="blurMyBackground"' : '' !!}> - + @if (!isset($hideImage) || (isset($hideImage) && !($hideImage))) -1 and !$item->videoFront) ? ' data-blur-img' : '' }}> @if (isset($image) || $item->imageFront('hero')) @@ -14,7 +14,7 @@ @slot('settings', $imageSettings ?? '') @slot('class', 'img-hero-mobile') @endcomponent - @else + @else @component('components.atoms._img') @slot('image', $image ?? $item->imageFront('hero')) @slot('settings', $imageSettings ?? '') diff --git a/resources/views/site/digitalPublicationDetail.blade.php b/resources/views/site/digitalPublicationDetail.blade.php index 0216c06c2..293e41205 100644 --- a/resources/views/site/digitalPublicationDetail.blade.php +++ b/resources/views/site/digitalPublicationDetail.blade.php @@ -41,83 +41,43 @@
@endif - @if ($item->present()->hasArticles(DigitalPublicationArticleType::Contributions->value)) + @foreach ($item->present()->topLevelArticles() as $topLevelArticle) @component('components.molecules._m-title-bar', [ 'variation' => 'm-title-bar--compact m-title-bar--light', ]) - {{ DigitalPublicationArticleType::Contributions->name }} + {!! $topLevelArticle->title !!} @endcomponent @component('components.organisms._o-grid-listing') - @slot('variation', 'o-grid-listing--journal') - @slot('cols_xsmall','1') - @slot('cols_small','2') - @slot('cols_medium','2') - @slot('cols_large','2') - @slot('cols_xlarge','2') - @foreach ($item->present()->getArticles(DigitalPublicationArticleType::Contributions->value) as $article) - @component('components.molecules._m-listing----publication') - @slot('variation', 'm-listing--journal') - @slot('href', $article->present()->getArticleUrl($item)) - @slot('image', $article->imageFront('hero')) - @slot('type', $article->present()->label) - @slot('title', $article->present()->title) - @slot('title_display', $article->present()->title_display) - @slot('list_description', $article->present()->list_description) - @slot('author_display', $article->showAuthors()) - @slot('imageSettings', array( - 'fit' => 'crop', - 'ratio' => '16:9', - 'srcset' => array(200,400,600), - 'sizes' => ImageHelpers::aic_imageSizes(array( - 'xsmall' => '216px', - 'small' => '216px', - 'medium' => '18', - 'large' => '13', - 'xlarge' => '13', - )), - )) - @endcomponent + @slot('variation', 'o-grid-listing--single-row o-grid-listing--scroll@xsmall o-grid-listing--scroll@small o-grid-listing--scroll@medium o-grid-listing--gridlines-cols') + @slot('cols_medium','3') + @slot('cols_large','4') + @slot('cols_xlarge','4') + + @foreach ($topLevelArticle->children as $article) + @if ($loop->iteration <= 3) + @component('components.molecules._m-listing----article') + @slot('imgVariation','') + @slot('item', $article) + @slot('module', 'collection.publications.digital-publications-articles') + @slot('routeParameters', ['pubId' => $item->id, 'pubSlug' => $item->getSlug(), 'id' => $article->id]) + @slot('imageSettings', array( + 'fit' => 'crop', + 'ratio' => '16:9', + 'srcset' => array(200,400,600), + 'sizes' => ImageHelpers::aic_imageSizes(array( + 'xsmall' => '216px', + 'small' => '216px', + 'medium' => '18', + 'large' => '13', + 'xlarge' => '13', + )), + )) + @endcomponent + @endif @endforeach @endcomponent - @endif - - @if ($item->present()->hasArticles(DigitalPublicationArticleType::Works->value)) - @component('components.molecules._m-title-bar', [ - 'variation' => 'm-title-bar--compact m-title-bar--light', - ]) - {{ DigitalPublicationArticleType::Works->name }} - @endcomponent - - @component('components.organisms._o-grid-listing') - @slot('variation', 'o-grid-listing--journal') - - @foreach ($item->present()->getArticles(DigitalPublicationArticleType::Works->value) as $article) - @component('components.molecules._m-listing----publication') - @slot('variation', 'm-listing--work') - @slot('href', $article->present()->getArticleUrl($item)) - @slot('image', $article->imageFront('hero')) - @slot('type', $article->present()->label) - @slot('title', $article->present()->title) - @slot('title_display', $article->present()->title_display) - @slot('list_description', $article->present()->list_description) - @slot('author_display', $article->showAuthors()) - @slot('imageSettings', array( - 'fit' => 'crop', - 'ratio' => '16:9', - 'srcset' => array(200,400,600), - 'sizes' => ImageHelpers::aic_imageSizes(array( - 'xsmall' => '216px', - 'small' => '216px', - 'medium' => '18', - 'large' => '13', - 'xlarge' => '13', - )), - )) - @endcomponent - @endforeach - @endcomponent - @endif + @endforeach @if (isset($item->sponsor_display)) @component('components.molecules._m-title-bar', [