blob: 8539e0ec78ec35a028fbc18e48b3ede17bea07fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
<?php
namespace Lightscale\LaralightTables;
use Lightscale\LaralightTables\Toolbar\Item as ToolbarItem;
use Lightscale\LaralightTables\Toolbar\Search as SearchItem;
use Lightscale\LaralightTables\Toolbar\PageSize as PageSizeItem;
use Lightscale\LaralightTables\Toolbar\Filter as FilterItem;
use Illuminate\View\View;
use Illuminate\Support\Collection;
class Toolbar
{
protected ?SearchItem $searchItem = null;
protected ?PageSizeItem $pageSizeItem = null;
protected Collection $startItems;
protected Collection $midItems;
protected Collection $endItems;
protected Collection $filterItems;
public function __construct(
private TableComponent $table
)
{
$this->startItems = collect();
$this->midItems = collect();
$this->endItems = collect();
$this->filterItems = collect();
}
private function addItem(Collection $list, ToolbarItem $item): static
{
$item->setToolbar($this);
if ($item instanceof FilterItem) {
$this->filterItems->push($item);
}
else if ($item instanceof PageSizeItem) {
$this->pageSizeItem = $item;
}
else if ($item instanceof SearchItem) {
$this->searchItem = $item;
}
$list->push($item);
return $this;
}
public function addStartItem(ToolbarItem $item): static
{
return $this->addItem($this->startItems, $item);
}
public function addMidItem(ToolbarItem $item): static
{
return $this->addItem($this->midItems, $item);
}
public function addEndItem(ToolbarItem $item): static
{
return $this->addItem($this->endItems, $item);
}
public function getTable(): TableComponent
{
return $this->table;
}
public function getSearch(): ?SearchItem
{
return $this->searchItem;
}
public function getPageSize(): ?PageSizeItem
{
return $this->pageSizeItem;
}
public function getFilters(): Collection
{
return $this->filterItems;
}
public function render(): View
{
return view('laralight-tables::toolbar', [
'startItems' => $this->startItems,
'midItems' => $this->midItems,
'endItems' => $this->endItems,
]);
}
}
|