Passed
Push — develop ( 0fc46b...6b7c8d )
by Tony
04:19
created

SyslogDataTable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 85
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getAjax() 0 4 1
A ajax() 0 9 1
A query() 0 7 1
A getBuilderParameters() 0 6 1
A getColumns() 0 17 1
A filename() 0 4 1
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
    public function ajax()
39
    {
40
        return $this->datatables
41
            ->eloquent($this->query())
42
            ->orderColumn('name', '-name $1')
43
            ->editColumn('device_id', 'datatables.generic.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
    /**
62
     * Sort by timestamp descending
63
     *
64
     * @return array
65
     */
66 1
    public function getBuilderParameters()
67
    {
68 1
        $params = parent::getBuilderParameters();
69 1
        $params['order'] = [[3, 'desc']];
70 1
        return $params;
71
    }
72
73
    /**
74
     * Get columns.
75
     *
76
     * @return array
77
     */
78 1
    public function getColumns()
79
    {
80
        return [
81
            'device_id' => [
82 1
                'title'       => trans('devices.label.hostname'),
83
            ],
84
            'program'      => [
85 1
                'title' => trans('general.text.program'),
86
            ],
87
            'msg'   => [
88 1
                'title' => trans('general.text.message'),
89
            ],
90
            'timestamp'  => [
91 1
                'title' => trans('general.text.timestamp'),
92
            ],
93
        ];
94
    }
95
96
    /**
97
     * Get filename for export.
98
     *
99
     * @return string
100
     */
101
    protected function filename()
102
    {
103
        return 'syslog';
104
    }
105
106
    /**
107
     * Get ajax url.
108
     *
109
     * @return \Illuminate\Contracts\Routing\UrlGenerator|string
110
     */
111 1
    public function getAjax()
112
    {
113 1
        return url('syslog');
114
    }
115
}
116