diff --git a/src/Platform/Commands/InstallCommand.php b/src/Platform/Commands/InstallCommand.php index c9dbd3a9bc..4d21e5957f 100644 --- a/src/Platform/Commands/InstallCommand.php +++ b/src/Platform/Commands/InstallCommand.php @@ -22,7 +22,8 @@ class InstallCommand extends Command * * @var string */ - protected $signature = 'orchid:install'; + protected $signature = 'orchid:install + {--without-examples : Install without examples}'; /** * The console command description. @@ -49,10 +50,13 @@ public function handle() 'orchid-migrations', 'orchid-app-stubs', 'orchid-assets', + $this->option('without-examples') ?: 'orchid-examples', ], ]) ->executeCommand('migrate') ->executeCommand('storage:link') + ->addPlatformProvider() + ->addRoutes() ->changeUserModel() ->when(class_exists(\App\Models\User::class), function () { $this->replaceInFiles(app_path(), 'use Orchid\\Platform\\Models\\User;', 'use App\\Models\\User;'); @@ -87,6 +91,42 @@ private function executeCommand(string $command, array $parameters = []): self return $this; } + /** + * @return $this + */ + private function addPlatformProvider(string $path = 'app/Orchid/PlatformProvider.php'): self + { + if ($this->option('without-examples')) { + return $this; + } + + $this->info('Adding PlatformProvider'); + + $platform_provider = file_get_contents(Dashboard::path('stubs/examples/Orchid/PlatformProvider.php')); + file_put_contents(base_path($path), $platform_provider); + + return $this; + } + + /** + * @return $this + */ + private function addRoutes(string $path = 'routes/platform.php'): self + { + $this->info('Adding routes'); + + if ($this->option('without-examples')) { + $source_path = 'stubs/app/routes/platform.stub'; + } else { + $source_path = 'stubs/examples/routes/platform.stub'; + } + + $platform_routes = file_get_contents(Dashboard::path($source_path)); + file_put_contents(base_path($path), $platform_routes); + + return $this; + } + /** * @return $this */ diff --git a/src/Platform/Providers/ConsoleServiceProvider.php b/src/Platform/Providers/ConsoleServiceProvider.php index 4a583668b0..1438ca217d 100644 --- a/src/Platform/Providers/ConsoleServiceProvider.php +++ b/src/Platform/Providers/ConsoleServiceProvider.php @@ -60,6 +60,7 @@ public function boot(): void ->registerTranslationsPublisher() ->registerConfigPublisher() ->registerOrchidPublisher() + ->registerExamplesPublisher() ->registerViewsPublisher() ->registerAssetsPublisher() ->commands($this->commands); @@ -129,13 +130,27 @@ protected function registerConfigPublisher(): self protected function registerOrchidPublisher(): self { $this->publishes([ - Dashboard::path('stubs/app/routes/') => base_path('routes'), Dashboard::path('stubs/app/Orchid/') => app_path('Orchid'), ], 'orchid-app-stubs'); return $this; } + /** + * Register examples. + * + * @return $this + */ + protected function registerExamplesPublisher(): self + { + $this->publishes([ + Dashboard::path('stubs/examples/Orchid/Layouts/') => app_path('Orchid/Layouts'), + Dashboard::path('stubs/examples/Orchid/Screens/') => app_path('Orchid/Screens'), + ], 'orchid-examples'); + + return $this; + } + /** * Register the asset publishing configuration. * diff --git a/stubs/app/Orchid/PlatformProvider.php b/stubs/app/Orchid/PlatformProvider.php index adaabc9556..3c8c89ad36 100644 --- a/stubs/app/Orchid/PlatformProvider.php +++ b/stubs/app/Orchid/PlatformProvider.php @@ -8,7 +8,6 @@ use Orchid\Platform\ItemPermission; use Orchid\Platform\OrchidServiceProvider; use Orchid\Screen\Actions\Menu; -use Orchid\Support\Color; class PlatformProvider extends OrchidServiceProvider { @@ -39,33 +38,6 @@ public function menu(): array ->title('Navigation') ->route(config('platform.index')), - Menu::make('Sample Screen') - ->icon('bs.collection') - ->route('platform.example') - ->badge(fn () => 6), - - Menu::make('Form Elements') - ->icon('bs.card-list') - ->route('platform.example.fields') - ->active('*/examples/form/*'), - - Menu::make('Layouts Overview') - ->icon('bs.window-sidebar') - ->route('platform.example.layouts'), - - Menu::make('Grid System') - ->icon('bs.columns-gap') - ->route('platform.example.grid'), - - Menu::make('Charts') - ->icon('bs.bar-chart') - ->route('platform.example.charts'), - - Menu::make('Cards') - ->icon('bs.card-text') - ->route('platform.example.cards') - ->divider(), - Menu::make(__('Users')) ->icon('bs.people') ->route('platform.systems.users') @@ -75,20 +47,7 @@ public function menu(): array Menu::make(__('Roles')) ->icon('bs.shield') ->route('platform.systems.roles') - ->permission('platform.systems.roles') - ->divider(), - - Menu::make('Documentation') - ->title('Docs') - ->icon('bs.box-arrow-up-right') - ->url('https://orchid.software/en/docs') - ->target('_blank'), - - Menu::make('Changelog') - ->icon('bs.box-arrow-up-right') - ->url('https://github.com/orchidsoftware/platform/blob/master/CHANGELOG.md') - ->target('_blank') - ->badge(fn () => Dashboard::version(), Color::DARK), + ->permission('platform.systems.roles'), ]; } diff --git a/stubs/app/routes/platform.stub b/stubs/app/routes/platform.stub new file mode 100644 index 0000000000..13bdddbeec --- /dev/null +++ b/stubs/app/routes/platform.stub @@ -0,0 +1,76 @@ +name('platform.main'); + +// Platform > Profile +Route::screen('profile', UserProfileScreen::class) + ->name('platform.profile') + ->breadcrumbs(fn (Trail $trail) => $trail + ->parent('platform.index') + ->push(__('Profile'), route('platform.profile'))); + +// Platform > System > Users > User +Route::screen('users/{user}/edit', UserEditScreen::class) + ->name('platform.systems.users.edit') + ->breadcrumbs(fn (Trail $trail, $user) => $trail + ->parent('platform.systems.users') + ->push($user->name, route('platform.systems.users.edit', $user))); + +// Platform > System > Users > Create +Route::screen('users/create', UserEditScreen::class) + ->name('platform.systems.users.create') + ->breadcrumbs(fn (Trail $trail) => $trail + ->parent('platform.systems.users') + ->push(__('Create'), route('platform.systems.users.create'))); + +// Platform > System > Users +Route::screen('users', UserListScreen::class) + ->name('platform.systems.users') + ->breadcrumbs(fn (Trail $trail) => $trail + ->parent('platform.index') + ->push(__('Users'), route('platform.systems.users'))); + +// Platform > System > Roles > Role +Route::screen('roles/{role}/edit', RoleEditScreen::class) + ->name('platform.systems.roles.edit') + ->breadcrumbs(fn (Trail $trail, $role) => $trail + ->parent('platform.systems.roles') + ->push($role->name, route('platform.systems.roles.edit', $role))); + +// Platform > System > Roles > Create +Route::screen('roles/create', RoleEditScreen::class) + ->name('platform.systems.roles.create') + ->breadcrumbs(fn (Trail $trail) => $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(fn (Trail $trail) => $trail + ->parent('platform.index') + ->push(__('Roles'), route('platform.systems.roles'))); diff --git a/stubs/app/Orchid/Layouts/Examples/ChartBarExample.php b/stubs/examples/Orchid/Layouts/Examples/ChartBarExample.php similarity index 100% rename from stubs/app/Orchid/Layouts/Examples/ChartBarExample.php rename to stubs/examples/Orchid/Layouts/Examples/ChartBarExample.php diff --git a/stubs/app/Orchid/Layouts/Examples/ChartLineExample.php b/stubs/examples/Orchid/Layouts/Examples/ChartLineExample.php similarity index 100% rename from stubs/app/Orchid/Layouts/Examples/ChartLineExample.php rename to stubs/examples/Orchid/Layouts/Examples/ChartLineExample.php diff --git a/stubs/app/Orchid/Layouts/Examples/ChartPercentageExample.php b/stubs/examples/Orchid/Layouts/Examples/ChartPercentageExample.php similarity index 100% rename from stubs/app/Orchid/Layouts/Examples/ChartPercentageExample.php rename to stubs/examples/Orchid/Layouts/Examples/ChartPercentageExample.php diff --git a/stubs/app/Orchid/Layouts/Examples/ChartPieExample.php b/stubs/examples/Orchid/Layouts/Examples/ChartPieExample.php similarity index 100% rename from stubs/app/Orchid/Layouts/Examples/ChartPieExample.php rename to stubs/examples/Orchid/Layouts/Examples/ChartPieExample.php diff --git a/stubs/app/Orchid/Layouts/Examples/ExampleElements.php b/stubs/examples/Orchid/Layouts/Examples/ExampleElements.php similarity index 100% rename from stubs/app/Orchid/Layouts/Examples/ExampleElements.php rename to stubs/examples/Orchid/Layouts/Examples/ExampleElements.php diff --git a/stubs/app/Orchid/Layouts/Examples/TabMenuExample.php b/stubs/examples/Orchid/Layouts/Examples/TabMenuExample.php similarity index 100% rename from stubs/app/Orchid/Layouts/Examples/TabMenuExample.php rename to stubs/examples/Orchid/Layouts/Examples/TabMenuExample.php diff --git a/stubs/examples/Orchid/PlatformProvider.php b/stubs/examples/Orchid/PlatformProvider.php new file mode 100644 index 0000000000..f49a20b9ce --- /dev/null +++ b/stubs/examples/Orchid/PlatformProvider.php @@ -0,0 +1,108 @@ +icon('bs.book') + ->title('Navigation') + ->route(config('platform.index')), + + Menu::make('Sample Screen') + ->icon('bs.collection') + ->route('platform.example') + ->badge(fn () => 6), + + Menu::make('Form Elements') + ->icon('bs.card-list') + ->route('platform.example.fields') + ->active('*/examples/form/*'), + + Menu::make('Overview Layouts') + ->icon('bs.window-sidebar') + ->route('platform.example.layouts'), + + Menu::make('Grid System') + ->icon('bs.columns-gap') + ->route('platform.example.grid'), + + Menu::make('Charts') + ->icon('bs.bar-chart') + ->route('platform.example.charts'), + + Menu::make('Cards') + ->icon('bs.card-text') + ->route('platform.example.cards') + ->divider(), + + Menu::make(__('Users')) + ->icon('bs.people') + ->route('platform.systems.users') + ->permission('platform.systems.users') + ->title(__('Access Controls')), + + Menu::make(__('Roles')) + ->icon('bs.shield') + ->route('platform.systems.roles') + ->permission('platform.systems.roles') + ->divider(), + + Menu::make('Documentation') + ->title('Docs') + ->icon('bs.box-arrow-up-right') + ->url('https://orchid.software/en/docs') + ->target('_blank'), + + Menu::make('Changelog') + ->icon('bs.box-arrow-up-right') + ->url('https://github.com/orchidsoftware/platform/blob/master/CHANGELOG.md') + ->target('_blank') + ->badge(fn () => Dashboard::version(), Color::DARK), + ]; + } + + /** + * Register permissions for the application. + * + * @return ItemPermission[] + */ + public function permissions(): array + { + return [ + ItemPermission::group(__('System')) + ->addPermission('platform.systems.roles', __('Roles')) + ->addPermission('platform.systems.users', __('Users')), + ]; + } +} diff --git a/stubs/app/Orchid/Screens/Examples/ExampleActionsScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleActionsScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleActionsScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleActionsScreen.php diff --git a/stubs/app/Orchid/Screens/Examples/ExampleCardsScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleCardsScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleCardsScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleCardsScreen.php diff --git a/stubs/app/Orchid/Screens/Examples/ExampleChartsScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleChartsScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleChartsScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleChartsScreen.php diff --git a/stubs/app/Orchid/Screens/Examples/ExampleFieldsAdvancedScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleFieldsAdvancedScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleFieldsAdvancedScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleFieldsAdvancedScreen.php diff --git a/stubs/app/Orchid/Screens/Examples/ExampleFieldsScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleFieldsScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleFieldsScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleFieldsScreen.php diff --git a/stubs/app/Orchid/Screens/Examples/ExampleGridScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleGridScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleGridScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleGridScreen.php diff --git a/stubs/app/Orchid/Screens/Examples/ExampleLayoutsScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleLayoutsScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleLayoutsScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleLayoutsScreen.php diff --git a/stubs/app/Orchid/Screens/Examples/ExampleScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleScreen.php diff --git a/stubs/app/Orchid/Screens/Examples/ExampleTextEditorsScreen.php b/stubs/examples/Orchid/Screens/Examples/ExampleTextEditorsScreen.php similarity index 100% rename from stubs/app/Orchid/Screens/Examples/ExampleTextEditorsScreen.php rename to stubs/examples/Orchid/Screens/Examples/ExampleTextEditorsScreen.php diff --git a/stubs/app/routes/platform.php b/stubs/examples/routes/platform.stub similarity index 100% rename from stubs/app/routes/platform.php rename to stubs/examples/routes/platform.stub