|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Nwidart\Modules\Facades\Module; |
|
6
|
|
|
|
|
7
|
|
|
use App\Models\User; |
|
8
|
|
|
use App\Traits\AllowTrait; |
|
9
|
|
|
|
|
10
|
|
|
class BuildAdminMenu |
|
11
|
|
|
{ |
|
12
|
|
|
use AllowTrait; |
|
13
|
|
|
|
|
14
|
|
|
protected $user; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct(User $user) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->user = $user; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Get the Admin links that the user has permission to access |
|
23
|
|
|
*/ |
|
24
|
|
|
public function execute() |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
$userMenu = $this->buildUserMenu(); |
|
28
|
|
|
$equipMenu = $this->buildEquipmentMenu(); |
|
29
|
|
|
$customerMenu = $this->buildCustomerMenu(); |
|
30
|
|
|
$techTipMenu = $this->buildTechTipMenu(); |
|
31
|
|
|
$moduleMenu = $this->buildModuleMenus(); |
|
32
|
|
|
$settingsMenu = $this->buildSettingsMenu(); |
|
33
|
|
|
$maintMenu = $this->buildMaintenanceMenu(); |
|
34
|
|
|
|
|
35
|
|
|
return array_merge($userMenu, $equipMenu, $customerMenu, $techTipMenu, $moduleMenu, $settingsMenu, $maintMenu); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get the navigation links for Users |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function buildUserMenu() |
|
42
|
|
|
{ |
|
43
|
|
|
$userBuild = []; |
|
44
|
|
|
if($this->checkPermission($this->user, 'Manage Users')) |
|
45
|
|
|
{ |
|
46
|
|
|
$userBuild = [ |
|
47
|
|
|
[ |
|
48
|
|
|
'name' => 'Create New User', |
|
49
|
|
|
'icon' => 'fas fa-user-plus', |
|
50
|
|
|
'link' => route('admin.user.create'), |
|
51
|
|
|
], |
|
52
|
|
|
[ |
|
53
|
|
|
'name' => 'Modify User', |
|
54
|
|
|
'icon' => 'fas fa-user-edit', |
|
55
|
|
|
'link' => route('admin.user.index'), |
|
56
|
|
|
], |
|
57
|
|
|
[ |
|
58
|
|
|
'name' => 'Show Deactivated Users', |
|
59
|
|
|
'icon' => 'fas fa-store-alt-slash', |
|
60
|
|
|
'link' => route('admin.deactivated-users'), |
|
61
|
|
|
], |
|
62
|
|
|
[ |
|
63
|
|
|
'name' => 'Password Policy', |
|
64
|
|
|
'icon' => 'fas fa-user-lock', |
|
65
|
|
|
'link' => route('admin.password-policy'), |
|
66
|
|
|
], |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$roleBuild = []; |
|
71
|
|
|
if($this->checkPermission($this->user, 'Manage Permissions')) |
|
72
|
|
|
{ |
|
73
|
|
|
$roleBuild = [[ |
|
74
|
|
|
'name' => 'User Roles and Permissions', |
|
75
|
|
|
'icon' => 'fas fa-users-cog', |
|
76
|
|
|
'link' => route('admin.user-roles.index'), |
|
77
|
|
|
]]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if(count($userBuild) > 0 || count($roleBuild) > 0) |
|
81
|
|
|
{ |
|
82
|
|
|
return ['Users' => array_merge($userBuild, $roleBuild)]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return []; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get the navigation links for Equipment and Equipment Categories |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function buildEquipmentMenu() |
|
92
|
|
|
{ |
|
93
|
|
|
$nav = []; |
|
94
|
|
|
|
|
95
|
|
|
if($this->checkPermission($this->user, 'Manage Equipment')) |
|
96
|
|
|
{ |
|
97
|
|
|
$nav = [ |
|
98
|
|
|
'Manage Equipment' => [ |
|
99
|
|
|
[ |
|
100
|
|
|
'name' => 'Equipment Types & Categories', |
|
101
|
|
|
'icon' => 'fas fa-cogs', |
|
102
|
|
|
'link' => route('equipment.index'), |
|
103
|
|
|
], |
|
104
|
|
|
[ |
|
105
|
|
|
'name' => 'Equipment Data Types (for customers)', |
|
106
|
|
|
'icon' => 'fas fa-database', |
|
107
|
|
|
'link' => route('data-types.index'), |
|
108
|
|
|
], |
|
109
|
|
|
], |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $nav; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Get the navigation links for customers |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function buildCustomerMenu() |
|
120
|
|
|
{ |
|
121
|
|
|
$nav = []; |
|
122
|
|
|
|
|
123
|
|
|
if($this->checkPermission($this->user, 'Manage Customers')) |
|
124
|
|
|
{ |
|
125
|
|
|
$nav = [ |
|
126
|
|
|
'Manage Customers' => [ |
|
127
|
|
|
[ |
|
128
|
|
|
'name' => 'Change Customer ID Number', |
|
129
|
|
|
'icon' => 'fas fa-fingerprint', |
|
130
|
|
|
'link' => route('admin.cust.change-id.index'), |
|
131
|
|
|
], |
|
132
|
|
|
[ |
|
133
|
|
|
'name' => 'View Deactivated Customers', |
|
134
|
|
|
'icon' => 'fas fa-ban', |
|
135
|
|
|
'link' => route('admin.cust.show-deactivated'), |
|
136
|
|
|
], |
|
137
|
|
|
[ |
|
138
|
|
|
'name' => 'Customer Uploaded File Types', |
|
139
|
|
|
'icon' => 'fas fa-file-alt', |
|
140
|
|
|
'link' => route('admin.cust.file-types.index'), |
|
141
|
|
|
], |
|
142
|
|
|
], |
|
143
|
|
|
]; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $nav; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Build Navigation menu for Tech Tips |
|
151
|
|
|
*/ |
|
152
|
|
|
protected function buildTechTipMenu() |
|
153
|
|
|
{ |
|
154
|
|
|
$nav = []; |
|
155
|
|
|
|
|
156
|
|
|
if($this->checkPermission($this->user, 'Manage Tech Tips')) |
|
157
|
|
|
{ |
|
158
|
|
|
$nav = [ |
|
159
|
|
|
'Manage Tech Tips' => [ |
|
160
|
|
|
[ |
|
161
|
|
|
'name' => 'Tech Tip Types', |
|
162
|
|
|
'icon' => 'fas fa-file-alt', |
|
163
|
|
|
'link' => route('admin.tips.tip-types.index'), |
|
164
|
|
|
], |
|
165
|
|
|
[ |
|
166
|
|
|
'name' => 'View Deleted Tech Tips', |
|
167
|
|
|
'icon' => 'fas fa-ban', |
|
168
|
|
|
'link' => route('admin.tips.deleted'), |
|
169
|
|
|
], |
|
170
|
|
|
[ |
|
171
|
|
|
'name' => 'View Flagged Comments', |
|
172
|
|
|
'icon' => 'far fa-flag', |
|
173
|
|
|
'link' => route('tips.comments.index'), |
|
174
|
|
|
], |
|
175
|
|
|
], |
|
176
|
|
|
]; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
return $nav; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Build Admin menu's for all of the installed Modules |
|
184
|
|
|
*/ |
|
185
|
|
|
protected function buildModuleMenus() |
|
186
|
|
|
{ |
|
187
|
|
|
$nav = []; |
|
188
|
|
|
$modules = Module::allEnabled(); |
|
189
|
|
|
|
|
190
|
|
|
foreach($modules as $module) |
|
191
|
|
|
{ |
|
192
|
|
|
$name = $module->getLowerName(); |
|
193
|
|
|
$navData = config($name.'.admin_nav'); |
|
194
|
|
|
$modNav = []; |
|
195
|
|
|
|
|
196
|
|
|
if($navData) |
|
197
|
|
|
{ |
|
198
|
|
|
foreach($navData as $n) |
|
199
|
|
|
{ |
|
200
|
|
|
if(!isset($n['perm_name']) || $this->checkPermission($this->user, $n['perm_name'])) |
|
201
|
|
|
{ |
|
202
|
|
|
$modNav[] = [ |
|
203
|
|
|
'name' => $n['name'], |
|
204
|
|
|
'link' => route($n['route']), |
|
205
|
|
|
'icon' => $n['icon'], |
|
206
|
|
|
]; |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
if(count($modNav) > 0) |
|
212
|
|
|
{ |
|
213
|
|
|
// Split Camel Case name into normal name |
|
214
|
|
|
$nav[implode(' ', preg_split('/(?=[A-Z])/', $module->getName()))] = $modNav; |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
return $nav; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Build navigation menu for Application Settings |
|
223
|
|
|
*/ |
|
224
|
|
|
protected function buildSettingsMenu() |
|
225
|
|
|
{ |
|
226
|
|
|
$nav = []; |
|
227
|
|
|
|
|
228
|
|
|
if($this->checkPermission($this->user, 'App Settings')) |
|
229
|
|
|
{ |
|
230
|
|
|
$nav = [ |
|
231
|
|
|
'Manage Application Settings' => [ |
|
232
|
|
|
[ |
|
233
|
|
|
'name' => 'Application Logo', |
|
234
|
|
|
'icon' => 'fas fa-image', |
|
235
|
|
|
'link' => route('admin.get-logo'), |
|
236
|
|
|
], |
|
237
|
|
|
[ |
|
238
|
|
|
'name' => 'Application Configuration', |
|
239
|
|
|
'icon' => 'fas fa-server', |
|
240
|
|
|
'link' => route('admin.get-config'), |
|
241
|
|
|
], |
|
242
|
|
|
[ |
|
243
|
|
|
'name' => 'Email Settings', |
|
244
|
|
|
'icon' => 'fas fa-envelope', |
|
245
|
|
|
'link' => route('admin.get-email'), |
|
246
|
|
|
], |
|
247
|
|
|
], |
|
248
|
|
|
]; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
return $nav; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Build navigation menu for Application Maintenance |
|
256
|
|
|
*/ |
|
257
|
|
|
protected function buildMaintenanceMenu() |
|
258
|
|
|
{ |
|
259
|
|
|
$nav = []; |
|
260
|
|
|
|
|
261
|
|
|
if($this->checkPermission($this->user, 'App Settings')) |
|
262
|
|
|
{ |
|
263
|
|
|
$nav = [ |
|
264
|
|
|
'Application Maintenance' => [ |
|
265
|
|
|
[ |
|
266
|
|
|
'name' => 'Application Logs', |
|
267
|
|
|
'icon' => 'fas fa-bug', |
|
268
|
|
|
'link' => route('admin.logs.index'), |
|
269
|
|
|
], |
|
270
|
|
|
[ |
|
271
|
|
|
'name' => 'Application Backups', |
|
272
|
|
|
'icon' => 'far fa-hdd', |
|
273
|
|
|
'link' => route('admin.backups.index'), |
|
274
|
|
|
], |
|
275
|
|
|
// TODO - Finish me!!! |
|
276
|
|
|
// [ |
|
277
|
|
|
// 'name' => 'Application Updates', |
|
278
|
|
|
// 'icon' => '', |
|
279
|
|
|
// 'link' => '#', |
|
280
|
|
|
// ], |
|
281
|
|
|
], |
|
282
|
|
|
]; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
return $nav; |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
|