Completed
Push — master ( 702238...a071d3 )
by Tony
02:57
created

DeviceGroupDataTable::filename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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>&nbsp; '.$group->deviceCount.'</span>';
47
            })
48 View Code Duplication
            ->addColumn('actions', function($group) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
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