From f65c6ea6510da5f248153f6bda3e0d37c435c60d Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Thu, 4 Jun 2020 13:39:12 +0300 Subject: [PATCH] refs #1073 Replace breadcrumbs package --- composer.json | 2 +- install-stubs/routes/breadcrumbs.php | 56 ------------- install-stubs/routes/platform.php | 81 ++++++++++++++++--- resources/views/dashboard.blade.php | 6 +- .../views/partials/breadcrumbs.blade.php | 30 ++++--- routes/breadcrumbs.php | 30 ------- routes/dashboard.php | 38 +++++---- routes/systems.php | 17 ++-- .../Providers/RouteServiceProvider.php | 3 - src/Screen/Screen.php | 2 +- tests/Environment.php | 16 +--- 11 files changed, 124 insertions(+), 157 deletions(-) delete mode 100644 install-stubs/routes/breadcrumbs.php delete mode 100644 routes/breadcrumbs.php diff --git a/composer.json b/composer.json index 4473076e7..e607958b8 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ ], "require": { "ext-json": "*", - "davejamesmiller/laravel-breadcrumbs": "^5.3", + "tabuna/breadcrumbs": "^1.0", "laravel/framework": "^7.0", "laravel/scout": "^8.0", "myclabs/php-enum": "^1.7", diff --git a/install-stubs/routes/breadcrumbs.php b/install-stubs/routes/breadcrumbs.php deleted file mode 100644 index 84cba6094..000000000 --- a/install-stubs/routes/breadcrumbs.php +++ /dev/null @@ -1,56 +0,0 @@ - System > Users -Breadcrumbs::for('platform.systems.users', function (BreadcrumbsGenerator $trail) { - $trail->parent('platform.systems.index'); - $trail->push(__('Users'), route('platform.systems.users')); -}); - -// Platform > System > Users > User -Breadcrumbs::for('platform.systems.users.edit', function (BreadcrumbsGenerator $trail, $user) { - $trail->parent('platform.systems.users'); - $trail->push(__('Edit'), route('platform.systems.users.edit', $user)); -}); - -// Platform > System > Roles -Breadcrumbs::for('platform.systems.roles', function (BreadcrumbsGenerator $trail) { - $trail->parent('platform.systems.index'); - $trail->push(__('Roles'), route('platform.systems.roles')); -}); - -// Platform > System > Roles > Create -Breadcrumbs::for('platform.systems.roles.create', function (BreadcrumbsGenerator $trail) { - $trail->parent('platform.systems.roles'); - $trail->push(__('Create'), route('platform.systems.roles.create')); -}); - -// Platform > System > Roles > Role -Breadcrumbs::for('platform.systems.roles.edit', function (BreadcrumbsGenerator $trail, $role) { - $trail->parent('platform.systems.roles'); - $trail->push(__('Role'), route('platform.systems.roles.edit', $role)); -}); - -// Platform -> Example Screen -Breadcrumbs::for('platform.example', function (BreadcrumbsGenerator $trail) { - $trail->parent('platform.index'); - $trail->push(__('Example screen')); -}); - -// Platform -> Example Fields -Breadcrumbs::for('platform.example.fields', function (BreadcrumbsGenerator $trail) { - $trail->parent('platform.index'); - $trail->push(__('Form controls')); -}); - -// Platform -> Example Layouts -Breadcrumbs::for('platform.example.layouts', function (BreadcrumbsGenerator $trail) { - $trail->parent('platform.index'); - $trail->push(__('Overview layouts')); -}); diff --git a/install-stubs/routes/platform.php b/install-stubs/routes/platform.php index 1397efe09..d11009531 100644 --- a/install-stubs/routes/platform.php +++ b/install-stubs/routes/platform.php @@ -15,6 +15,7 @@ use App\Orchid\Screens\User\UserEditScreen; use App\Orchid\Screens\User\UserListScreen; use Illuminate\Support\Facades\Route; +use Tabuna\Breadcrumbs\Trail; /* |-------------------------------------------------------------------------- @@ -28,21 +29,79 @@ */ // Main -Route::screen('/main', PlatformScreen::class)->name('platform.main'); +Route::screen('/main', PlatformScreen::class) + ->name('platform.main'); -// Users... -Route::screen('users/{users}/edit', UserEditScreen::class)->name('platform.systems.users.edit'); -Route::screen('users', UserListScreen::class)->name('platform.systems.users'); +// Platform > System > Users +Route::screen('users/{users}/edit', UserEditScreen::class) + ->name('platform.systems.users.edit') + ->breadcrumbs(function (Trail $trail, $user) { + return $trail + ->parent('platform.systems.users') + ->push(__('Edit'), route('platform.systems.users.edit', $user)); + }); -// Roles... -Route::screen('roles/{roles}/edit', RoleEditScreen::class)->name('platform.systems.roles.edit'); -Route::screen('roles/create', RoleEditScreen::class)->name('platform.systems.roles.create'); -Route::screen('roles', RoleListScreen::class)->name('platform.systems.roles'); +// Platform > System > Users > User +Route::screen('users', UserListScreen::class) + ->name('platform.systems.users') + ->breadcrumbs(function (Trail $trail) { + return $trail + ->parent('platform.systems.index') + ->push(__('Users'), route('platform.systems.users')); + }); + +// Platform > System > Roles > Role +Route::screen('roles/{roles}/edit', RoleEditScreen::class) + ->name('platform.systems.roles.edit') + ->breadcrumbs(function (Trail $trail, $role) { + return $trail + ->parent('platform.systems.roles') + ->push(__('Role'), route('platform.systems.roles.edit', $role)); + }); + +// Platform > System > Roles > Create +Route::screen('roles/create', RoleEditScreen::class) + ->name('platform.systems.roles.create') + ->breadcrumbs(function (Trail $trail) { + return $trail + ->parent('platform.systems.roles') + ->push(__('Create'), route('platform.systems.roles.create')); + }); + +// Platform > System > Roles +Route::screen('roles', RoleListScreen::class) + ->name('platform.systems.roles') + ->breadcrumbs(function (Trail $trail) { + return $trail + ->parent('platform.systems.index') + ->push(__('Roles'), route('platform.systems.roles')); + }); // Example... -Route::screen('example', ExampleScreen::class)->name('platform.example'); -Route::screen('example-fields', ExampleFieldsScreen::class)->name('platform.example.fields'); -Route::screen('example-layouts', ExampleLayoutsScreen::class)->name('platform.example.layouts'); +Route::screen('example', ExampleScreen::class) + ->name('platform.example') + ->breadcrumbs(function (Trail $trail) { + return $trail + ->parent('platform.index') + ->push(__('Example screen')); + }); + +Route::screen('example-fields', ExampleFieldsScreen::class) + ->name('platform.example.fields') + ->breadcrumbs(function (Trail $trail) { + return $trail + ->parent('platform.index') + ->push(__('Form controls')); + }); + +Route::screen('example-layouts', ExampleLayoutsScreen::class) + ->name('platform.example.layouts') + ->breadcrumbs(function (Trail $trail) { + return $trail + ->parent('platform.index') + ->push(__('Overview layouts')); + }); + Route::screen('example-charts', ExampleChartsScreen::class)->name('platform.example.charts'); Route::screen('example-editors', ExampleTextEditorsScreen::class)->name('platform.example.editors'); Route::screen('example-cards', ExampleCardsScreen::class)->name('platform.example.cards'); diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 256f2689f..24004cc11 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -55,11 +55,9 @@ - @if (Breadcrumbs::exists()) - {{ Breadcrumbs::view('platform::partials.breadcrumbs') }} - @endif + @includeWhen(Breadcrumbs::has(), 'platform::partials.breadcrumbs') -
+
@include('platform::partials.alert') @yield('content') diff --git a/resources/views/partials/breadcrumbs.blade.php b/resources/views/partials/breadcrumbs.blade.php index 949efe194..2932f8039 100644 --- a/resources/views/partials/breadcrumbs.blade.php +++ b/resources/views/partials/breadcrumbs.blade.php @@ -1,13 +1,17 @@ -@if (count($breadcrumbs) > 1) - -@endif + diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php deleted file mode 100644 index 21f239f8e..000000000 --- a/routes/breadcrumbs.php +++ /dev/null @@ -1,30 +0,0 @@ -push(__('Main'), route('platform.index')); -}); - -// Platform > System -Breadcrumbs::for('platform.systems.index', function (BreadcrumbsGenerator $trail) { - $trail->parent('platform.index'); - $trail->push(__('Systems'), route('platform.systems.index')); -}); - -// Platform -> Notifications -Breadcrumbs::for('platform.notifications', function (BreadcrumbsGenerator $trail) { - $trail->parent('platform.index'); - $trail->push(__('Notifications')); -}); - -// Platform -> Search Result -Breadcrumbs::for('platform.search', function (BreadcrumbsGenerator $trail, string $query) { - $trail->parent('platform.index'); - $trail->push(__('Search')); - $trail->push($query); -}); diff --git a/routes/dashboard.php b/routes/dashboard.php index 97a1e150f..cf56ee15d 100644 --- a/routes/dashboard.php +++ b/routes/dashboard.php @@ -6,24 +6,32 @@ use Orchid\Platform\Http\Controllers\Systems\IndexController; use Orchid\Platform\Http\Screens\NotificationScreen; use Orchid\Platform\Http\Screens\SearchScreen; - -/* -|-------------------------------------------------------------------------- -| Dashboard Web Routes -|-------------------------------------------------------------------------- -| -| Base route -| -*/ +use Tabuna\Breadcrumbs\Trail; // Index and default... -$this->router->get('/', [IndexController::class, 'index'])->name('index'); -$this->router->post('/async/{screen}/{method?}/{template?}', [AsyncController::class, 'load'])->name('async'); +$this->router->get('/', [IndexController::class, 'index']) + ->name('index') + ->breadcrumbs(function (Trail $trail) { + return $trail->push(__('Main'), route('platform.index')); + }); -$this->router->fallback([IndexController::class, 'fallback']); +$this->router->screen('search/{query}', SearchScreen::class) + ->name('search') + ->breadcrumbs(function (Trail $trail, string $query) { + return $trail->parent('platform.index') + ->push(__('Search')) + ->push($query); + }); -$this->router->screen('search/{query}', SearchScreen::class)->name('search'); -$this->router->screen('notifications/{id?}', NotificationScreen::class)->name('notifications'); +$this->router->screen('notifications/{id?}', NotificationScreen::class) + ->name('notifications') + ->breadcrumbs(function (Trail $trail) { + return $trail->parent('platform.index') + ->push(__('Notifications')); + }); -$this->router->post('/api/notifications', [NotificationScreen::class, 'unreadNotification']) +$this->router->post('api/notifications', [NotificationScreen::class, 'unreadNotification']) ->name('api.notifications'); + +$this->router->post('async/{screen}/{method?}/{template?}', [AsyncController::class, 'load'])->name('async'); +$this->router->fallback([IndexController::class, 'fallback']); diff --git a/routes/systems.php b/routes/systems.php index 3c02d92bf..eef18fcc6 100644 --- a/routes/systems.php +++ b/routes/systems.php @@ -5,18 +5,15 @@ use Orchid\Platform\Http\Controllers\Systems\AttachmentController; use Orchid\Platform\Http\Controllers\Systems\RelationController; use Orchid\Platform\Http\Controllers\Systems\SystemController; - -/* -|-------------------------------------------------------------------------- -| Systems Web Routes -|-------------------------------------------------------------------------- -| -| Base route -| -*/ +use Tabuna\Breadcrumbs\Trail; $this->router->get('/', [SystemController::class, 'index']) - ->name('systems.index'); + ->name('systems.index') + ->breadcrumbs(function (Trail $trail) { + return $trail + ->parent('platform.index') + ->push(__('Systems'), route('platform.systems.index')); + }); $this->router->post('files', [AttachmentController::class, 'upload']) ->name('systems.files.upload'); diff --git a/src/Platform/Providers/RouteServiceProvider.php b/src/Platform/Providers/RouteServiceProvider.php index c2ae75b45..3a7079149 100644 --- a/src/Platform/Providers/RouteServiceProvider.php +++ b/src/Platform/Providers/RouteServiceProvider.php @@ -26,9 +26,6 @@ public function boot() ]); $this->binding(); - - require Dashboard::path('routes/breadcrumbs.php'); - parent::boot(); } diff --git a/src/Screen/Screen.php b/src/Screen/Screen.php index edcb96c16..cf41bc0c3 100644 --- a/src/Screen/Screen.php +++ b/src/Screen/Screen.php @@ -163,7 +163,7 @@ public function handle(...$parameters) ); $query = request()->query(); - $query = !is_array($query) ? [] : $query; + $query = ! is_array($query) ? [] : $query; $parameters = array_filter($parameters); $parameters = array_merge(array_keys($query), $parameters); diff --git a/tests/Environment.php b/tests/Environment.php index 76929969f..4244a8922 100644 --- a/tests/Environment.php +++ b/tests/Environment.php @@ -4,9 +4,7 @@ namespace Orchid\Tests; -use DaveJamesMiller\Breadcrumbs\BreadcrumbsGenerator; -use DaveJamesMiller\Breadcrumbs\BreadcrumbsManager; -use DaveJamesMiller\Breadcrumbs\Facades\Breadcrumbs; +use Tabuna\Breadcrumbs\Breadcrumbs; use Orchid\Database\Seeds\OrchidDatabaseSeeder; use Orchid\Platform\Models\User; use Orchid\Platform\Providers\FoundationServiceProvider; @@ -14,6 +12,7 @@ use Orchid\Support\Facades\Dashboard; use Orchid\Tests\App\ExemplarServiceProvider; use Sti3bas\ScoutArray\ScoutArrayEngineServiceProvider; +use Tabuna\Breadcrumbs\BreadcrumbsServiceProvider; use Watson\Active\Active; /** @@ -73,16 +72,6 @@ protected function getEnvironmentSetUp($app) ]); $config->set('scout.driver', 'array'); $config->set('database.default', 'orchid'); - - $config->set('breadcrumbs', [ - 'view' => 'breadcrumbs::bootstrap4', - 'files' => base_path('routes/breadcrumbs.php'), - 'unnamed-route-exception' => false, - 'missing-route-bound-breadcrumb-exception' => false, - 'invalid-named-breadcrumb-exception' => false, - 'manager-class' => BreadcrumbsManager::class, - 'generator-class' => BreadcrumbsGenerator::class, - ]); } /** @@ -93,6 +82,7 @@ protected function getEnvironmentSetUp($app) protected function getPackageProviders($app) { return [ + BreadcrumbsServiceProvider::class, FoundationServiceProvider::class, ExemplarServiceProvider::class, ScoutArrayEngineServiceProvider::class,