1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Attributes\DataTables\Adminarea; |
6
|
|
|
|
7
|
|
|
use Rinvex\Attributes\Models\Attribute; |
8
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
9
|
|
|
|
10
|
|
|
class AttributesDataTable extends AbstractDataTable |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
protected $model = Attribute::class; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected $builderParameters = [ |
21
|
|
|
'drawCallback' => 'function (settings) { |
22
|
|
|
var lastGroup = null; |
23
|
|
|
var api = this.api(); |
24
|
|
|
var colspan = api.columns(\':visible\').count(); |
25
|
|
|
var rows = api.rows({page:\'current\'}).nodes(); |
26
|
|
|
|
27
|
|
|
api.column(\'group:name\', {page:\'current\'} ).data().each(function (rowGroup, rowIndex) { |
28
|
|
|
if (lastGroup !== rowGroup) { |
29
|
|
|
$(rows).eq(rowIndex).before( |
30
|
|
|
\'<tr class="attribute-group"><td colspan="\'+colspan+\'"><strong>\'+(rowGroup ? rowGroup : "No Group")+\'</strong></td></tr>\' |
|
|
|
|
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
lastGroup = rowGroup; |
34
|
|
|
} |
35
|
|
|
}); |
36
|
|
|
}', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the query object to be processed by dataTables. |
41
|
|
|
* |
42
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
public function query() |
45
|
|
|
{ |
46
|
|
|
$locale = app()->getLocale(); |
47
|
|
|
$query = app($this->model)->query()->orderBy('group', 'ASC')->orderBy('sort_order', 'ASC')->orderBy("name->\${$locale}", 'ASC'); |
|
|
|
|
48
|
|
|
|
49
|
|
|
return $this->applyScopes($query); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Display ajax response. |
54
|
|
|
* |
55
|
|
|
* @return \Illuminate\Http\JsonResponse |
56
|
|
|
*/ |
57
|
|
|
public function ajax() |
58
|
|
|
{ |
59
|
|
|
return datatables($this->query()) |
60
|
|
|
->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1') |
61
|
|
|
->make(true); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get columns. |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
protected function getColumns(): array |
70
|
|
|
{ |
71
|
|
|
$link = config('cortex.foundation.route.locale_prefix') |
72
|
|
|
? '"<a href=\""+routes.route(\'adminarea.attributes.edit\', {attribute: full.slug, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"' |
|
|
|
|
73
|
|
|
: '"<a href=\""+routes.route(\'adminarea.attributes.edit\', {attribute: full.slug})+"\">"+data+"</a>"'; |
74
|
|
|
|
75
|
|
|
return [ |
76
|
|
|
'name' => ['title' => trans('cortex/attributes::common.name'), 'render' => $link, 'responsivePriority' => 0], |
|
|
|
|
77
|
|
|
'slug' => ['title' => trans('cortex/attributes::common.slug')], |
78
|
|
|
'type' => ['title' => trans('cortex/attributes::common.type'), 'render' => 'Lang.trans(\'cortex/attributes::common.\'+data)'], |
|
|
|
|
79
|
|
|
'group' => ['title' => trans('cortex/attributes::common.group'), 'visible' => false], |
80
|
|
|
'is_collection' => ['title' => trans('cortex/attributes::common.collection')], |
81
|
|
|
'is_required' => ['title' => trans('cortex/attributes::common.required')], |
82
|
|
|
'created_at' => ['title' => trans('cortex/attributes::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
83
|
|
|
'updated_at' => ['title' => trans('cortex/attributes::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.