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
|
|
|
* Get default builder parameters. |
36
|
|
|
* |
37
|
|
|
* @return array |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
protected function getBuilderParameters() |
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
|
|
'keys' => true, |
43
|
|
|
'autoWidth' => false, |
44
|
|
|
'order' => [[0 => 'asc']], |
45
|
|
|
'dom' => "<'row'<'col-sm-6'B><'col-sm-6'f>> <'row'r><'row'<'col-sm-12't>> <'row'<'col-sm-5'i><'col-sm-7'p>>", |
|
|
|
|
46
|
|
|
'drawCallback' => "function (settings) { |
47
|
|
|
var api = this.api(); |
48
|
|
|
|
49
|
|
|
$('#{$this->id} tbody td.dt-details-control').on('click', function () { |
|
|
|
|
50
|
|
|
var tr = $(this).closest('tr'); |
51
|
|
|
var row = api.row(tr); |
52
|
|
|
|
53
|
|
|
if (row.child.isShown()) { |
54
|
|
|
row.child.hide(); |
55
|
|
|
tr.removeClass('shown'); |
56
|
|
|
} else { |
57
|
|
|
row.child(dtFormatLogDetails(row.data().properties)).show(); |
58
|
|
|
tr.addClass('shown'); |
59
|
|
|
} |
60
|
|
|
}); |
61
|
|
|
}", |
62
|
|
|
'buttons' => [ |
63
|
|
|
'print', 'reset', 'reload', 'export', |
64
|
|
|
['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>'], |
|
|
|
|
65
|
|
|
['extend' => 'pageLength', 'text' => '<i class="fa fa-list-ol"></i> '.trans('cortex/foundation::common.limit').' <span class="caret"/>'], |
|
|
|
|
66
|
|
|
], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get columns. |
72
|
|
|
* |
73
|
|
|
* @return array |
|
|
|
|
74
|
|
|
*/ |
75
|
|
|
protected function getColumns() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
'details' => ['title' => '', 'data' => null, 'defaultContent' => '', 'class' => 'dt-details-control', 'searchable' => false, 'orderable' => false], |
|
|
|
|
79
|
|
|
'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], |
|
|
|
|
80
|
|
|
'description' => ['title' => trans('cortex/foundation::common.description'), 'orderable' => false], |
81
|
|
|
'created_at' => ['title' => trans('cortex/foundation::common.date'), 'render' => "moment(data).format('MMM Do, YYYY - hh:mm:ss A')"], |
|
|
|
|
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.