1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sco\Admin\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Auth\Access\AuthorizationException; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Routing\Controller; |
8
|
|
|
use Sco\Admin\Contracts\ComponentInterface; |
9
|
|
|
use Sco\Admin\Facades\AdminNavigation; |
10
|
|
|
|
11
|
|
|
class AdminController extends Controller |
12
|
|
|
{ |
13
|
|
|
public function getMenu() |
14
|
|
|
{ |
15
|
|
|
$pages = AdminNavigation::filterByAccessRights() |
16
|
|
|
->sort() |
17
|
|
|
->getPages(); |
18
|
|
|
return response()->json($pages); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function index(ComponentInterface $component) |
22
|
|
|
{ |
23
|
|
|
if (! $component->isDisplay()) { |
24
|
|
|
throw new AuthorizationException(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return view('admin::app'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getList(ComponentInterface $component) |
31
|
|
|
{ |
32
|
|
|
if (! $component->isDisplay()) { |
33
|
|
|
throw new AuthorizationException(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $component->get(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function config(ComponentInterface $component) |
40
|
|
|
{ |
41
|
|
|
if (! $component->isDisplay()) { |
42
|
|
|
throw new AuthorizationException(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $component->getConfigs(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getCreateInfo(ComponentInterface $component) |
49
|
|
|
{ |
50
|
|
|
if (! $component->isCreate()) { |
51
|
|
|
throw new AuthorizationException(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$form = $component->fireCreate(); |
55
|
|
|
|
56
|
|
|
return $form; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function create(ComponentInterface $component) |
60
|
|
|
{ |
61
|
|
|
if (! $component->isCreate()) { |
62
|
|
|
throw new AuthorizationException(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return view('admin::app'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function store(ComponentInterface $component, Request $request) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
if (! $component->isCreate()) { |
71
|
|
|
throw new AuthorizationException(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$component->store(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getEditInfo(ComponentInterface $component, $id) |
78
|
|
|
{ |
79
|
|
|
if (! $component->isEdit()) { |
80
|
|
|
throw new AuthorizationException(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$form = $component->fireEdit($id); |
84
|
|
|
|
85
|
|
|
return $form; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function edit(ComponentInterface $component, $id) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
if (! $component->isEdit()) { |
91
|
|
|
throw new AuthorizationException(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return view('admin::app'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function update(ComponentInterface $component, Request $request, $id) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
if (! $component->isEdit()) { |
100
|
|
|
throw new AuthorizationException(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$component->update($id); |
104
|
|
|
|
105
|
|
|
return response()->json(['message' => 'ok']); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
View Code Duplication |
public function delete(ComponentInterface $component, $id) |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
if (! $component->isDelete()) { |
111
|
|
|
throw new AuthorizationException(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$component->delete($id); |
115
|
|
|
|
116
|
|
|
return response()->json(['message' => 'ok']); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function forceDelete(ComponentInterface $component, $id) |
120
|
|
|
{ |
121
|
|
|
if (! $component->isDestroy()) { |
122
|
|
|
throw new AuthorizationException(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$component->forceDelete($id); |
126
|
|
|
|
127
|
|
|
return response()->json(['message' => 'ok']); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function restore(ComponentInterface $component, $id) |
131
|
|
|
{ |
132
|
|
|
if (! $component->isRestore()) { |
133
|
|
|
throw new AuthorizationException(); |
134
|
|
|
} |
135
|
|
|
$component->restore($id); |
136
|
|
|
|
137
|
|
|
return response()->json(['message' => 'ok']); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
View Code Duplication |
public function reorder(ComponentInterface $component) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
if (! $component->isEdit()) { |
143
|
|
|
throw new AuthorizationException(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
//TODO |
147
|
|
|
|
148
|
|
|
return response()->json(['message' => 'ok']); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.