| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * app/DataTables/DeviceDataTable.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Datatable for devices | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use App\Models\Device; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | class DeviceDataTable 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('status_reason', 'datatables.device.status-reason') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ->editColumn('vendor', 'datatables.device.icon') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ->editColumn('hostname', 'datatables.device.hostname') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ->editColumn('resources', 'datatables.device.resources') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ->editColumn('hardware', '{{ $hardware }}<br />{{ $features }}') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ->editColumn('os', '{{ ucfirst($os) }}<br />{{ $version }}') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ->editColumn('location', '{{ Util::formatUptime($uptime) }}<br />{{ $location }}') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ->rawColumns(['status_reason', 'vendor', 'hostname', 'resources', 'hardware', 'os', 'location']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             ->make(true); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * Get the query object to be processed by datatables. | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     public function query() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $device = Device::with(['portCountRelation', 'sensorCountRelation'])->select('devices.*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         return $this->applyScopes($device); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      * Get columns. | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 3 |  |     public function getColumns() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             'status'    => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 3 |  |                 'title' => trans('general.text.status'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 3 |  |                 'data'  => 'status_reason', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 3 |  |                 'width' => '40px', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 3 |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             'vendor'         => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 3 |  |                 'title'      => trans('devices.text.vendor'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 3 |  |                 'className'  => 'device-icon', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 'searchable' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 'orderable'  => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             'hostname'  => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 3 |  |                 'title' => trans('devices.label.hostname'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             'resources'      => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 'title'      => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 'searchable' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 'orderable'  => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             'hardware'  => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 3 |  |                 'title' => trans('devices.text.platform'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             'features'    => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 'visible' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             'os'        => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 3 |  |                 'title' => trans('devices.text.os'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             'version'     => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 'visible' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             'location'  => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 3 |  |                 'title' => trans('devices.text.uptime_location'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         ]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |      * Get filename for export. | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     protected function filename() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         return 'devices'; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 117 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |  |