Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install without examples #2792

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/Platform/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class InstallCommand extends Command
*
* @var string
*/
protected $signature = 'orchid:install';
protected $signature = 'orchid:install
{--without-examples : Install without examples}';

/**
* The console command description.
Expand All @@ -44,10 +45,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()
->setValueEnv('SCOUT_DRIVER')
->showMeLove();
Expand Down Expand Up @@ -80,6 +84,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
*/
Expand Down
17 changes: 16 additions & 1 deletion src/Platform/Providers/ConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function boot(): void
->registerTranslationsPublisher()
->registerConfigPublisher()
->registerOrchidPublisher()
->registerExamplesPublisher()
->registerViewsPublisher()
->registerAssetsPublisher()
->commands($this->commands);
Expand Down Expand Up @@ -125,13 +126,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.
*
Expand Down
43 changes: 1 addition & 42 deletions stubs/app/Orchid/PlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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('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')
Expand All @@ -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'),
];
}

Expand Down
76 changes: 76 additions & 0 deletions stubs/app/routes/platform.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

use App\Orchid\Screens\PlatformScreen;
use App\Orchid\Screens\Role\RoleEditScreen;
use App\Orchid\Screens\Role\RoleListScreen;
use App\Orchid\Screens\User\UserEditScreen;
use App\Orchid\Screens\User\UserListScreen;
use App\Orchid\Screens\User\UserProfileScreen;
use Illuminate\Support\Facades\Route;
use Tabuna\Breadcrumbs\Trail;

/*
|--------------------------------------------------------------------------
| Dashboard Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the need "dashboard" middleware group. Now create something great!
|
*/

// Main
Route::screen('/main', PlatformScreen::class)
->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')));
108 changes: 108 additions & 0 deletions stubs/examples/Orchid/PlatformProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

declare(strict_types=1);

namespace App\Orchid;

use Orchid\Platform\Dashboard;
use Orchid\Platform\ItemPermission;
use Orchid\Platform\OrchidServiceProvider;
use Orchid\Screen\Actions\Menu;
use Orchid\Support\Color;

class PlatformProvider extends OrchidServiceProvider
{
/**
* Bootstrap the application services.
*
* @param Dashboard $dashboard
*
* @return void
*/
public function boot(Dashboard $dashboard): void
{
parent::boot($dashboard);

// ...
}

/**
* Register the application menu.
*
* @return Menu[]
*/
public function menu(): array
{
return [
Menu::make('Get Started')
->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')),
];
}
}
File renamed without changes.
Loading