Skip to content

Commit

Permalink
Merge branch 'feature/modular-2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdancingcat committed Oct 24, 2023
2 parents 40ff1a0 + 9af0a23 commit e6b2240
Show file tree
Hide file tree
Showing 24 changed files with 470 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ npm-debug.log
yarn-error.log
cs_fixer_tmp*
.php_cs.cache
.phpunit.cache
.php-cs-fixer.cache
/public/mix-manifest.json
/*.diff
Expand Down
14 changes: 2 additions & 12 deletions app/Http/Controllers/ModularPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@

use Illuminate\Http\Request;
use Contracts\Repositories\ModularPageRepositoryContract;
use Contracts\Repositories\EventRepositoryContract;
use Contracts\Repositories\ArticleRepositoryContract;

class ModularPageController extends Controller
{
/**
* Construct the controller.
*
* @param ArticleRepositoryContract $article
* @param EventRepositoryContract $event
*/
public function __construct(ModularPageRepositoryContract $promo, ArticleRepositoryContract $article, EventRepositoryContract $event)
public function __construct(ModularPageRepositoryContract $promo)
{
$this->promo = $promo;
$this->article = $article;
$this->event = $event;
}

/**
Expand All @@ -37,10 +31,6 @@ public function index(Request $request)
{
$promos['promos'] = $this->promo->getModularPromos($request->data['base']);

$articles = $this->article->listing($request->data['base']['data']['news_application_id'] ?? $request->data['base']['site']['news']['application_id']);

$events = $this->event->getEvents($request->data['base']['data']['event_listing_site_id'] ?? $request->data['base']['site']['id']);

return view('modular/modularpage', merge($request->data, $articles, $events, $promos));
return view('modular/modularpage', merge($request->data, $promos));
}
}
70 changes: 66 additions & 4 deletions app/Repositories/ModularPageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Repositories;

use Contracts\Repositories\ModularPageRepositoryContract;
use Contracts\Repositories\EventRepositoryContract;
use Contracts\Repositories\ArticleRepositoryContract;
use Illuminate\Cache\Repository;
use Illuminate\Support\Str;
use Waynestate\Api\Connector;
use Waynestate\Promotions\ParsePromos;

Expand All @@ -25,11 +28,18 @@ class ModularPageRepository implements ModularPageRepositoryContract
* @param ParsePromos $parsePromos
* @param Repository $cache
*/
public function __construct(Connector $wsuApi, ParsePromos $parsePromos, Repository $cache)
{
public function __construct(
Connector $wsuApi,
ParsePromos $parsePromos,
Repository $cache,
ArticleRepositoryContract $article,
EventRepositoryContract $event
) {
$this->wsuApi = $wsuApi;
$this->parsePromos = $parsePromos;
$this->cache = $cache;
$this->article = $article;
$this->event = $event;
}

/**
Expand All @@ -53,7 +63,7 @@ public function getModularPromos(array $data)
$component = str_replace('_', '-', $component);

if (str_starts_with($properties, '{') === true) {
$components[$component] = $this->parsePromoJSON($properties, $data['page']['id']);
$components[$component] = $this->parseJSON($properties, $data['page']['id']);
} else {
// If only an ID is entered without json
$components[$component]['id'] = (int)$properties;
Expand All @@ -80,8 +90,32 @@ public function getModularPromos(array $data)

$promos = $this->appendComponentProperties($promos, $components);

$promos = $this->changePromoItemDisplay($promos);

$promos = $this->parsePromos->parse($promos, $group_reference, $group_config);

foreach($components as $component => $properties) {
if (str_contains($component, 'news')) {
$articles = $this->article->listing($properties['id']);
foreach($articles['articles']['data'] as $key => $data) {
$articles['articles']['data'][$key]['component'] = $properties;
$articles['articles']['data'][$key]['component']['filename'] = preg_replace('/-\d+$/', '', $component);
}
$promos[$component] = $articles['articles']['data'];
}

if (str_contains($component, 'events')) {
$events = $this->event->getEvents($properties['id']);
foreach($events['events'] as $key => $dates) {
foreach($dates as $date => $data) {
$events['events'][$key]['component'] = $properties;
$events['events'][$key]['component']['filename'] = preg_replace('/-\d+$/', '', $component);
}
}
$promos[$component] = $events['events'];
}
}

// Reset promo item key to use component values in template
if (!empty($promos)) {
foreach ($promos as $component => $values) {
Expand All @@ -95,7 +129,7 @@ public function getModularPromos(array $data)
/**
* {@inheritdoc}
*/
public function parsePromoJSON($json, $page_id)
public function parseJSON($json, $page_id)
{
$component = [];

Expand Down Expand Up @@ -146,4 +180,32 @@ public function appendComponentProperties($promos, $components = null)

return $promos;
}

/**
* {@inheritdoc}
*/
public function changePromoItemDisplay($promos)
{
$promos['promotions'] = collect($promos['promotions'])->map(function ($item) {

// Enable the individual promotion view
if (!empty($item['component']['singlePromoView']) && $item['component']['singlePromoView'] === true) {
$item['link'] = 'view/'.Str::slug($item['title']).'-'.$item['promo_item_id'];
}

// Hide excerpt
if (!empty($item['component']['showExcerpt']) && $item['component']['showExcerpt'] === false) {
unset($item['excerpt']);
}

// Hide description
if (!empty($item['component']['showDescription']) && $item['component']['showDescription'] === false) {
unset($item['description']);
}

return $item;
})->toArray();

return $promos;
}
}
2 changes: 1 addition & 1 deletion factories/GenericPromo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function create($limit = 1, $flatten = false, $options = [])
{
$promo_group_id = $this->faker->randomNumber(5);

for ($i = 0; $i <= ($limit - 1); $i++) {
for ($i = 0; $i <= $limit - 1; $i++) {
$data[$i] = [
'title' => ucfirst(implode(' ', $this->faker->words(3))),
'excerpt' => $this->faker->sentence(),
Expand Down
62 changes: 62 additions & 0 deletions factories/Spotlight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Factories;

use Contracts\Factories\FactoryContract;
use Faker\Factory;

class Spotlight implements FactoryContract
{
/**
* Construct the factory.
*/
public function __construct(Factory $faker)
{
$this->faker = $faker->create();
}

/**
* {@inheritdoc}
*/
public function create($limit = 1, $flatten = false, $options = [])
{
$promo_group_id = $this->faker->randomNumber(5);

for ($i = 0; $i <= $limit - 1; $i++) {
$data[$i] = [
'title' => $this->faker->name,
'excerpt' => $this->faker->jobTitle,
'description' => '<p>&ldquo;' . $this->faker->text(200) . '&rdquo;</p>',
'link' => 'https://wayne.edu',
'promo_item_id' => $i,
'promo_group_id' => strval($promo_group_id),
'relative_url' => '/styleguide/image/600x600?text=600x600:'.$i,
'filename_url' => '/styleguide/image/600x600?text=600x600:'.$i,
'filename_alt_text' => 'Placeholder image '.$i,
'secondary_image' => '',
'secondary_relative_url' => '/styleguide/image/150x150?text=150x150:'.$i, // 4:3
'secondary_filename_url' => '',
'secondary_alt_text' => 'Secondary placeholder image '.$i,
'option' => '',
//'option' => $this->faker->randomElement(['Gold', 'Green', '']),
'start_date' => $this->faker->dateTimeThisMonth('now')->format('Y-m-d H:i:s'),
'end_date' => '',
'display_start_date' => '0000-00-00 00:00:00',
'display_end_date' => '0000-00-00 00:00:00',
'start_time_hide' => '0',
'end_time_hide' => '0',
'group' => [
'title' => 'Promo group title',
],
];

$data[$i] = array_replace_recursive($data[$i], $options);
}

if ($limit === 1 && $flatten === true) {
return current($data);
}

return $data;
}
}
3 changes: 1 addition & 2 deletions resources/views/components/events-listing.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{--
$events => array // ['title', 'url', 'date', 'start_time', 'is_all_day']
$cal_name => string // 'main/'
$link_text => string // 'More events'
--}}

Expand Down Expand Up @@ -33,7 +32,7 @@
@endforeach
@if($dates == end($events))
<li class="flex -mx-2 ml-17">
<a href="//events.wayne.edu/{{ $cal_name ?? 'main/' }}month/" class="hover:underline">{{ $link_text ?? 'More events' }}</a>
<a href="//events.wayne.edu/{{ $dates[0]['calendar_url'] ?? 'main/' }}month/" class="hover:underline">{{ $link_text ?? 'More events' }}</a>
</li>
@endif
@endforeach
Expand Down
2 changes: 1 addition & 1 deletion resources/views/modular/components/accordion.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{--
$items => array // ['title', 'description']
$item => array // ['title', 'description']
--}}
<div class="col-span-2">
@if(!empty($data[0]['component']['heading']))<h2 class="mt-0">{{ $data[0]['component']['heading'] }}</h2>@endif
Expand Down
5 changes: 4 additions & 1 deletion resources/views/modular/components/button-column.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div>
{{--
$button => array // ['title', 'link']
--}}
<div class="col-span-2 md:col-span-1">
@if(!empty($data[0]['component']['heading']))<h2 class="mt-0">{{ $data[0]['component']['heading'] }}</h2>@endif
<div class="grid gap-y-4 xl:mx-0 items-start">
@foreach($data as $button)
Expand Down
5 changes: 4 additions & 1 deletion resources/views/modular/components/button-row.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{{--
$button => array // ['title', 'link']
--}}
<div class="col-span-2">
@if(!empty($data[0]['component']['heading']))<h2 class="mt-0">{{ $data[0]['component']['heading'] }}</h2>@endif
<div class="grid md:grid-cols-2 lg:grid-cols-3 gap-x-4 gap-y-2 mx-4 xl:mx-0 items-start">
<div class="grid md:grid-cols-2 lg:grid-cols-3 gap-x-4 gap-y-2 xl:mx-0 items-start">
@foreach($data as $button)
<a href="{{ $button['link'] }}" class="green-button text-lg w-full mb-0">{{ $button['title'] }}</a>
@endforeach
Expand Down
61 changes: 61 additions & 0 deletions resources/views/modular/components/catalog.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{--
$item => single // ['title', 'excerpt', 'description', 'link', 'filename_url', 'filename_alt_text']
--}}

<div class="col-span-2">
@if(!empty($data[0]['component']['heading']))<h2 class="mt-0">{{ $data[0]['component']['heading'] }}</h2>@endif

@if(!empty($data[0]['component']['columns']) && $data[0]['component']['columns'] == 1)
<div class="grid gap-4">
@foreach($data as $item)
<{{ !empty($item['link']) ? 'a href='.$item['link'] : 'div' }} class="flex items-start space-x-3 md:space-x-6 mb-8 {{ !empty($item['link']) ? 'group' : '' }}">
@if(!empty($item['filename_url']))
@image($item['filename_url'], $item['filename_alt_text'], 'w-1/4 shrink-0')
@endif

<div class="md:mt-0 content">
<div class="font-bold text-xl group-hover:underline group-focus:underline">{{ $item['title'] }}</div>
@if(!empty($item['excerpt']))
<div class="text-black mt-1">
{!! strip_tags($item['excerpt'], ['em', 'strong']) !!}
</div>
@endif
@if(!empty($item['description']))
@if (!empty($item['link']))
<div class="text-black mt-1">{!! preg_replace(array('"<a href(.*?)>"', '"</a>"'), array('',''), $item['description']) !!}</div>
@else
<div class="text-black mt-1">{!! $item['description'] !!}</div>
@endif
@endif
</div>
<{{ !empty($item['link']) ? '/a' : '/div' }}>
@endforeach
</div>
@else
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-{{ !empty($data[0]['component']['columns']) && $data[0]['component']['columns'] >= 3 ? '3' : '2' }} xl:grid-cols-{{ !empty($data[0]['component']['columns']) ? $data[0]['component']['columns'] : '3' }}">
@foreach($data as $item)
<{{ !empty($item['link']) ? 'a href='.$item['link'] : 'div' }} class="flex items-start space-x-3 md:space-x-0 md:block {{ !empty($item['link']) ? 'group' : '' }}">
@if(!empty($item['filename_url']))
@image($item['filename_url'], $item['filename_alt_text'], 'w-1/4 shrink-0 md:shrink md:w-full')
@endif

<div class=>
<div class="w-full relative md:pt-2">
<div class="font-bold text-xl group-hover:underline group-focus:underline">{{ $item['title'] }}</div>
@if(!empty($item['excerpt']))
<div class="block mt-1 font-normal text-black">{!! strip_tags($item['excerpt'], ['em','strong']) !!}</div>
@endif
@if(!empty($item['description']))
@if (!empty($item['link']))
<div class="text-black mt-1">{!! preg_replace(array('"<a href(.*?)>"', '"</a>"'), array('',''), $item['description']) !!}</div>
@else
<div class="text-black mt-1">{!! $item['description'] !!}</div>
@endif
@endif
</div>
</div>
<{{ !empty($item['link']) ? '/a' : '/div' }}>
@endforeach
</div>
@endif
</div>
9 changes: 6 additions & 3 deletions resources/views/modular/components/content-column.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<div class="col-span-1 content">
{{--
$item => array // ['title', 'description']
--}}
<div class="col-span-2 md:col-span-1 content">
@if(!empty($data[0]['component']['heading']))<h2 class="mt-0">{{ $data[0]['component']['heading'] }}</h2>@endif
@foreach($data as $content_block)
@if(!empty($data[0]['group']['heading']))
@if(!empty($data[0]['component']['heading']))
<h3>{{ $content_block['title'] }}</h3>
@else
<h2>{{ $content_block['title'] }}</h2>
<h2 class="mt-0">{{ $content_block['title'] }}</h2>
@endif
{!! $content_block['description'] !!}
@endforeach
Expand Down
5 changes: 4 additions & 1 deletion resources/views/modular/components/content-row.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{{--
$item => array // ['title', 'description']
--}}
<div class="col-span-2 content">
@if(!empty($data[0]['component']['heading']))<h2 class="mt-0">{{ $data[0]['component']['heading'] }}</h2>@endif
@foreach($data as $content_block)
@if(!empty($data[0]['component']['heading']))
<h3>{{ $content_block['title'] }}</h3>
@else
<h2>{{ $content_block['title'] }}</h2>
<h2 class="mt-0">{{ $content_block['title'] }}</h2>
@endif
{!! $content_block['description'] !!}
@endforeach
Expand Down
Loading

0 comments on commit e6b2240

Please sign in to comment.