From 2d4e2d53427db448c03f9ccaf2e1d8a32a3bc415 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 23 Aug 2019 16:25:45 +0200 Subject: [PATCH] fix #2926 @1 --- .../Controllers/ApplicationController.php | 23 ++++++++ app/Models/Application.php | 11 ++++ app/Templates/Solution.php | 54 +++++++++++++++++++ resources/views/pages/application.blade.php | 34 ++++++++++++ resources/views/pages/home.blade.php | 2 +- resources/views/pages/solution.blade.php | 16 ++++++ 6 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/ApplicationController.php create mode 100644 resources/views/pages/application.blade.php diff --git a/app/Http/Controllers/ApplicationController.php b/app/Http/Controllers/ApplicationController.php new file mode 100644 index 0000000..0c506d7 --- /dev/null +++ b/app/Http/Controllers/ApplicationController.php @@ -0,0 +1,23 @@ +_404(); + } + $this->data['page'] = $application->getPageData(); + $this->data['related'] = PageData::fromEntities(Product::with('media')->whereIn('id', $application->related)->get()); + return view('pages.application', $this->data); + } +} diff --git a/app/Models/Application.php b/app/Models/Application.php index 9ce59a2..5d00116 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -5,15 +5,26 @@ namespace App\Models; use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel; +use Spatie\MediaLibrary\Models\Media; class Application extends CubistMagicPageModel { + + protected $table = 'applications'; protected $_options = ['name' => 'application', 'singular' => 'application', 'plural' => 'applications']; + public function registerMediaConversions(Media $media = null) { + + parent::registerMediaConversions($media); + + $this->addMediaConversion('thumb') + ->crop('crop-center', 348, 232); + } + public function setFields() { $this->addField(['name' => 'title', diff --git a/app/Templates/Solution.php b/app/Templates/Solution.php index 07e7b8c..5b35ffb 100644 --- a/app/Templates/Solution.php +++ b/app/Templates/Solution.php @@ -3,11 +3,65 @@ namespace App\Templates; +use App\Models\Application; +use Barryvdh\Debugbar\Facade as Debugbar; +use Cubist\Backpack\app\Magic\Menu\Item; +use Cubist\Backpack\app\Magic\PageData; class Solution extends Base { + protected static $_menuChildrenDone = false; + public function getName() { return 'Solution'; } + + public function init() + { + parent::init(); + + $this->addField(['name' => 'applications', + 'label' => 'Applications', + 'type' => 'SelectFromModel', + 'optionsmodel' => 'App\Models\Application', + 'attribute' => 'title_solutions', + 'order' => true, + 'multiple' => true, + 'tab' => 'Applications']); + } + + public function setMenuChildren($menu) + { + if (self::$_menuChildrenDone) { + return; + } + + self::$_menuChildrenDone = true; + + Debugbar::startMeasure('nav_applications', 'Make applications nav items'); + parent::setMenuChildren($menu); + + $applications = Application::all(); + + foreach ($applications as $application) { + $item = new Item(); + $item->setTitle($application->title); + $item->setHref($application->getSlugOrTitleAttribute()); + $item->setId('application/' . $application->id); + $item->setController(['controller' => 'ApplicationController', 'action' => 'view', 'params' => ['id' => $application->id]]); + $menu->addChild($item); + } + + Debugbar::stopMeasure('nav_applications'); + } + + public function setData(&$data) + { + if (null === $data['page']->applications) { + $data['applications'] = []; + return; + } + $data['applications'] = PageData::fromEntities(Application::whereIn('id', $data['page']->applications)->get()); + } } diff --git a/resources/views/pages/application.blade.php b/resources/views/pages/application.blade.php new file mode 100644 index 0000000..168934c --- /dev/null +++ b/resources/views/pages/application.blade.php @@ -0,0 +1,34 @@ +@extends('layouts/app') + +@section('content') + + + + + +
+ {{-- Todo: use larger image + srcset here --}} + {{ $page->title }} + +
+ @markdown($page->content) +
+
+
+
+ + + + + + + {{-- Product Grid --}} + + @foreach($related as $id=>$rel) + @include('partials.product-link',['id'=>$id,'product'=>$rel]) + @endforeach + + + + +@endsection diff --git a/resources/views/pages/home.blade.php b/resources/views/pages/home.blade.php index 5d84449..c500fd5 100644 --- a/resources/views/pages/home.blade.php +++ b/resources/views/pages/home.blade.php @@ -95,7 +95,7 @@ {{-- Solutions / Applications --}} - + @foreach ($page->get('solutions', []) as $solution) diff --git a/resources/views/pages/solution.blade.php b/resources/views/pages/solution.blade.php index b26799e..abec4c4 100644 --- a/resources/views/pages/solution.blade.php +++ b/resources/views/pages/solution.blade.php @@ -4,4 +4,20 @@ @intro(['padding' => 'pb-4v']) + + + + + + @foreach ($applications as $application) + + + {{ $application->title_solutions }} + + @endforeach + + + + @endsection -- 2.39.5