chapcz/chap-adminlte

管理控制

安装: 137

依赖: 0

建议者: 0

安全: 0

星标: 5

关注者: 4

分支: 2

开放问题: 2

语言:CSS

类型:项目

2.1.6 2023-09-01 18:31 UTC

README

此扩展简化了创建管理控制的过程。

功能

  • 易于安装和使用
  • 包含脚本和样式
  • 简单使用多个通知面板
  • 翻译
  • 准备好的登录控制
  • PHP 7.2 严格模式
  • PHPStan 级别 7
  • 可作为 Nette 扩展配置
  • 在 neon 中可配置菜单树(也包括用户限制)

用法

要使用此扩展,请在 Composer 中要求它

composer require chapcz/chap-adminlte

最小设置

extensions:
	admin: Chap\AdminLTE\DI\Extension

admin:
	
	menu:
		-
			name: "Home"
			link: "Admin:"
			icon: "fa-files-o"
			resource: "home"
			privilege: "view"
		-
			name: "Dvaaa"
			icon: "fa-pie-chart"
			role: "user"
			items:
				-
					name: Boo
					link: "Admin:boo"
					icon: fa-trip
				-
					name: Foo
					link: "Admin:foo"
					icon: fa-trip
					items:
					    -
					        name: Hoo
					        link: "Admin:hoo"
					        icon: fa-trip

带有面板和搜索回调的示例

表示者

<?php declare(strict_types=1);

namespace Chap\AdminModule\Presenters;

use Chap\AdminLTE\AdminControl;
use Chap\AdminLTE\IAdminControlFactory;
use Chap\AdminLTE\Notifications\MessagePanel;
use Chap\AdminLTE\Notifications\NotificationPanel;
use Chap\AdminLTE\Notifications\TaskPanel;
use Nette\Application\UI\Presenter;
use Nette\Application\UI\Form;

class AdminPresenter extends Presenter
{
    /**
     * @var IAdminControlFactory
     */
    private $adminControlFactory;

    public function __construct(IAdminControlFactory $adminControlFactory)
    {
        parent::__construct();
        $this->adminControlFactory = $adminControlFactory;
    }

    /**
     * @return AdminControl
     */
    protected function createComponentAdmin(): AdminControl
    {
        $admin = $this->adminControlFactory
            ->create()
            ->addPanel($this->getExampleNotificationsPanel())
            ->addPanel($this->getExampleTasksPanel())
            ->addPanel($this->getMessagesPanel());

        $admin->onSearch[] = function (Form $form): void {
            $this->redirect('search', ['word' => $form->getValues()['q']]);
        };

        return $admin;
    }

    private function getExampleNotificationsPanel() :NotificationPanel
    {
        return (new NotificationPanel())
            ->setLinkAll('#')
            ->setCounter(50)
            ->setHeaderTitle('%d Notifications')
            ->addNotification('#', 'Something')
            ->addNotification('#', 'Something')
            ->addNotification('#', 'Something')
            ->addNotification('#', 'Something')
            ->addNotification('#', 'Something')
            ->addNotification('#', 'Something')
            ->addNotification('#', 'Something')
            ;
    }

    private function getMessagesPanel() :MessagePanel
    {
        return (new MessagePanel())
            ->setLinkAll('#')
            ->setCounter(2)
            ->setHeaderTitle('%d messages')
            ->addMessage('#', 'Hallo', 'world !', '/image/avatar.png', '2 hours ago')
            ->addMessage('#', 'This', 'is message', '/image/avatar.png', '3 hours ago');
    }

    private function getExampleTasksPanel() :TaskPanel
    {
        $panel = (new TaskPanel())
            ->setLinkAll('#')
            ->setCounter(0)
            ->setHeaderTitle(null);

        for ($i = 1; $i <= 10; $i++ ) {
            $panel->addTask('#', 'My task ' . $i, $i*10);
        }

        return $panel;
    }

    /**
     * @param $word
     */
    public function actionSearch(string $word): void
    {
        $this->flashMessage('Looking for: ' . $word, 'danger');
    }
}

@layout.latte

{capture $content}{include content}{/capture}

{control admin $content, $flashes}

##模态框:对于具有模态属性的 a 标签,将在模态窗口中显示 "no-layout" 结果。

<a n:href="edit" class="btn btn-success" modal>Add user</a>

组件

懒加载屏幕(在演示网站上显示)
    protected function createComponentSlowScreen(): SlowComponent
    {
        return $this->slowComponentFactory->create();
    }

    // Component with slow response (reading remote data, compute something) 
    protected function createComponentSlowScreenLazyLoaded(): LazyScreen
    {
        return new LazyScreen(function () {
            return $this->slowComponentFactory->create();
        });
    }
操作按钮(在演示网站上显示)

有时添加一些与视图相关的操作是有用的(例如,在产品详情编辑、发送、分配等情况下)。

    public function renderDetail(): void
    {
        $this['admin']->addActionButton(Button::builder()->typeWarning()
            ->link($this->link('this#test'))->faIcon('eye')->build());
        $this['admin']->addActionButton(Button::builder()->typeInfo()
            ->link($this->link('this#test2'))->faIcon('cog')->build());
        $this['admin']->addDropdownLink(new DropLink('', 'link'));
    }
信息板(在演示网站上显示)

为了仪表板的目的,我们可以显示一些包含有用信息的信息框。

    protected function createComponentDashBoard(): InfoBoard
    {
        return (new InfoBoard())
            ->setColSpan(6)
            ->addBox((new InfoBox())
                ->setColor('red')
                ->setLink('#')
                ->setIcon('pencil')
                ->setNumber(1222)
                ->setProgress(90)
                ->setText('Pencil text')
            )
            ->addBox((new InfoBox())
                ->setColor('green')
                ->setIcon('globe')
                ->setText('Globe text')
                ->setNumber((float) random_int(0, 9999))
            );
    }

待办事项

  • 改进菜单控制和嵌套项目的更好授权
  • 更多示例

灵感