]> _ Git - odl.git/commitdiff
wait #5006 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 13 Jan 2022 19:13:17 +0000 (20:13 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 13 Jan 2022 19:13:17 +0000 (20:13 +0100)
app/Fields/Link.php
app/Http/Controllers/FrontController.php
app/Models/Menu.php [new file with mode: 0644]
resources/views/layouts/app.blade.php
resources/views/vendor/backpack/base/inc/sidebar_content.blade.php

index 1f455ee3afe56035ae46256609c45606b0de853e..691804776848d912470ae58e9ac48ae51822fe50 100644 (file)
@@ -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;
     }
 }
index 640c0839450f09441c093fef220a00cca8a13b3a..3dbc8387034387070e9cf7fcd2e8be4242747e16 100644 (file)
@@ -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 (file)
index 0000000..eebdf0d
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Models;
+
+use App\Fields\Link;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
+
+class Menu extends CubistMagicAbstractModel
+{
+    protected $table = 'menu';
+    protected $_options = ['name' => '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]);
+
+    }
+}
+
index 2f80a4f5a3a919f28fccce22ea3205727ffd2d03..1468dd61c4870c5a096eab936056f091568c6e52 100644 (file)
     <body x-data="app()"
           @resize.window.debounce="measureWidth()"
           class="font-primary p-8 @stack('extra_body_classes')">
-@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.
-    --}}
-    <div style="width: var(--content-width)">
-        <x-header main="true" />
-
-        <div class="min-h-content flex flex-col mx-22 pt-22 opacity-0" :class="{ 'opacity-0': maskContents }">
-            @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.
+        --}}
+        <div style="width: var(--content-width)">
+            <x-header main="true"/>
+
+            <div class="min-h-content flex flex-col mx-22 pt-22 opacity-0" :class="{ 'opacity-0': maskContents }">
+                @yield('content')
+            </div>
         </div>
-    </div>
 
-    {{-- MENU OVERLAY --}}
-    <div class="overlay menu-overlay
+        {{-- MENU OVERLAY --}}
+        <div class="overlay menu-overlay
                 bg-blue text-white
                 z-30"
-         x-show="menuOpen"
-         x-transition.opacity.duration.500ms
-         x-transition:leave.opacity.duration.500ms.delay.500ms
-         x-cloak>
-
-        <x-header logo-class="text-white" />
-
-        <ul class="w-full font-medium text-6xl">
-            @php
-                $menu_links = [
-                    '/accueil.html' => 'Accueil',
-                    '/coeur/index.html' => 'Synthèse de l\'offre',
-                    '/ressources.html' => 'Offre',
-                    '/mediatheque.html' => 'Médiathèque',
-                    '/glossaire.html' => 'Glossaire',
-                    '/aide.html' => 'Aide',
-                ];
-            @endphp
-
-            @foreach ($menu_links as $link => $text)
-                {{-- Overflow is hidden for text entrance animation. --}}
-                {{-- Extra padding and negative margin added so hover scale effect isn't clipped --}}
-                <li class="overflow-hidden pl-4 -ml-4">
-                    <div x-show="menuOpen"
-                         class="transition transform ease-out-quint"
-                         style="transition-delay: {{ 250 + (50 * $loop->index) }}ms"
-                         x-transition:enter="duration-1000"
-                         x-transition:enter-start="translate-y-[100px]"
-                         x-transition:enter-end="translate-x-0"
-                         x-transition:leave="duration-500"
-                         x-transition:leave-start="translate-x-0"
-                         x-transition:leave-end="translate-y-[100px]">
-                        <x-link
-                            href="{{ $link }}"
-                            @click.prevent="menuOpen = false; setTimeout(() => window.location = $event.target.href, 200);"
-                            class="block py-8 text-current
+             x-show="menuOpen"
+             x-transition.opacity.duration.500ms
+             x-transition:leave.opacity.duration.500ms.delay.500ms
+             x-cloak>
+
+            <x-header logo-class="text-white"/>
+
+            <ul class="w-full font-medium text-6xl">
+                @foreach ($menu as $link)
+                    {{-- Overflow is hidden for text entrance animation. --}}
+                    {{-- Extra padding and negative margin added so hover scale effect isn't clipped --}}
+                    <li class="overflow-hidden pl-4 -ml-4">
+                        <div x-show="menuOpen"
+                             class="transition transform ease-out-quint"
+                             style="transition-delay: {{ 250 + (50 * $loop->index) }}ms"
+                             x-transition:enter="duration-1000"
+                             x-transition:enter-start="translate-y-[100px]"
+                             x-transition:enter-end="translate-x-0"
+                             x-transition:leave="duration-500"
+                             x-transition:leave-start="translate-x-0"
+                             x-transition:leave-end="translate-y-[100px]">
+                            <x-link
+                                href="{{ $link['url'] }}"
+                                data-type="{{$link['type']}}"
+                                @click.prevent="menuOpen = false; setTimeout(() => window.location = $event.target.href, 200);"
+                                class="block py-8 text-current
                                    transform origin-bottom-left
                                    transition-transform duration-200
                                    hover:scale-105">
-                            {{ $text }}
-                        </x-link>
-                    </div>
-                </li>
-                <li class="bg-blue-dark h-px
+                                {{ $link['title'] }}
+                            </x-link>
+                        </div>
+                    </li>
+                    <li class="bg-blue-dark h-px
                            transform origin-left
                            transition ease-out-quint"
-                    x-show="menuOpen"
-                    style="transition-delay: {{ 250 + (50 * $loop->index) }}ms"
-                    x-transition:enter="duration-2000"
-                    x-transition:enter-start="scale-x-0"
-                    x-transition:enter-end="scale-x-100"
-                    x-transition:leave="duration-500"
-                    x-transition:leave-start="scale-x-100"
-                    x-transition:leave-end="scale-x-0">
-                </li>
-            @endforeach
-        </ul>
-    </div>
+                        x-show="menuOpen"
+                        style="transition-delay: {{ 250 + (50 * $loop->index) }}ms"
+                        x-transition:enter="duration-2000"
+                        x-transition:enter-start="scale-x-0"
+                        x-transition:enter-end="scale-x-100"
+                        x-transition:leave="duration-500"
+                        x-transition:leave-start="scale-x-100"
+                        x-transition:leave-end="scale-x-0">
+                    </li>
+                @endforeach
+            </ul>
+        </div>
 
-    {{-- Search Overlay --}}
-    <x-search />
+        {{-- Search Overlay --}}
+        <x-search/>
 
 @endsection
index eb76a0205d4b6bf739f57c73eca951898d591042..68439385a65308ea55febb56070f3a26e36ed42f 100644 (file)
@@ -6,6 +6,11 @@
     <li class='nav-item nav-dropdown open'><a class='nav-link nav-dropdown-toggle' href='#'><i
                 class='nav-icon la la-edit'></i>Edition des contenus</a>
         <ul class='nav-dropdown-items'>
+            @can('menu:read')
+                <li class='nav-item'><a class='nav-link' href='{{ backpack_url('menu') }}'><i
+                            class='la la-bars'></i>
+                        <span>Menu</span></a></li>
+            @endcan
             @can('publications:read')
                 <li class='nav-item'><a class='nav-link' href='{{ backpack_url('publications') }}'><i
                             class='la la-book-open'></i>