codicastudio / menu-manager
一个随机的 Codica Studio 包。
Requires
- php: ^7.4 || ^8.0
- dev-master
- 1.0.0
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/qs-and-express-6.11.0
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-1.4.2
- dev-dependabot/npm_and_yarn/minimatch-3.1.2
- dev-dependabot/npm_and_yarn/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/async-2.6.4
- dev-dependabot/npm_and_yarn/minimist-1.2.6
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/follow-redirects-1.14.8
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/ws-6.2.2
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/browserslist-4.16.6
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/npm_and_yarn/ssri-6.0.2
- dev-dependabot/npm_and_yarn/y18n-4.0.1
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/ini-1.3.8
This package is auto-updated.
Last update: 2024-09-06 18:17:05 UTC
README
提供一种简单的方式来对侧边栏上的资源进行排序和分组。
安装
您可以通过 composer 安装此包
composer require digital-creative/collapsible-resource-manager
接下来,您必须使用 Nova 注册该工具。这通常在 NovaServiceProvider
的 tools
方法中完成。
class NovaServiceProvider extends NovaApplicationServiceProvider { public function tools() { return [ // ... new CollapsibleResourceManager([ 'navigation' => [ TopLevelResource::make([ 'label' => 'Resources', 'resources' => [ \App\Nova\User::class ] ]), ] ]) ]; } }
选项
new CollapsibleResourceManager([ 'disable_default_resource_manager' => true, // default 'remember_menu_state' => false, // default 'navigation' => [ TopLevelResource::make(...), TopLevelResource::make(...) ] ]);
在 navigation
键中,仅允许使用 TopLevelResource
,任何其他资源都将被忽略。
导航资源
顶级资源
TopLevelResource::make([ 'label' => 'Resources', 'expanded' => null, 'badge' => null, 'icon' => null, 'linkTo' => null, // accepts an instance of `NovaResource` or a Nova `Resource::class` 'resources' => [ NovaResource::make(...), Group::make(...), LensResource::make(...), InternalLink::make(...), ExternalLink::make(...), RawResource::make(...) ] ]);
默认情况下,顶级项不可折叠('expanded' => null
)。如果您将 expanded
设置为 true
或 false
,则将在标题的右侧显示可折叠指示器。如果为 true
,则默认展开,如果为 false
,则默认折叠。
Nova 资源
您可以通过传递 \App\Nova\Resource::class
或 NovaResource
的实例来传递
NovaResource::make(\App\Nova\Customer::class);
您还可以通过链式调用这些方法之一将用户重定向到特定视图
NovaResource::make(\App\Nova\Customer::class)->index(); // Open the create index for the given resource - default NovaResource::make(\App\Nova\Customer::class)->create(); // Open the create view for the given resource NovaResource::make(\App\Nova\Customer::class)->detail($resourceId); // Open the detail view for the given ID NovaResource::make(\App\Nova\Customer::class)->edit($resourceId); // Open the form view of the given ID
还尊重每个视图的授权
分组
分组以切换形式出现,带有 +/- 符号,允许用户将多个项目折叠到侧边栏上的单个条目中
Group::make([ 'label' => 'Admin', 'expanded' => false, 'resources' => [ // any resource instance ] ]);
内部链接
内部链接是一种通过默认导航机制手动将用户重定向到特定 URL 的简单方法
InternalLink::make([ 'label' => 'My custom internal link', 'badge' => null, 'icon' => null, 'target' => '_self', 'path' => '/my/custom/resource/url', 'params' => [ 'resourceId' => 1 ], 'query' => [' resource_per_page' => 100 ] ]);
透镜资源
透镜资源是一种快速将条目添加到侧边栏的方法,该条目将用户直接重定向到特定资源的透镜视图
它需要两个参数:透镜所使用的资源以及您要链接到的透镜类本身
LensResource::make( \App\Nova\Customer::class, \App\Nova\Lenses\MostValuableCustomers::class );
外部链接
外部链接非常有用,可以添加到菜单中,将用户重定向到外部 URL
ExternalLink::make([ 'label' => 'Google', 'badge' => null, 'icon' => null, 'target' => '_blank', 'url' => 'https://google.com.br' ]);
原始资源
如果所有预配置的资源都不满足您的需求,原始资源提供了一种手动定义应构建哪些参数的方法
RawResource::make([ 'label' => 'Customer', 'badge' => null, 'icon' => null, 'target' => '_self', 'name' => 'index', 'path' => null, 'params' => [ 'resourceName' => 'customer' ], 'query' => [ 'foo' => 'bar' ], ]);
授权
所有资源都使用 AuthorizedToSee
nova 特性,因此它们的行为类似于工具和卡片,您可以在其中链式调用 canSee
以确定当前登录用户是否有权查看资源。
Group::make(...)->canSee(function($request) { return true/false; });
默认情况下,NovaResource
将遵循为给定资源注册的默认策略,但可以通过链式调用 ->canSee()
手动覆盖。
资源标签和翻译
您可以通过调用 ->label()
方法将翻译标签传递给任何资源,例如
NovaResource::make(\App\Nova\Customer::class)->label(function() { return __('Customer'); }); // or NovaResource::make(\App\Nova\Customer::class)->label(__('Customer'));
资源图标
您可以通过以下方式为 NovaResource
定义图标
- 在
NovaResource
上调用->icon()
方法,它接受一个返回string
的Closure
或直接返回一个string
- 在资源类上设置一个名为
icon
的静态方法,该方法返回一个string
class Customer extends Resource { //... public static function icon(): string { return <<<SVG <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"> <path fill="currentColor" d="M11.21 11.99c0-.87-.31-1.62-.93-2.23-.61-.62-1.36-.93-2.23-.93s-1.62.31-2.23.93c-.62.62-.93 1.36-.93 2.23 0 .87.31 1.62.93 2.23.62.62 1.36.93 2.23.93s1.62-.31 2.23-.93c.62-.61.93-1.35.93-2.23zm9.48 6.32c0-.43-.16-.8-.47-1.11a1.52 1.52 0 00-1.11-.47c-.43 0-.8.16-1.11.47-.31.31-.47.68-.47 1.11 0 .44.15.81.46 1.12.31.31.68.46 1.12.46.44 0 .81-.15 1.12-.46s.46-.68.46-1.12zm0-12.64c0-.43-.16-.8-.47-1.11s-.68-.47-1.11-.47c-.43 0-.8.16-1.11.47s-.47.68-.47 1.11c0 .44.15.81.46 1.12.31.31.68.46 1.12.46.44 0 .81-.15 1.12-.46.31-.31.46-.68.46-1.12zm-4.74 5.2v2.28c0 .08-.03.16-.09.24-.06.08-.12.12-.2.13l-1.91.3c-.09.29-.22.6-.4.94.28.4.65.87 1.11 1.42.06.09.09.17.09.25 0 .1-.03.18-.09.23-.19.25-.53.62-1.02 1.1-.49.49-.81.73-.97.73-.09 0-.18-.03-.26-.09l-1.41-1.1c-.3.16-.62.28-.95.38-.09.89-.19 1.53-.28 1.91-.06.2-.18.3-.37.3H6.9c-.09 0-.17-.03-.25-.09-.07-.06-.12-.13-.12-.22l-.28-1.88c-.28-.08-.59-.21-.93-.38l-1.46 1.1c-.06.06-.14.09-.25.09-.09 0-.18-.03-.26-.1-1.19-1.09-1.78-1.75-1.78-1.98 0-.07.03-.15.09-.23.08-.12.25-.33.51-.65s.45-.57.58-.75c-.19-.36-.33-.7-.43-1.01l-1.88-.3c-.08-.01-.15-.05-.21-.12s-.09-.15-.09-.24v-2.28c0-.08.03-.16.09-.24.06-.08.12-.12.2-.13l1.91-.3c.09-.29.22-.6.4-.94-.28-.4-.65-.87-1.11-1.42a.507.507 0 01-.09-.26c0-.1.03-.18.09-.25.18-.25.52-.61 1.01-1.1s.82-.73.98-.73c.09 0 .18.03.26.09L5.3 6.69c.28-.15.6-.28.95-.4.09-.89.19-1.52.28-1.9.06-.2.18-.3.37-.3h2.3c.09 0 .17.03.25.09.07.07.11.14.12.22l.28 1.89c.28.08.59.21.93.38l1.46-1.1c.07-.06.15-.09.25-.09.09 0 .18.03.26.1 1.19 1.09 1.78 1.75 1.78 1.98 0 .07-.03.14-.09.23-.1.13-.27.35-.52.67-.25.31-.43.56-.56.74.19.4.33.73.42 1.01l1.88.28c.08.02.15.06.21.13.05.08.08.16.08.25zm7.9 6.58v1.73c0 .13-.61.26-1.84.38-.1.22-.22.44-.37.64.42.93.63 1.5.63 1.7 0 .03-.02.06-.05.09-1 .58-1.51.88-1.53.88-.07 0-.26-.19-.57-.58-.31-.39-.53-.67-.64-.84-.16.02-.29.02-.37.02-.08 0-.21-.01-.37-.02-.12.17-.33.45-.64.84-.31.39-.5.58-.57.58-.02 0-.53-.29-1.53-.88a.105.105 0 01-.05-.09c0-.21.21-.77.63-1.7a3.78 3.78 0 01-.37-.64c-1.23-.12-1.84-.25-1.84-.38v-1.73c0-.13.61-.26 1.84-.38.11-.24.23-.45.37-.64-.42-.93-.63-1.5-.63-1.7 0-.03.02-.06.05-.09.03-.02.18-.1.43-.25.26-.15.5-.29.73-.42.23-.13.35-.2.37-.2.07 0 .26.19.57.57s.53.66.64.83c.16-.02.29-.02.37-.02.08 0 .21.01.37.02.42-.58.8-1.05 1.14-1.38l.07-.02c.03 0 .54.29 1.53.86.03.02.05.05.05.09 0 .21-.21.77-.63 1.7.14.19.26.4.37.64 1.23.13 1.84.26 1.84.39zm0-12.64v1.73c0 .13-.61.26-1.84.38-.1.22-.22.44-.37.64.42.93.63 1.5.63 1.7 0 .03-.02.06-.05.09-1 .58-1.51.88-1.53.88-.07 0-.26-.19-.57-.58s-.53-.67-.64-.84c-.16.02-.29.02-.37.02-.08 0-.21-.01-.37-.02-.12.17-.33.45-.64.84s-.5.58-.57.58c-.02 0-.53-.29-1.53-.88a.105.105 0 01-.05-.09c0-.21.21-.77.63-1.7a3.78 3.78 0 01-.37-.64c-1.23-.12-1.84-.25-1.84-.38V4.81c0-.13.61-.26 1.84-.38.11-.24.23-.45.37-.64-.42-.93-.63-1.5-.63-1.7 0-.03.02-.06.05-.09.03-.02.18-.1.43-.25.26-.15.5-.29.73-.42.23-.13.35-.2.37-.2.07 0 .26.19.57.57s.53.66.64.83c.16-.02.29-.02.37-.02.08 0 .21.01.37.02.42-.58.8-1.05 1.14-1.38l.07-.02c.03 0 .54.29 1.53.86.03.02.05.05.05.09 0 .21-.21.77-.63 1.7.14.19.26.4.37.64 1.23.13 1.84.26 1.84.39z"/> </svg> SVG; } }
对于 LensResource
,静态图标方法应在透镜类上定义,而不是在资源类上定义
对于不接受类字符串作为配置的所有其他资源,可以通过传递图标密钥或通过调用 ->icon()
到资源本身来设置图标,例如
ExternalLink::make([ ... 'icon' => function() { return '<svg>...</svg>' }, // or 'icon' => '<svg>...</svg>', ]); ExternalLink::make(...)->icon(function() { return '<svg>...</svg>' }); // or ExternalLink::make(...)->icon('<svg>...</svg>');
许可
MIT 许可证(MIT)。有关更多信息,请参阅许可文件