@@ -25,8 +25,7 @@ |
||
25 | 25 | foreach ($menuItems as $index => $menuItem) { |
26 | 26 | if (!array_key_exists('can', $menuItem) || $menuResolver->resolve($menuItem['can'])) { |
27 | 27 | $link = array_key_exists('link', $menuItem) ? |
28 | - $menuItem['link'] : |
|
29 | - ['type' => MenuItemLinkType::URI, 'uri' => '#']; |
|
28 | + $menuItem['link'] : ['type' => MenuItemLinkType::URI, 'uri' => '#']; |
|
30 | 29 | |
31 | 30 | $hasIcon = array_key_exists('icon', $menuItem); |
32 | 31 |
@@ -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 | ]; |
@@ -16,7 +16,7 @@ |
||
16 | 16 | view() |
17 | 17 | ->composer( |
18 | 18 | ['mdp::layouts.main', 'mdp::layouts.user.auth-v1'], |
19 | - static function (View $view) use ($pageTitle) { |
|
19 | + static function(View $view) use ($pageTitle) { |
|
20 | 20 | $data = $view->getData(); |
21 | 21 | |
22 | 22 | if (array_key_exists('mdp', $data)) { |
@@ -58,7 +58,7 @@ |
||
58 | 58 | $words = explode(' ', $this->getTitle()); |
59 | 59 | |
60 | 60 | $abbrArray = array_map( |
61 | - static function ($word) { |
|
61 | + static function($word) { |
|
62 | 62 | $array = mb_str_split($word); |
63 | 63 | |
64 | 64 | return current($array); |
@@ -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 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | Route::name('kield01.mdp.') |
7 | 7 | ->prefix('mdp') |
8 | 8 | ->group( |
9 | - static function () { |
|
9 | + static function() { |
|
10 | 10 | Route::get('login', [TestAuthController::class, 'login'])->name('user.login'); |
11 | 11 | Route::post('login', [TestAuthController::class, 'auth'])->name('user.auth'); |
12 | 12 |
@@ -8,10 +8,10 @@ |
||
8 | 8 | Route::name('kield01.mdp.dashboard.') |
9 | 9 | ->prefix('mdp') |
10 | 10 | ->group( |
11 | - static function () { |
|
11 | + static function() { |
|
12 | 12 | Route::prefix('dashboard') |
13 | 13 | ->group( |
14 | - static function () { |
|
14 | + static function() { |
|
15 | 15 | Route::get('', [TestDashboardController::class, 'dashboard'])->name('index'); |
16 | 16 | } |
17 | 17 | ); |
@@ -11,33 +11,33 @@ |
||
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 = [ |
|
22 | - 'email' => $request->post('email'), |
|
23 | - 'password' => $request->post('password') |
|
24 | - ]; |
|
25 | - |
|
26 | - $emailCheck = Str::is('[email protected]', $credentials['email']); |
|
27 | - $passwordCheck = Str::is('adminTest!123', $credentials['password']); |
|
28 | - $checksPassed = $emailCheck && $passwordCheck; |
|
29 | - |
|
30 | - if ($checksPassed) { |
|
31 | - return redirect(route('kield01.mdp.dashboard.index')); |
|
32 | - } |
|
33 | - |
|
34 | - return redirect() |
|
35 | - ->back() |
|
36 | - ->with($credentials); |
|
37 | - } |
|
38 | - |
|
39 | - public function register(): string |
|
40 | - { |
|
41 | - return view('mdp::pages.user.register')->render(); |
|
42 | - } |
|
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 = [ |
|
22 | + 'email' => $request->post('email'), |
|
23 | + 'password' => $request->post('password') |
|
24 | + ]; |
|
25 | + |
|
26 | + $emailCheck = Str::is('[email protected]', $credentials['email']); |
|
27 | + $passwordCheck = Str::is('adminTest!123', $credentials['password']); |
|
28 | + $checksPassed = $emailCheck && $passwordCheck; |
|
29 | + |
|
30 | + if ($checksPassed) { |
|
31 | + return redirect(route('kield01.mdp.dashboard.index')); |
|
32 | + } |
|
33 | + |
|
34 | + return redirect() |
|
35 | + ->back() |
|
36 | + ->with($credentials); |
|
37 | + } |
|
38 | + |
|
39 | + public function register(): string |
|
40 | + { |
|
41 | + return view('mdp::pages.user.register')->render(); |
|
42 | + } |
|
43 | 43 | } |