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
|
|
|
/** |
11
|
|
|
* @property string $resource |
12
|
|
|
* @property string $tabs |
13
|
|
|
* @property string $id |
14
|
|
|
*/ |
15
|
|
|
class ImportLogsDataTable extends AbstractDataTable |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected $model = Log::class; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
protected $transformer = LogTransformer::class; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get the query object to be processed by dataTables. |
29
|
|
|
* |
30
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
31
|
|
|
*/ |
32
|
|
|
public function query() |
33
|
|
|
{ |
34
|
|
|
$query = Log::where('description', 'imported')->where('subject_type', $this->resource); |
35
|
|
|
|
36
|
|
|
return $this->applyScopes($query); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Display ajax response. |
41
|
|
|
* |
42
|
|
|
* @return \Illuminate\Http\JsonResponse |
43
|
|
|
*/ |
44
|
|
|
public function ajax() |
45
|
|
|
{ |
46
|
|
|
return datatables($this->query()) |
|
|
|
|
47
|
|
|
->setTransformer(app($this->transformer)) |
48
|
|
|
->make(true); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get default builder parameters. |
53
|
|
|
* |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
|
|
protected function getBuilderParameters(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
'dom' => $this->dom, |
60
|
|
|
'keys' => $this->keys, |
61
|
|
|
'order' => $this->order, |
62
|
|
|
'retrieve' => $this->retrieve, |
63
|
|
|
'autoWidth' => $this->autoWidth, |
64
|
|
|
'drawCallback' => "function (settings) { |
65
|
|
|
var api = this.api(); |
66
|
|
|
|
67
|
|
|
$('#{$this->id} tbody td.dt-details-control').on('click', function () { |
68
|
|
|
var tr = $(this).closest('tr'); |
69
|
|
|
var row = api.row(tr); |
70
|
|
|
|
71
|
|
|
if (row.child.isShown()) { |
72
|
|
|
row.child.hide(); |
73
|
|
|
tr.removeClass('shown'); |
74
|
|
|
} else { |
75
|
|
|
row.child(dtFormatLogDetails(row.data().properties)).show(); |
76
|
|
|
tr.addClass('shown'); |
77
|
|
|
} |
78
|
|
|
}); |
79
|
|
|
}", |
80
|
|
|
'buttons' => [ |
81
|
|
|
'print', 'reset', 'reload', 'export', |
82
|
|
|
['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>'], |
83
|
|
|
['extend' => 'pageLength', 'text' => '<i class="fa fa-list-ol"></i> '.trans('cortex/foundation::common.limit').' <span class="caret"/>'], |
84
|
|
|
], |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get columns. |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
protected function getColumns(): array |
94
|
|
|
{ |
95
|
|
|
return [ |
96
|
|
|
'details' => ['title' => '', 'data' => null, 'defaultContent' => '', 'class' => 'dt-details-control', 'searchable' => false, 'orderable' => false], |
97
|
|
|
'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], |
98
|
|
|
'description' => ['title' => trans('cortex/foundation::common.description'), 'orderable' => false], |
99
|
|
|
'created_at' => ['title' => trans('cortex/foundation::common.date'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
100
|
|
|
]; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.