|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* DeviceGroupController.php |
|
4
|
|
|
* |
|
5
|
|
|
* -Description- |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
* @package LibreNMS |
|
21
|
|
|
* @link http://librenms.org |
|
22
|
|
|
* @copyright 2016 Tony Murray |
|
23
|
|
|
* @author Tony Murray <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace App\Http\Controllers; |
|
27
|
|
|
|
|
28
|
|
|
use App\DataTables\DeviceGroupDataTable; |
|
29
|
|
|
use App\Http\Requests\AdminOnlyRequest; |
|
30
|
|
|
use App\Http\Requests\DeviceGroupRequest; |
|
31
|
|
|
use App\Models\DeviceGroup; |
|
32
|
|
|
|
|
33
|
|
|
class DeviceGroupController extends Controller |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Display a listing of the resource. |
|
37
|
|
|
* |
|
38
|
|
|
* @param DeviceGroupDataTable $dataTable |
|
39
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
40
|
|
|
*/ |
|
41
|
|
|
public function index(DeviceGroupDataTable $dataTable) |
|
42
|
|
|
{ |
|
43
|
|
|
return $dataTable->render('devices.group-list'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Show the form for creating a new resource. |
|
48
|
|
|
* |
|
49
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
50
|
|
|
*/ |
|
51
|
|
|
public function create() |
|
52
|
|
|
{ |
|
53
|
|
|
return view('devices.group-edit'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Store a newly created resource in storage. |
|
58
|
|
|
* |
|
59
|
|
|
* @param \Illuminate\Http\Request $request |
|
60
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
61
|
|
|
*/ |
|
62
|
|
|
public function store(DeviceGroupRequest $request) |
|
63
|
|
|
{ |
|
64
|
|
|
$group = DeviceGroup::create($request->all()); |
|
65
|
|
|
|
|
66
|
|
|
return response()->json(['message' => trans('devices.groups.created', ['name' => $group->name])]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Display the specified resource. |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $id |
|
73
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
74
|
|
|
*/ |
|
75
|
|
|
public function show($id) |
|
76
|
|
|
{ |
|
77
|
|
|
return redirect('devices/group='.$id); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Show the form for editing the specified resource. |
|
82
|
|
|
* |
|
83
|
|
|
* @param int $id |
|
84
|
|
|
* @return \Illuminate\Http\Response |
|
85
|
|
|
*/ |
|
86
|
|
|
public function edit($id) |
|
87
|
|
|
{ |
|
88
|
|
|
$group = DeviceGroup::findOrFail($id); |
|
89
|
|
|
return view('devices.group-edit')->withGroup($group); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Update the specified resource in storage. |
|
94
|
|
|
* |
|
95
|
|
|
* @param \Illuminate\Http\Request $request |
|
96
|
|
|
* @param int $id |
|
97
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
98
|
|
|
*/ |
|
99
|
|
|
public function update(DeviceGroupRequest $request, $id) |
|
100
|
|
|
{ |
|
101
|
|
|
$group = DeviceGroup::find($id); |
|
102
|
|
|
$group->update($request->all()); |
|
103
|
|
|
$group->updateRelations(); |
|
104
|
|
|
|
|
105
|
|
|
return response()->json(['message' => trans('devices.groups.updated', ['name' => $group->name])]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Remove the specified resource from storage. |
|
110
|
|
|
* |
|
111
|
|
|
* @param \Illuminate\Http\Request $request |
|
112
|
|
|
* @param int $id |
|
113
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
114
|
|
|
* @throws \Exception |
|
115
|
|
|
*/ |
|
116
|
|
|
public function destroy(AdminOnlyRequest $request, $id) |
|
117
|
|
|
{ |
|
118
|
|
|
$group = DeviceGroup::find($id); |
|
119
|
|
|
if ($group && $group->delete()) { |
|
120
|
|
|
return response()->json(['message' => trans('devices.groups.deleted', ['name' => $group->name])]); |
|
121
|
|
|
} else { |
|
122
|
|
|
return response()->json(['message' => trans('devices.groups.deletefailed', ['name' => $group ? $group->name : ""])], 422); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.