1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Foundation\DataTables; |
6
|
|
|
|
7
|
|
|
use Cortex\Foundation\Models\Log; |
8
|
|
|
use Cortex\Foundation\Transformers\LogTransformer; |
9
|
|
|
|
10
|
|
|
class LogsDataTable extends AbstractDataTable |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
protected $model = Log::class; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected $transformer = LogTransformer::class; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Get the query object to be processed by dataTables. |
24
|
|
|
* |
25
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
26
|
|
|
*/ |
27
|
|
|
public function query() |
28
|
|
|
{ |
29
|
|
|
$query = $this->resource->activity(); |
|
|
|
|
30
|
|
|
|
31
|
|
|
return $this->applyScopes($query); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Display ajax response. |
36
|
|
|
* |
37
|
|
|
* @return \Illuminate\Http\JsonResponse |
38
|
|
|
*/ |
39
|
|
|
public function ajax() |
40
|
|
|
{ |
41
|
|
|
return datatables($this->query()) |
|
|
|
|
42
|
|
|
->setTransformer($this->transformer) |
43
|
|
|
->make(true); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get default builder parameters. |
48
|
|
|
* |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
protected function getBuilderParameters(): array |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
'keys' => true, |
55
|
|
|
'retrieve' => true, |
56
|
|
|
'autoWidth' => false, |
57
|
|
|
'order' => $this->order, |
58
|
|
|
'dom' => $this->dom, |
59
|
|
|
'drawCallback' => "function (settings) { |
60
|
|
|
var api = this.api(); |
61
|
|
|
|
62
|
|
|
$('#{$this->id} tbody td.dt-details-control').on('click', function () { |
|
|
|
|
63
|
|
|
var tr = $(this).closest('tr'); |
64
|
|
|
var row = api.row(tr); |
65
|
|
|
|
66
|
|
|
if (row.child.isShown()) { |
67
|
|
|
row.child.hide(); |
68
|
|
|
tr.removeClass('shown'); |
69
|
|
|
} else { |
70
|
|
|
row.child(dtFormatLogDetails(row.data().properties)).show(); |
71
|
|
|
tr.addClass('shown'); |
72
|
|
|
} |
73
|
|
|
}); |
74
|
|
|
}", |
75
|
|
|
'buttons' => [ |
76
|
|
|
'print', 'reset', 'reload', 'export', |
77
|
|
|
['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>'], |
|
|
|
|
78
|
|
|
['extend' => 'pageLength', 'text' => '<i class="fa fa-list-ol"></i> '.trans('cortex/foundation::common.limit').' <span class="caret"/>'], |
|
|
|
|
79
|
|
|
], |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get columns. |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
protected function getColumns(): array |
89
|
|
|
{ |
90
|
|
|
return [ |
91
|
|
|
'details' => ['title' => '', 'data' => null, 'defaultContent' => '', 'class' => 'dt-details-control', 'searchable' => false, 'orderable' => false], |
|
|
|
|
92
|
|
|
'causer' => ['title' => trans('cortex/foundation::common.causer'), 'name' => 'causer.username', 'searchable' => false, 'orderable' => false, 'render' => 'full.causer_route ? "<a href=\""+full.causer_route+"\">"+data+"</a>" : data', 'responsivePriority' => 0], |
|
|
|
|
93
|
|
|
'description' => ['title' => trans('cortex/foundation::common.description'), 'orderable' => false], |
94
|
|
|
'created_at' => ['title' => trans('cortex/foundation::common.date'), 'render' => "moment(data).format('MMM Do, YYYY - hh:mm:ss A')"], |
|
|
|
|
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.