|
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
|
|
|
/** |
|
11
|
|
|
* @property \Illuminate\Database\Eloquent\Model $resource |
|
12
|
|
|
* @property string $tabs |
|
13
|
|
|
* @property string $id |
|
14
|
|
|
* @property string $url |
|
15
|
|
|
*/ |
|
16
|
|
|
class ImportRecordsDataTable extends AbstractDataTable |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $model = ImportRecord::class; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $transformer = ImportRecordTransformer::class; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get the query object to be processed by dataTables. |
|
30
|
|
|
* |
|
31
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
|
|
32
|
|
|
*/ |
|
33
|
|
|
public function query() |
|
34
|
|
|
{ |
|
35
|
|
|
$query = app($this->model)->query()->where('resource', $this->resource->getMorphClass()); |
|
36
|
|
|
|
|
37
|
|
|
return $this->applyScopes($query); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Display ajax response. |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
44
|
|
|
*/ |
|
45
|
|
|
public function ajax() |
|
46
|
|
|
{ |
|
47
|
|
|
return datatables($this->query()) |
|
|
|
|
|
|
48
|
|
|
->setTransformer(app($this->transformer)) |
|
49
|
|
|
->make(true); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get default builder parameters. |
|
54
|
|
|
* |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getBuilderParameters(): array |
|
58
|
|
|
{ |
|
59
|
|
|
$columnsButton = ['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>']; |
|
|
|
|
|
|
60
|
|
|
$lengthButton = ['extend' => 'pageLength', 'text' => '<i class="fa fa-list-ol"></i> '.trans('cortex/foundation::common.limit').' <span class="caret"/>']; |
|
|
|
|
|
|
61
|
|
|
$importButton = ['extend' => 'import', 'action' => "function () { |
|
62
|
|
|
let selectedIds = []; |
|
63
|
|
|
let selected = this.rows( { selected: true } ); |
|
64
|
|
|
if (selected.count()) { |
|
65
|
|
|
selected.data().each(function (row) { |
|
66
|
|
|
selectedIds.push(row.id); |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
$.ajax({ |
|
70
|
|
|
method: 'POST', |
|
71
|
|
|
data: { |
|
72
|
|
|
selected_ids: selectedIds, |
|
73
|
|
|
_token: window.Laravel.csrfToken, |
|
74
|
|
|
}, |
|
75
|
|
|
url: window.location.pathname.replace('/import', '/hoard'), |
|
76
|
|
|
success: function(response) { |
|
77
|
|
|
let notification = function() { $.notify({message: response}, {type: 'info', mouse_over: 'pause', z_index: 9999, animate:{enter: \"animated fadeIn\", exit: \"animated fadeOut\"}}); }; if (typeof notification === 'function') { notification(); notification = null; }; |
|
|
|
|
|
|
78
|
|
|
window.location.reload(); |
|
79
|
|
|
}, |
|
80
|
|
|
}); |
|
81
|
|
|
}}"]; |
|
82
|
|
|
|
|
83
|
|
|
return array_merge([ |
|
84
|
|
|
'dom' => $this->dom, |
|
85
|
|
|
'keys' => $this->keys, |
|
86
|
|
|
'mark' => $this->mark, |
|
87
|
|
|
'order' => $this->order, |
|
88
|
|
|
'select' => $this->select, |
|
89
|
|
|
'retrieve' => $this->retrieve, |
|
90
|
|
|
'autoWidth' => $this->autoWidth, |
|
91
|
|
|
'fixedHeader' => $this->fixedHeader, |
|
92
|
|
|
'buttons' => ['print', 'reset', 'reload', $importButton, $columnsButton, $lengthButton], |
|
93
|
|
|
], $this->builderParameters); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get columns. |
|
98
|
|
|
* |
|
99
|
|
|
* @return array |
|
100
|
|
|
*/ |
|
101
|
|
|
protected function getColumns(): array |
|
102
|
|
|
{ |
|
103
|
|
|
return [ |
|
104
|
|
|
'resource' => ['title' => trans('cortex/foundation::common.resource')], |
|
105
|
|
|
'status' => ['title' => trans('cortex/foundation::common.status')], |
|
106
|
|
|
'data' => ['title' => trans('cortex/foundation::common.data'), 'orderable' => false], |
|
107
|
|
|
'created_at' => ['title' => trans('cortex/foundation::common.created_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
|
|
|
|
|
|
108
|
|
|
'updated_at' => ['title' => trans('cortex/foundation::common.updated_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
|
|
|
|
|
|
109
|
|
|
]; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.