@@ -7,25 +7,25 @@ |
||
| 7 | 7 | use KielD01\LaravelMaterialDashboardPro\Helpers\MenuItemLinkType; |
| 8 | 8 | |
| 9 | 9 | return [ |
| 10 | - [ |
|
| 11 | - 'title' => 'Dashboard', |
|
| 12 | - 'link' => [ |
|
| 13 | - 'type' => MenuItemLinkType::ROUTE, |
|
| 14 | - 'route' => 'dashboard.index', |
|
| 15 | - ], |
|
| 16 | - 'icon' => [MaterialIcon::class, 'dashboard'], |
|
| 17 | - ], |
|
| 18 | - [ |
|
| 19 | - 'title' => 'Users', |
|
| 20 | - 'icon' => [FontAwesomeIcon::class, 'login'], |
|
| 21 | - 'children' => [ |
|
| 22 | - [ |
|
| 23 | - 'title' => 'Create User', |
|
| 24 | - 'link' => [ |
|
| 25 | - 'type' => MenuItemLinkType::ROUTE, |
|
| 26 | - 'route' => 'users.create', |
|
| 27 | - ], |
|
| 28 | - ] |
|
| 29 | - ] |
|
| 30 | - ], |
|
| 10 | + [ |
|
| 11 | + 'title' => 'Dashboard', |
|
| 12 | + 'link' => [ |
|
| 13 | + 'type' => MenuItemLinkType::ROUTE, |
|
| 14 | + 'route' => 'dashboard.index', |
|
| 15 | + ], |
|
| 16 | + 'icon' => [MaterialIcon::class, 'dashboard'], |
|
| 17 | + ], |
|
| 18 | + [ |
|
| 19 | + 'title' => 'Users', |
|
| 20 | + 'icon' => [FontAwesomeIcon::class, 'login'], |
|
| 21 | + 'children' => [ |
|
| 22 | + [ |
|
| 23 | + 'title' => 'Create User', |
|
| 24 | + 'link' => [ |
|
| 25 | + 'type' => MenuItemLinkType::ROUTE, |
|
| 26 | + 'route' => 'users.create', |
|
| 27 | + ], |
|
| 28 | + ] |
|
| 29 | + ] |
|
| 30 | + ], |
|
| 31 | 31 | ]; |
@@ -11,31 +11,31 @@ |
||
| 11 | 11 | |
| 12 | 12 | class TestAuthController extends Controller |
| 13 | 13 | { |
| 14 | - public function login(): string |
|
| 15 | - { |
|
| 16 | - return view('mdp::pages.user.login')->render(); |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - public function auth(Request $request): RedirectResponse |
|
| 20 | - { |
|
| 21 | - $credentials = $request->only(['email', 'password']); |
|
| 22 | - [$email, $password] = $credentials; |
|
| 23 | - |
|
| 24 | - $emailCheck = Str::is('[email protected]', $email); |
|
| 25 | - $passwordCheck = Str::is('adminTest!123', $password); |
|
| 26 | - $checksPassed = $emailCheck && $passwordCheck; |
|
| 27 | - |
|
| 28 | - if ($checksPassed) { |
|
| 29 | - return redirect(route('kield01.mdp.dashboard.index')); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - return redirect() |
|
| 33 | - ->back() |
|
| 34 | - ->with($credentials); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function register(): string |
|
| 38 | - { |
|
| 39 | - return view('mdp::pages.user.register')->render(); |
|
| 40 | - } |
|
| 14 | + public function login(): string |
|
| 15 | + { |
|
| 16 | + return view('mdp::pages.user.login')->render(); |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + public function auth(Request $request): RedirectResponse |
|
| 20 | + { |
|
| 21 | + $credentials = $request->only(['email', 'password']); |
|
| 22 | + [$email, $password] = $credentials; |
|
| 23 | + |
|
| 24 | + $emailCheck = Str::is('[email protected]', $email); |
|
| 25 | + $passwordCheck = Str::is('adminTest!123', $password); |
|
| 26 | + $checksPassed = $emailCheck && $passwordCheck; |
|
| 27 | + |
|
| 28 | + if ($checksPassed) { |
|
| 29 | + return redirect(route('kield01.mdp.dashboard.index')); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + return redirect() |
|
| 33 | + ->back() |
|
| 34 | + ->with($credentials); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function register(): string |
|
| 38 | + { |
|
| 39 | + return view('mdp::pages.user.register')->render(); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -17,165 +17,165 @@ |
||
| 17 | 17 | |
| 18 | 18 | class MenuItem |
| 19 | 19 | { |
| 20 | - private Request $request; |
|
| 21 | - private string $title; |
|
| 22 | - private string $menuItemLinkType; |
|
| 23 | - private string $link; |
|
| 24 | - private string $baseLink; |
|
| 25 | - private Icon $icon; |
|
| 26 | - private Collection $children; |
|
| 27 | - private UuidInterface $hash; |
|
| 28 | - private string $abbr; |
|
| 29 | - private bool $isChild; |
|
| 30 | - private array $classes = [ |
|
| 31 | - 'nav-item', |
|
| 32 | - ]; |
|
| 33 | - |
|
| 34 | - public function __construct( |
|
| 35 | - string $title, |
|
| 36 | - string $menuItemLinkType, |
|
| 37 | - string $link, |
|
| 38 | - Icon $icon = null, |
|
| 39 | - array $children = [], |
|
| 40 | - bool $isChild = false |
|
| 41 | - ) |
|
| 42 | - { |
|
| 43 | - $this->title = $title; |
|
| 44 | - $this->menuItemLinkType = $menuItemLinkType; |
|
| 45 | - $this->link = $this->baseLink = $link; |
|
| 46 | - $this->icon = $icon; |
|
| 47 | - $this->children = collect($children); |
|
| 48 | - $this->isChild = $isChild; |
|
| 49 | - $this->hash = Uuid::fromString(md5($this->title)); |
|
| 50 | - $this->request = resolve(Request::class); |
|
| 51 | - |
|
| 52 | - $this->setAbbr(); |
|
| 53 | - $this->setActive(); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - private function setAbbr(): void |
|
| 57 | - { |
|
| 58 | - $words = explode(' ', $this->getTitle()); |
|
| 59 | - |
|
| 60 | - $abbrArray = array_map( |
|
| 61 | - static function ($word) { |
|
| 62 | - $array = mb_str_split($word); |
|
| 63 | - |
|
| 64 | - return current($array); |
|
| 65 | - }, |
|
| 66 | - $words |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - $abbrString = mb_strtoupper(implode('', $abbrArray)); |
|
| 70 | - |
|
| 71 | - $this->abbr = preg_replace( |
|
| 72 | - '/([^0-9A-Za-zА-я])/u', |
|
| 73 | - '', |
|
| 74 | - $abbrString |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function getTitle(): string |
|
| 79 | - { |
|
| 80 | - return $this->title; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - private function setActive(): void |
|
| 84 | - { |
|
| 85 | - /** @var Route $route */ |
|
| 86 | - $route = $this->request->route(); |
|
| 87 | - |
|
| 88 | - if (!is_null($route)) { |
|
| 89 | - switch ($this->menuItemLinkType) { |
|
| 90 | - case MenuItemLinkType::ROUTE: |
|
| 91 | - if ($this->getBaseLink() === $route->getName()) { |
|
| 92 | - $this->classes[] = 'active'; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - break; |
|
| 96 | - case MenuItemLinkType::URI: |
|
| 97 | - $match0 = mb_strpos( |
|
| 98 | - $route->uri(), |
|
| 99 | - $this->getBaseLink() |
|
| 100 | - ) === 0; |
|
| 101 | - |
|
| 102 | - if ($match0) { |
|
| 103 | - $this->classes[] = 'active'; |
|
| 104 | - } |
|
| 105 | - break; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - private function getBaseLink(): string |
|
| 111 | - { |
|
| 112 | - return $this->baseLink; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function getLink(): string |
|
| 116 | - { |
|
| 117 | - $uri = '#'; |
|
| 118 | - |
|
| 119 | - switch ($this->hasChildren()) { |
|
| 120 | - case true: |
|
| 121 | - $uri = sprintf('#%s', $this->getMenuItemHash()); |
|
| 122 | - break; |
|
| 123 | - case false: |
|
| 124 | - switch ($this->menuItemLinkType) { |
|
| 125 | - case MenuItemLinkType::ROUTE: |
|
| 126 | - try { |
|
| 127 | - $uri = route($this->link); |
|
| 128 | - } catch (Throwable $exception) { |
|
| 129 | - Log::error(sprintf('Menu Build Item issue : %s', $exception->getMessage())); |
|
| 130 | - } |
|
| 131 | - break; |
|
| 132 | - case MenuItemLinkType::URI: |
|
| 133 | - $uri = $this->link; |
|
| 134 | - break; |
|
| 135 | - } |
|
| 136 | - break; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $uri; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - public function hasChildren(): bool |
|
| 143 | - { |
|
| 144 | - return $this->children->isNotEmpty(); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - public function getMenuItemHash(): string |
|
| 148 | - { |
|
| 149 | - return $this->hash->toString(); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function hasIcon(): bool |
|
| 153 | - { |
|
| 154 | - return !is_null($this->getIcon()); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function getIcon(): ?Icon |
|
| 158 | - { |
|
| 159 | - return $this->icon; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - public function isChild(): bool |
|
| 163 | - { |
|
| 164 | - return $this->isChild; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - public function getChildren(): Collection |
|
| 168 | - { |
|
| 169 | - return $this->children; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function getAbbr(): string |
|
| 173 | - { |
|
| 174 | - return $this->abbr; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function getClasses(): string |
|
| 178 | - { |
|
| 179 | - return implode(' ', $this->classes); |
|
| 180 | - } |
|
| 20 | + private Request $request; |
|
| 21 | + private string $title; |
|
| 22 | + private string $menuItemLinkType; |
|
| 23 | + private string $link; |
|
| 24 | + private string $baseLink; |
|
| 25 | + private Icon $icon; |
|
| 26 | + private Collection $children; |
|
| 27 | + private UuidInterface $hash; |
|
| 28 | + private string $abbr; |
|
| 29 | + private bool $isChild; |
|
| 30 | + private array $classes = [ |
|
| 31 | + 'nav-item', |
|
| 32 | + ]; |
|
| 33 | + |
|
| 34 | + public function __construct( |
|
| 35 | + string $title, |
|
| 36 | + string $menuItemLinkType, |
|
| 37 | + string $link, |
|
| 38 | + Icon $icon = null, |
|
| 39 | + array $children = [], |
|
| 40 | + bool $isChild = false |
|
| 41 | + ) |
|
| 42 | + { |
|
| 43 | + $this->title = $title; |
|
| 44 | + $this->menuItemLinkType = $menuItemLinkType; |
|
| 45 | + $this->link = $this->baseLink = $link; |
|
| 46 | + $this->icon = $icon; |
|
| 47 | + $this->children = collect($children); |
|
| 48 | + $this->isChild = $isChild; |
|
| 49 | + $this->hash = Uuid::fromString(md5($this->title)); |
|
| 50 | + $this->request = resolve(Request::class); |
|
| 51 | + |
|
| 52 | + $this->setAbbr(); |
|
| 53 | + $this->setActive(); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + private function setAbbr(): void |
|
| 57 | + { |
|
| 58 | + $words = explode(' ', $this->getTitle()); |
|
| 59 | + |
|
| 60 | + $abbrArray = array_map( |
|
| 61 | + static function ($word) { |
|
| 62 | + $array = mb_str_split($word); |
|
| 63 | + |
|
| 64 | + return current($array); |
|
| 65 | + }, |
|
| 66 | + $words |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + $abbrString = mb_strtoupper(implode('', $abbrArray)); |
|
| 70 | + |
|
| 71 | + $this->abbr = preg_replace( |
|
| 72 | + '/([^0-9A-Za-zА-я])/u', |
|
| 73 | + '', |
|
| 74 | + $abbrString |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function getTitle(): string |
|
| 79 | + { |
|
| 80 | + return $this->title; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + private function setActive(): void |
|
| 84 | + { |
|
| 85 | + /** @var Route $route */ |
|
| 86 | + $route = $this->request->route(); |
|
| 87 | + |
|
| 88 | + if (!is_null($route)) { |
|
| 89 | + switch ($this->menuItemLinkType) { |
|
| 90 | + case MenuItemLinkType::ROUTE: |
|
| 91 | + if ($this->getBaseLink() === $route->getName()) { |
|
| 92 | + $this->classes[] = 'active'; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + break; |
|
| 96 | + case MenuItemLinkType::URI: |
|
| 97 | + $match0 = mb_strpos( |
|
| 98 | + $route->uri(), |
|
| 99 | + $this->getBaseLink() |
|
| 100 | + ) === 0; |
|
| 101 | + |
|
| 102 | + if ($match0) { |
|
| 103 | + $this->classes[] = 'active'; |
|
| 104 | + } |
|
| 105 | + break; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + private function getBaseLink(): string |
|
| 111 | + { |
|
| 112 | + return $this->baseLink; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function getLink(): string |
|
| 116 | + { |
|
| 117 | + $uri = '#'; |
|
| 118 | + |
|
| 119 | + switch ($this->hasChildren()) { |
|
| 120 | + case true: |
|
| 121 | + $uri = sprintf('#%s', $this->getMenuItemHash()); |
|
| 122 | + break; |
|
| 123 | + case false: |
|
| 124 | + switch ($this->menuItemLinkType) { |
|
| 125 | + case MenuItemLinkType::ROUTE: |
|
| 126 | + try { |
|
| 127 | + $uri = route($this->link); |
|
| 128 | + } catch (Throwable $exception) { |
|
| 129 | + Log::error(sprintf('Menu Build Item issue : %s', $exception->getMessage())); |
|
| 130 | + } |
|
| 131 | + break; |
|
| 132 | + case MenuItemLinkType::URI: |
|
| 133 | + $uri = $this->link; |
|
| 134 | + break; |
|
| 135 | + } |
|
| 136 | + break; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $uri; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + public function hasChildren(): bool |
|
| 143 | + { |
|
| 144 | + return $this->children->isNotEmpty(); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + public function getMenuItemHash(): string |
|
| 148 | + { |
|
| 149 | + return $this->hash->toString(); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function hasIcon(): bool |
|
| 153 | + { |
|
| 154 | + return !is_null($this->getIcon()); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function getIcon(): ?Icon |
|
| 158 | + { |
|
| 159 | + return $this->icon; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + public function isChild(): bool |
|
| 163 | + { |
|
| 164 | + return $this->isChild; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + public function getChildren(): Collection |
|
| 168 | + { |
|
| 169 | + return $this->children; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function getAbbr(): string |
|
| 173 | + { |
|
| 174 | + return $this->abbr; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function getClasses(): string |
|
| 178 | + { |
|
| 179 | + return implode(' ', $this->classes); |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -6,11 +6,11 @@ |
||
| 6 | 6 | |
| 7 | 7 | class DemoMenuVisibilityResolver extends MenuVisibilityResolver |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @inheritDoc |
|
| 11 | - */ |
|
| 12 | - public function resolve(mixed $valueOrValues): bool |
|
| 13 | - { |
|
| 14 | - return in_array('sudo', $valueOrValues, true); |
|
| 15 | - } |
|
| 9 | + /** |
|
| 10 | + * @inheritDoc |
|
| 11 | + */ |
|
| 12 | + public function resolve(mixed $valueOrValues): bool |
|
| 13 | + { |
|
| 14 | + return in_array('sudo', $valueOrValues, true); |
|
| 15 | + } |
|
| 16 | 16 | } |
@@ -9,15 +9,15 @@ |
||
| 9 | 9 | |
| 10 | 10 | class MdpViewComposer |
| 11 | 11 | { |
| 12 | - private MaterialDashboardPro $mdp; |
|
| 12 | + private MaterialDashboardPro $mdp; |
|
| 13 | 13 | |
| 14 | - public function __construct(MaterialDashboardPro $mdp) |
|
| 15 | - { |
|
| 16 | - $this->mdp = $mdp; |
|
| 17 | - } |
|
| 14 | + public function __construct(MaterialDashboardPro $mdp) |
|
| 15 | + { |
|
| 16 | + $this->mdp = $mdp; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function compose(View $view): void |
|
| 20 | - { |
|
| 21 | - $view->with('mdp', $this->mdp); |
|
| 22 | - } |
|
| 19 | + public function compose(View $view): void |
|
| 20 | + { |
|
| 21 | + $view->with('mdp', $this->mdp); |
|
| 22 | + } |
|
| 23 | 23 | } |