Completed
Push — master ( 5a4be0...da8e2f )
by wen
13:25
created

AdminController::getMenu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    {
142
        if (! $component->isEdit()) {
143
            throw new AuthorizationException();
144
        }
145
146
        //TODO
147
148
        return response()->json(['message' => 'ok']);
149
    }
150
}
151