| @@ 31-99 (lines=69) @@ | ||
| 28 | use App\DataTables\BaseDataTable; | |
| 29 | use App\Models\General\IPv4; | |
| 30 | ||
| 31 | class IPv4DataTable extends BaseDataTable | |
| 32 | { | |
| 33 | ||
| 34 | /** | |
| 35 | * Display ajax response. | |
| 36 | * | |
| 37 | * @return \Illuminate\Http\JsonResponse | |
| 38 | */ | |
| 39 | public function ajax() | |
| 40 |     { | |
| 41 | return $this->datatables | |
| 42 | ->eloquent($this->query()) | |
| 43 |             ->editColumn('hostname', function($data) { | |
| 44 |                 $hostname = is_null($data->device) ? trans('devices.text.deleted') : $data->device->hostname; | |
| 45 |                 return '<a href="'.url("devices/".$data->device_id).'">'.$hostname.'</a>'; | |
| 46 | }) | |
| 47 |             ->editColumn('ifName', function($data) { | |
| 48 |                 $ifName = is_null($data->ifName) ? trans('devices.text.deleted') : $data->ifName; | |
| 49 |                 return '<a href="'.url("devices/".$data->device_id."/ports/".$data->port_id).'">'.$ifName.'</a>'; | |
| 50 | }) | |
| 51 | ->make(true); | |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Get the query object to be processed by datatables. | |
| 56 | * | |
| 57 | * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | |
| 58 | */ | |
| 59 | public function query() | |
| 60 |     { | |
| 61 |         $data = IPv4::join('ports', 'ports.port_id', '=', 'ipv4_addresses.port_id')->join('devices', 'devices.device_id', '=', 'ports.device_id')->select('ipv4_addresses.*', 'ports.*', 'devices.*'); | |
| 62 |         //FIXME We should use this once laravel-datatables supports it upstream $data = IPv4::with('port.device')->select('ipv4_addresses.*'); | |
| 63 | return $this->applyScopes($data); | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * Get columns. | |
| 68 | * | |
| 69 | * @return array | |
| 70 | */ | |
| 71 | public function getColumns() | |
| 72 |     { | |
| 73 | return [ | |
| 74 | 'hostname' => [ | |
| 75 |                 'title' => trans('devices.label.hostname'), | |
| 76 | ], | |
| 77 | 'ifName' => [ | |
| 78 |                 'title' => trans('general.text.interface'), | |
| 79 | ], | |
| 80 | 'ipv4_address' => [ | |
| 81 |                 'title'    => trans('general.text.address'), | |
| 82 | ], | |
| 83 | 'ifDescr' => [ | |
| 84 |                 'title' => trans('general.text.port_descr'), | |
| 85 | ], | |
| 86 | ]; | |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Get filename for export. | |
| 91 | * | |
| 92 | * @return string | |
| 93 | */ | |
| 94 | protected function filename() | |
| 95 |     { | |
| 96 | return 'ipv4'; | |
| 97 | } | |
| 98 | ||
| 99 | } | |
| 100 | ||
| @@ 31-99 (lines=69) @@ | ||
| 28 | use App\DataTables\BaseDataTable; | |
| 29 | use App\Models\General\IPv6; | |
| 30 | ||
| 31 | class IPv6DataTable extends BaseDataTable | |
| 32 | { | |
| 33 | ||
| 34 | /** | |
| 35 | * Display ajax response. | |
| 36 | * | |
| 37 | * @return \Illuminate\Http\JsonResponse | |
| 38 | */ | |
| 39 | public function ajax() | |
| 40 |     { | |
| 41 | return $this->datatables | |
| 42 | ->eloquent($this->query()) | |
| 43 |             ->editColumn('hostname', function($data) { | |
| 44 |                 $hostname = is_null($data->device) ? trans('devices.text.deleted') : $data->device->hostname; | |
| 45 |                 return '<a href="'.url("devices/".$data->device_id).'">'.$hostname.'</a>'; | |
| 46 | }) | |
| 47 |             ->editColumn('ifName', function($data) { | |
| 48 |                 $ifName = is_null($data->ifName) ? trans('devices.text.deleted') : $data->ifName; | |
| 49 |                 return '<a href="'.url("devices/".$data->device_id."/ports/".$data->port_id).'">'.$ifName.'</a>'; | |
| 50 | }) | |
| 51 | ->make(true); | |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Get the query object to be processed by datatables. | |
| 56 | * | |
| 57 | * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | |
| 58 | */ | |
| 59 | public function query() | |
| 60 |     { | |
| 61 |         $data = IPv6::join('ports', 'ports.port_id', '=', 'ipv6_addresses.port_id')->join('devices', 'devices.device_id', '=', 'ports.device_id')->select('ipv6_addresses.*', 'ports.*', 'devices.*'); | |
| 62 |         //FIXME We should use this once laravel-datatables supports it upstream $data = IPv6::with('port.device')->select('ipv6_addresses.*'); | |
| 63 | return $this->applyScopes($data); | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * Get columns. | |
| 68 | * | |
| 69 | * @return array | |
| 70 | */ | |
| 71 | public function getColumns() | |
| 72 |     { | |
| 73 | return [ | |
| 74 | 'hostname' => [ | |
| 75 |                 'title' => trans('devices.label.hostname'), | |
| 76 | ], | |
| 77 | 'ifName' => [ | |
| 78 |                 'title' => trans('general.text.interface'), | |
| 79 | ], | |
| 80 | 'ipv6_address' => [ | |
| 81 |                 'title'    => trans('general.text.address'), | |
| 82 | ], | |
| 83 | 'ifDescr' => [ | |
| 84 |                 'title' => trans('general.text.port_descr'), | |
| 85 | ], | |
| 86 | ]; | |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Get filename for export. | |
| 91 | * | |
| 92 | * @return string | |
| 93 | */ | |
| 94 | protected function filename() | |
| 95 |     { | |
| 96 | return 'ipv6'; | |
| 97 | } | |
| 98 | ||
| 99 | } | |
| 100 | ||