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

[3.x] Spa #1076

Draft
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Draft
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
46 changes: 26 additions & 20 deletions src/Laravel/Layouts/AppLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
namespace MoonShine\Laravel\Layouts;

use MoonShine\Laravel\Components\Layout\{Flash, Locales, Notifications, Profile, Search};
use MoonShine\Laravel\Components\Fragment;
use MoonShine\Laravel\Resources\MoonShineUserResource;
use MoonShine\Laravel\Resources\MoonShineUserRoleResource;
use MoonShine\MenuManager\MenuGroup;
use MoonShine\MenuManager\MenuItem;
use MoonShine\UI\Components\{Breadcrumbs,
use MoonShine\UI\Components\{ActionButton,
Breadcrumbs,
Components,
Layout\Block,
Layout\Body,
Expand All @@ -27,6 +29,8 @@
Layout\Wrapper,
Title,
When};
use MoonShine\Support\AlpineJs;
use MoonShine\Support\Enums\JsEvent;
use MoonShine\UI\MoonShineLayout;

class AppLayout extends MoonShineLayout
Expand All @@ -38,11 +42,11 @@ protected function menu(): array
MenuItem::make(
static fn () => __('moonshine::ui.resource.admins_title'),
moonshine()->getContainer(MoonShineUserResource::class)
),
)->spa(),
MenuItem::make(
static fn () => __('moonshine::ui.resource.role_title'),
moonshine()->getContainer(MoonShineUserRoleResource::class)
),
)->spa(),
]),
];
}
Expand Down Expand Up @@ -91,28 +95,30 @@ public function build(): LayoutBuilder
])->collapsed(),

Block::make([
Flash::make(),
Header::make([
Breadcrumbs::make($this->getPage()->getBreadcrumbs())
->prepend(moonshineRouter()->getEndpoints()->home(), icon: 'home'),
Fragment::make([
Flash::make(),
Header::make([
Breadcrumbs::make($this->getPage()->getBreadcrumbs())
->prepend(moonshineRouter()->getEndpoints()->home(), icon: 'home'),

Search::make(),
Search::make(),

When::make(
static fn (): bool => moonshineConfig()->isAuthEnabled() && moonshineConfig()->isUseNotifications(),
static fn (): array => [Notifications::make()]
),
When::make(
static fn (): bool => moonshineConfig()->isAuthEnabled() && moonshineConfig()->isUseNotifications(),
static fn (): array => [Notifications::make()]
),

Locales::make(),
]),
Locales::make(),
]),

Content::make([
Title::make($this->getPage()->getTitle())->class('mb-6'),
Content::make([
Title::make($this->getPage()->getTitle())->class('mb-6'),

Components::make(
$this->getPage()->getComponents()
),
]),
Components::make(
$this->getPage()->getComponents()
),
]),
])->name('_content')->customAttributes(['id' => 'content']),

Footer::make()
->copyright(static fn (): string => sprintf(
Expand Down
29 changes: 16 additions & 13 deletions src/Laravel/Layouts/CompactLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Layout\TopBar,
Layout\Wrapper,
When};
use MoonShine\Laravel\Components\Fragment;

class CompactLayout extends AppLayout
{
Expand Down Expand Up @@ -158,23 +159,25 @@ public function build(): LayoutBuilder
]),
])->collapsed(),
Block::make([
Flash::make(),
Header::make([
Breadcrumbs::make($this->getPage()->getBreadcrumbs())
->prepend(moonshineRouter()->getEndpoints()->home(), icon: 'home'),
Fragment::make([
Flash::make(),
Header::make([
Breadcrumbs::make($this->getPage()->getBreadcrumbs())
->prepend(moonshineRouter()->getEndpoints()->home(), icon: 'home'),

Search::make(),
Search::make(),

Notifications::make(),
Notifications::make(),

Locales::make(),
]),
Locales::make(),
]),

Content::make([
Components::make(
$this->getPage()->getComponents()
),
]),
Content::make([
Components::make(
$this->getPage()->getComponents()
),
]),
])->name('_content')->customAttributes(['id' => 'content']),

Footer::make()
->copyright(static fn (): string => sprintf(
Expand Down
14 changes: 14 additions & 0 deletions src/Laravel/Providers/MoonShineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@
use MoonShine\Laravel\MoonShineConfigurator;
use MoonShine\Laravel\MoonShineRequest;
use MoonShine\Laravel\Resources\ModelResource;
use MoonShine\Laravel\Resources\MoonShineUserRoleResource;
use MoonShine\Laravel\Storage\LaravelStorage;
use MoonShine\MenuManager\MenuItem;
use MoonShine\MenuManager\MenuManager;
use MoonShine\MoonShine;
use MoonShine\Support\Enums\Env;
use MoonShine\UI\Applies\AppliesRegister;
use MoonShine\UI\Components\ActionButton;
use MoonShine\UI\Contracts\Collections\FieldsCollection;
use MoonShine\UI\Fields\Checkbox;
use MoonShine\UI\Fields\Date;
Expand Down Expand Up @@ -181,6 +184,17 @@ protected function registerBindings(): self
old: static fn (string $key, mixed $default) => session()->getOldInput($key, $default)
));

MenuItem::macro('spa', function () {
/** @var ModelResource $filler */
$filler = value($this->getFiller());

return $this->setUrl(
fn() => $filler->getFragmentLoadUrl('_content')
)->changeButton(
static fn(ActionButton $btn) => $btn->async(selector: '#content')
);
});

return $this;
}

Expand Down
9 changes: 7 additions & 2 deletions src/Laravel/Traits/Resource/ResourceModelCrudRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MoonShine\Laravel\Traits\Resource;

use Illuminate\Database\Eloquent\Model;
use MoonShine\Core\Contracts\PageContract;
use MoonShine\Core\Contracts\ResourceContract;
use MoonShine\Laravel\Pages\Page;
use MoonShine\Support\Enums\PageType;
Expand Down Expand Up @@ -77,10 +78,14 @@ public function getDetailPageUrl(

public function getFragmentLoadUrl(
string $fragment,
Page $page,
Model|int|string|null $model,
?PageContract $page = null,
Model|int|string|null $model = null,
array $params = []
): string {
if(is_null($page)) {
$page = $this->getIndexPage();
}

return $this->getPageUrl(
$page,
params: array_filter([
Expand Down
2 changes: 2 additions & 0 deletions src/MenuManager/MenuElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MoonShine\MenuManager;

use Closure;
use Illuminate\Support\Traits\Macroable;
use MoonShine\Support\Components\MoonShineComponentAttributeBag;
use MoonShine\Support\Traits\HasCanSee;
use MoonShine\Support\Traits\Makeable;
Expand All @@ -17,6 +18,7 @@

abstract class MenuElement implements MoonShineRenderable, HasCanSeeContract
{
use Macroable;
use Makeable;
use WithComponentAttributes;
use WithIcon;
Expand Down
Loading