|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* app/DataTables/General/SyslogDataTable.php |
|
4
|
|
|
* |
|
5
|
|
|
* Datatable for syslog |
|
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 Neil Lathwood |
|
23
|
|
|
* @author Neil Lathwood <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace App\DataTables\General; |
|
27
|
|
|
|
|
28
|
|
|
use App\DataTables\BaseDataTable; |
|
29
|
|
|
use App\Models\General\Syslog; |
|
30
|
|
|
|
|
31
|
|
|
class SyslogDataTable extends BaseDataTable |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Display ajax response. |
|
35
|
|
|
* |
|
36
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
37
|
|
|
*/ |
|
38
|
|
View Code Duplication |
public function ajax() |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
return $this->datatables |
|
41
|
|
|
->eloquent($this->query()) |
|
42
|
|
|
->orderColumn('name', '-name $1') |
|
43
|
|
|
->editColumn('device_id', 'datatables.syslog.hostname') |
|
44
|
|
|
->rawColumns(['device_id']) |
|
45
|
|
|
->make(true); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get the query object to be processed by datatables. |
|
50
|
|
|
* |
|
51
|
|
|
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder |
|
52
|
|
|
*/ |
|
53
|
|
|
public function query() |
|
54
|
|
|
{ |
|
55
|
|
|
$syslog = Syslog::with(['device' => function ($query) { |
|
56
|
|
|
return $query->addSelect(['device_id', 'hostname']); |
|
57
|
|
|
}])->select('syslog.*'); |
|
58
|
|
|
return $this->applyScopes($syslog); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getBuilderParameters() |
|
62
|
|
|
{ |
|
63
|
|
|
$params = parent::getBuilderParameters(); |
|
64
|
|
|
$params['order'] = [[3, 'desc']]; |
|
65
|
|
|
return $params; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get columns. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
View Code Duplication |
public function getColumns() |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
return [ |
|
76
|
|
|
'device_id' => [ |
|
77
|
|
|
'title' => trans('devices.label.hostname'), |
|
78
|
|
|
], |
|
79
|
|
|
'program' => [ |
|
80
|
|
|
'title' => trans('general.text.program'), |
|
81
|
|
|
], |
|
82
|
|
|
'msg' => [ |
|
83
|
|
|
'title' => trans('general.text.message'), |
|
84
|
|
|
], |
|
85
|
|
|
'timestamp' => [ |
|
86
|
|
|
'title' => trans('general.text.timestamp'), |
|
87
|
|
|
], |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get filename for export. |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function filename() |
|
97
|
|
|
{ |
|
98
|
|
|
return 'syslog'; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get ajax url. |
|
103
|
|
|
* |
|
104
|
|
|
* @return \Illuminate\Contracts\Routing\UrlGenerator|string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getAjax() |
|
107
|
|
|
{ |
|
108
|
|
|
return url('syslog'); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
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.