|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Inertia\Inertia; |
|
6
|
|
|
use Nwidart\Modules\Facades\Module; |
|
7
|
|
|
|
|
8
|
|
|
use App\Models\UserRolePermissions; |
|
9
|
|
|
use App\Http\Controllers\Controller; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Support\Facades\Auth; |
|
12
|
|
|
use Illuminate\Support\Facades\Gate; |
|
13
|
|
|
|
|
14
|
|
|
class AdminHomeController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Administration Home Page |
|
18
|
2 |
|
*/ |
|
19
|
|
|
public function __invoke() |
|
20
|
2 |
|
{ |
|
21
|
|
|
Gate::authorize('admin-link', Auth::user()); |
|
22
|
|
|
|
|
23
|
1 |
|
// Build each of the Administration menus depending on customer's access |
|
24
|
1 |
|
$userBuild = $this->buildUserList(); |
|
25
|
1 |
|
$equipmentBuild = $this->buildEquipmentList(); |
|
26
|
|
|
$custBuild = $this->buildCustomerList(); |
|
27
|
|
|
$moduleBuild = $this->buildModuleAdmin(); |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
1 |
|
|
|
31
|
1 |
|
return Inertia::render('Admin/index', [ |
|
32
|
|
|
'links' => array_merge($userBuild, $equipmentBuild, $custBuild, $moduleBuild), |
|
33
|
|
|
]); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
// Build the user administration links if the user has access |
|
37
|
|
|
protected function buildUserList() |
|
38
|
1 |
|
{ |
|
39
|
1 |
|
$userBuild = []; |
|
40
|
|
|
if($this->getPermissionValue('Manage Users')) |
|
41
|
|
|
{ |
|
42
|
|
|
$userBuild = [ |
|
43
|
1 |
|
[ |
|
44
|
1 |
|
'name' => 'Create New User', |
|
45
|
1 |
|
'icon' => 'fas fa-user-plus', |
|
46
|
|
|
'link' => route('admin.user.create'), |
|
47
|
|
|
], |
|
48
|
1 |
|
[ |
|
49
|
1 |
|
'name' => 'Modify User', |
|
50
|
1 |
|
'icon' => 'fas fa-user-edit', |
|
51
|
|
|
'link' => route('admin.user.list'), |
|
52
|
|
|
], |
|
53
|
1 |
|
[ |
|
54
|
1 |
|
'name' => 'Show Deactivated Users', |
|
55
|
1 |
|
'icon' => 'fas fa-store-alt-slash', |
|
56
|
|
|
'link' => route('admin.disabled.index'), |
|
57
|
|
|
], |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
1 |
|
|
|
61
|
1 |
|
$roleBuild = []; |
|
62
|
|
|
if($this->getPermissionValue('Manage Permissions')) |
|
63
|
|
|
{ |
|
64
|
1 |
|
$roleBuild = [[ |
|
65
|
1 |
|
'name' => 'User Roles and Permissions', |
|
66
|
1 |
|
'icon' => 'fas fa-users-cog', |
|
67
|
|
|
'link' => route('admin.user-roles.index'), |
|
68
|
|
|
]]; |
|
69
|
|
|
} |
|
70
|
1 |
|
|
|
71
|
|
|
return ['users' => array_merge($userBuild, $roleBuild)]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
// Build the equipment administration links if the user has access |
|
75
|
|
|
protected function buildEquipmentList() |
|
76
|
1 |
|
{ |
|
77
|
1 |
|
$nav = []; |
|
78
|
|
|
if($this->getPermissionValue('Manage Equipment')) |
|
79
|
|
|
{ |
|
80
|
|
|
$nav = [ |
|
81
|
|
|
'equipment types and categories' => [ |
|
82
|
1 |
|
[ |
|
83
|
1 |
|
'name' => 'Create New Category', |
|
84
|
1 |
|
'icon' => 'fas fa-plus-square', |
|
85
|
|
|
'link' => route('admin.equipment.categories.create'), |
|
86
|
|
|
], |
|
87
|
1 |
|
[ |
|
88
|
1 |
|
'name' => 'Modify Existing Category', |
|
89
|
1 |
|
'icon' => 'fas fa-edit', |
|
90
|
|
|
'link' => route('admin.equipment.categories.index'), |
|
91
|
|
|
], |
|
92
|
1 |
|
[ |
|
93
|
1 |
|
'name' => 'Create New Equipment', |
|
94
|
1 |
|
'icon' => 'fas fa-plus-square', |
|
95
|
|
|
'link' => route('admin.equipment.create'), |
|
96
|
|
|
], |
|
97
|
1 |
|
[ |
|
98
|
1 |
|
'name' => 'Modify Existing Equipment', |
|
99
|
1 |
|
'icon' => 'fas fa-edit', |
|
100
|
|
|
'link' => route('admin.equipment.index'), |
|
101
|
|
|
], |
|
102
|
|
|
// TODO - Finish Me |
|
103
|
|
|
// [ |
|
104
|
|
|
// 'name' => 'Modify Information Gathered for Customer Equipment', |
|
105
|
|
|
// 'icon' => '', |
|
106
|
|
|
// 'link' => '#', |
|
107
|
|
|
// ], |
|
108
|
|
|
] |
|
109
|
|
|
]; |
|
110
|
|
|
} |
|
111
|
1 |
|
|
|
112
|
|
|
return $nav; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
1 |
|
// Build Customer Management list |
|
116
|
|
|
protected function buildCustomerList() |
|
117
|
1 |
|
{ |
|
118
|
|
|
$nav = []; |
|
119
|
1 |
|
|
|
120
|
|
|
if($this->getPermissionValue('Manage Customers')) |
|
121
|
|
|
{ |
|
122
|
|
|
$nav = [ |
|
123
|
|
|
'Manage Customers' => [ |
|
124
|
1 |
|
[ |
|
125
|
1 |
|
'name' => 'Change Customer ID Number', |
|
126
|
1 |
|
'icon' => 'fas fa-fingerprint', |
|
127
|
|
|
'link' => route('customers.change-id.index'), |
|
128
|
|
|
], |
|
129
|
1 |
|
[ |
|
130
|
1 |
|
'name' => 'View Deactivated Customers', |
|
131
|
1 |
|
'icon' => 'fas fa-ban', |
|
132
|
|
|
'link' => route('customers.show-deactivated'), |
|
133
|
|
|
], |
|
134
|
|
|
[ |
|
135
|
|
|
'name' => 'View Deleted Customer Information', |
|
136
|
|
|
'icon' => 'fas fa-trash-alt', |
|
137
|
|
|
'link' => '#', |
|
138
|
|
|
], |
|
139
|
|
|
], |
|
140
|
|
|
]; |
|
141
|
|
|
} |
|
142
|
1 |
|
|
|
143
|
|
|
return $nav; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
protected function buildModuleAdmin() |
|
147
|
|
|
{ |
|
148
|
|
|
$nav = []; |
|
149
|
|
|
$modules = Module::allEnabled(); |
|
150
|
|
|
|
|
151
|
|
|
foreach($modules as $module) |
|
152
|
|
|
{ |
|
153
|
1 |
|
$name = $module->getLowerName(); |
|
154
|
|
|
$navData = config($name.'.admin_nav'); |
|
155
|
1 |
|
$modNav = []; |
|
156
|
|
|
|
|
157
|
1 |
|
foreach($navData as $n) |
|
158
|
1 |
|
{ |
|
159
|
|
|
$modNav[] = [ |
|
160
|
1 |
|
'name' => $n['name'], |
|
161
|
|
|
'link' => route($n['route']), |
|
162
|
|
|
'icon' => $n['icon'], |
|
163
|
|
|
]; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
// Split Camel Case name into normal name |
|
167
|
|
|
$nav[implode(' ',preg_split('/(?=[A-Z])/', $module->getName()))] = $modNav; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
return $nav; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
// Determine if the user has permissions for a specific area |
|
181
|
|
|
protected function getPermissionValue($description) |
|
182
|
|
|
{ |
|
183
|
|
|
$allowed = UserRolePermissions::where('role_id', Auth::user()->role_id)->whereHas('UserRolePermissionTypes', function($q) use ($description) |
|
|
|
|
|
|
184
|
|
|
{ |
|
185
|
|
|
$q->where('description', $description); |
|
186
|
|
|
})->first(); |
|
187
|
|
|
|
|
188
|
|
|
return $allowed->allow; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|