1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Foundation\DataTables; |
6
|
|
|
|
7
|
|
|
use Cortex\Foundation\Models\ImportRecord; |
8
|
|
|
use Cortex\Foundation\Transformers\ImportRecordTransformer; |
9
|
|
|
|
10
|
|
|
class ImportRecordsDataTable extends AbstractDataTable |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
protected $model = ImportRecord::class; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected $transformer = ImportRecordTransformer::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 = app($this->model)->query()->where('resource', $this->resource->getMorphClass()); |
|
|
|
|
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(app($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
|
|
|
$columnsButton = ['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>']; |
|
|
|
|
54
|
|
|
$lengthButton = ['extend' => 'pageLength', 'text' => '<i class="fa fa-list-ol"></i> '.trans('cortex/foundation::common.limit').' <span class="caret"/>']; |
|
|
|
|
55
|
|
|
$importButton = ['extend' => 'import', 'action' => "function () { |
56
|
|
|
let selectedIds = []; |
57
|
|
|
let selected = this.rows( { selected: true } ); |
58
|
|
|
if (selected.count()) { |
59
|
|
|
selected.data().each(function (row) { |
60
|
|
|
console.log(row); |
61
|
|
|
selectedIds.push(row.id); |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
$.ajax({ |
65
|
|
|
method: 'POST', |
66
|
|
|
data: { |
67
|
|
|
selected_ids: selectedIds, |
68
|
|
|
_token: window.Laravel.csrfToken, |
69
|
|
|
}, |
70
|
|
|
url: window.location.pathname.replace('/import', '/hoard'), |
71
|
|
|
success: function(response) { |
72
|
|
|
let notification = function() { $.notify({message: response}, {type: 'info', mouse_over: 'pause', z_index: 9999, animate:{enter: \"animated fadeIn\", exit: \"animated fadeOut\"}}); }; console.log('asd'); if (typeof notification === 'function') { notification(); notification = null; }; |
|
|
|
|
73
|
|
|
window.location.reload(); |
74
|
|
|
}, |
75
|
|
|
}); |
76
|
|
|
}}"]; |
77
|
|
|
|
78
|
|
|
return array_merge([ |
79
|
|
|
'select' => true, |
80
|
|
|
'stateSave' => true, |
81
|
|
|
'dom' => $this->dom, |
82
|
|
|
'keys' => false, |
83
|
|
|
'mark' => $this->mark, |
84
|
|
|
'order' => $this->order, |
85
|
|
|
'retrieve' => $this->retrieve, |
86
|
|
|
'autoWidth' => $this->autoWidth, |
87
|
|
|
'searchPane' => $this->searchPane, |
88
|
|
|
'fixedHeader' => $this->fixedHeader, |
89
|
|
|
'buttons' => ['print', 'reset', 'reload', $importButton, $columnsButton, $lengthButton], |
90
|
|
|
], $this->builderParameters); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get columns. |
95
|
|
|
* |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
protected function getColumns(): array |
99
|
|
|
{ |
100
|
|
|
return [ |
101
|
|
|
'resource' => ['title' => trans('cortex/foundation::common.resource')], |
102
|
|
|
'status' => ['title' => trans('cortex/foundation::common.status')], |
103
|
|
|
'data' => ['title' => trans('cortex/foundation::common.data'), 'orderable' => false], |
104
|
|
|
'created_at' => ['title' => trans('cortex/foundation::common.created_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
|
|
|
|
105
|
|
|
'updated_at' => ['title' => trans('cortex/foundation::common.updated_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
|
|
|
|
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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.