From 93a64f265c2cccbbd61d255c97212d0c77f3d91c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 13 Jan 2022 20:13:17 +0100 Subject: [PATCH] wait #5006 @0.75 --- app/Fields/Link.php | 17 ++- app/Http/Controllers/FrontController.php | 39 +++++- app/Models/Menu.php | 29 ++++ resources/views/layouts/app.blade.php | 132 ++++++++---------- .../base/inc/sidebar_content.blade.php | 5 + 5 files changed, 140 insertions(+), 82 deletions(-) create mode 100644 app/Models/Menu.php diff --git a/app/Fields/Link.php b/app/Fields/Link.php index 1f455ee..6918047 100644 --- a/app/Fields/Link.php +++ b/app/Fields/Link.php @@ -2,19 +2,26 @@ namespace App\Fields; +use App\Models\Asset; use Cubist\Backpack\Magic\Fields\SelectFromArray; class Link extends SelectFromArray { public function getOptions() { - return ['home' => 'Home', + $res = ['home' => 'Home', 'resources' => 'Ressources', 'medialibrary' => 'Mediathèque', - 'tour' => 'Visite guidée', 'fluidbook' => 'Fluidbook', - 'animation' => 'Animation d\'ouverture', - 'search' => 'Moteur de recherche', - 'menu' => 'Menu']; +// 'animation' => 'Animation d\'ouverture', +// 'search' => 'Moteur de recherche', +// 'menu' => 'Menu' + ]; + + foreach (Asset::whereIn('type', ['audio', 'video', 'pdf'])->get() as $asset) { + $res['asset_' . $asset->id] = ucfirst($asset->type) . ' ' . $asset->id . ' - ' . $asset->title; + } + + return $res; } } diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index 640c083..3dbc838 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Models\Asset; use App\Models\AssetTheme; +use App\Models\Menu; use App\Models\Publication; use App\Models\Resource; use Cubist\Backpack\Magic\PageData; @@ -58,22 +59,48 @@ class FrontController extends Controller protected function _getDataFromCMS() { - return ['resources' => $this->_getResourcesFromCMS(), 'home' => $this->_getHomeFromCMS(), 'medialibrary' => $this->_getMediaLibraryFromCMS(), 'resources_pdf' => $this->_getResourcesPDFFromCMS()]; + return ['menu' => $this->_getMenuFromCMS(), 'resources' => $this->_getResourcesFromCMS(), 'home' => $this->_getHomeFromCMS(), 'medialibrary' => $this->_getMediaLibraryFromCMS(), 'resources_pdf' => $this->_getResourcesPDFFromCMS()]; + } + + protected function _getMenuFromCMS() + { + $res = []; + + $map = ['home' => '/accueil.html', + 'resources' => '/ressources.html', + 'medialibrary' => '/mediatheque.html', + 'fluidbook' => '/coeur/index.html']; + + foreach (Menu::all() as $item) { + $link = ['title' => $item->title]; + if (str_starts_with($item->link, 'asset_')) { + $link['type'] = $item->type; + $assetId = substr($item->link, 6); + /** @var Asset $asset */ + $asset = Asset::find($assetId); + $link['url'] = $asset->getFirstMediaUrl($asset->file_upload); + } else { + $link['type'] = 'page'; + $link['url'] = $map[$item->link] ?? $item->link; + } + $res[] = $link; + } + return $res; } protected function _getHomeFromCMS() { - $p=Publication::find('1'); - $res= $p->getPageData(); - if(null===$res->get('raccourcis')){ - $res->set('raccourcis',$p->getAttribute('raccourcis')); + $p = Publication::find('1'); + $res = $p->getPageData(); + if (null === $res->get('raccourcis')) { + $res->set('raccourcis', $p->getAttribute('raccourcis')); } return $res; } protected function _getMediaLibraryFromCMS() { - return ['themes' => PageData::fromEntities(AssetTheme::all()), 'assets' => PageData::fromEntities(Asset::whereNotNull('theme')->orderBy('code','ASC')->get())]; + return ['themes' => PageData::fromEntities(AssetTheme::all()), 'assets' => PageData::fromEntities(Asset::whereNotNull('theme')->orderBy('code', 'ASC')->get())]; } protected function _getResourcesPDFFromCMS() diff --git a/app/Models/Menu.php b/app/Models/Menu.php new file mode 100644 index 0000000..eebdf0d --- /dev/null +++ b/app/Models/Menu.php @@ -0,0 +1,29 @@ + 'menu', + 'singular' => 'Element de menu', + 'plural' => 'Elements de menu', + 'oneinstance' => false]; + + /** + * @throws \Exception + */ + public function setFields() + { + parent::setFields(); + + $this->addField('title', Text::class, 'Titre', ['column' => true]); + $this->addField('link', Link::class, 'Link', ['column' => true]); + + } +} + diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 2f80a4f..1468dd6 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -57,86 +57,76 @@ -@endsection - -@section('main') - {{-- - Content has constrained width so that nothing shifts when overlay is opened and scrolling is disabled. - The body width changes when scrollbars are removed, which causes alignment problems, especially with - fixed-position elements. - --}} -
- - -
- @yield('content') + @endsection + + @section('main') + {{-- + Content has constrained width so that nothing shifts when overlay is opened and scrolling is disabled. + The body width changes when scrollbars are removed, which causes alignment problems, especially with + fixed-position elements. + --}} +
+ + +
+ @yield('content') +
-
- {{-- MENU OVERLAY --}} - - {{-- Search Overlay --}} - + {{-- Search Overlay --}} + @endsection diff --git a/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php b/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php index eb76a02..6843938 100644 --- a/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php +++ b/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php @@ -6,6 +6,11 @@