|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* DeviceGroupDataTable.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\DataTables; |
|
27
|
|
|
|
|
28
|
|
|
use App\Models\DeviceGroup; |
|
29
|
|
|
|
|
30
|
|
|
class DeviceGroupDataTable extends BaseDataTable |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Display ajax response. |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
36
|
|
|
*/ |
|
37
|
|
|
public function ajax() |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->datatables |
|
40
|
|
|
->eloquent($this->query()) |
|
41
|
|
|
->editColumn('name', function($group) { |
|
42
|
|
|
return '<a href="'.url('devices/group='.$group->id).'">'.$group->name.'</a>'; |
|
43
|
|
|
}) |
|
44
|
|
|
->editColumn('count', function($group) { |
|
45
|
|
|
return '<span data-toggle="tooltip" title="'.$group->deviceCount.' '.trans('nav.devices.devices').'" class="badge bg-aqua"> |
|
46
|
|
|
<i class="fa fa-server"></i> '.$group->deviceCount.'</span>'; |
|
47
|
|
|
}) |
|
48
|
|
|
->addColumn('actions', function($group) { |
|
49
|
|
|
$edit = '<button type="button" class="btn btn-xs btn-primary showModal" data-toggle="modal" data-target="#generalModal" data-href="'. |
|
50
|
|
|
route('device-groups.edit', ['group_id' => $group->id]). |
|
51
|
|
|
'"><i class="fa fa-edit fa-lg fa-fw"></i><span class="hidden-xs"> '.trans('button.edit').'</span></button> '; |
|
52
|
|
|
|
|
53
|
|
|
$delete = '<button type="button" class="btn btn-xs btn-danger deleteModal" data-toggle="modal" data-target="#deleteModal" data-href="'. |
|
54
|
|
|
route('device-groups.destroy', ['group_id' => $group->id]). |
|
55
|
|
|
'"><i class="fa fa-trash fa-lg fa-fw"></i><span class="hidden-xs"> '.trans('button.delete').'</span></button> '; |
|
56
|
|
|
|
|
57
|
|
|
return $edit.$delete; |
|
58
|
|
|
}) |
|
59
|
|
|
->make(true); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the query object to be processed by datatables. |
|
64
|
|
|
* |
|
65
|
|
|
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder |
|
66
|
|
|
*/ |
|
67
|
|
|
public function query() |
|
68
|
|
|
{ |
|
69
|
|
|
$devicegroups = DeviceGroup::query()->with('deviceCountRelation'); |
|
70
|
|
|
return $this->applyScopes($devicegroups); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get columns. |
|
75
|
|
|
* |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getColumns() |
|
79
|
|
|
{ |
|
80
|
|
|
return [ |
|
81
|
|
|
'id' => [ |
|
82
|
|
|
'visible' => false, |
|
83
|
|
|
], |
|
84
|
|
|
'name' => [ |
|
85
|
|
|
'title' => trans('devices.groups.name'), |
|
86
|
|
|
], |
|
87
|
|
|
'count' => [ |
|
88
|
|
|
'title' => '', |
|
89
|
|
|
'searchable' => false, |
|
90
|
|
|
], |
|
91
|
|
|
'desc' => [ |
|
92
|
|
|
'title' => trans('devices.groups.desc'), |
|
93
|
|
|
], |
|
94
|
|
|
'patternSql' => [ |
|
95
|
|
|
'title' => trans('devices.groups.pattern'), |
|
96
|
|
|
], |
|
97
|
|
|
'actions' => [ |
|
98
|
|
|
'title' => trans('devices.groups.actions'), |
|
99
|
|
|
], |
|
100
|
|
|
]; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get filename for export. |
|
105
|
|
|
* |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function filename() |
|
109
|
|
|
{ |
|
110
|
|
|
return 'devicegroups'; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|