1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\Core\Layout\Seeds; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use atk4\ui\Menu as BaseMenu; |
7
|
|
|
use Epesi\Core\Layout\Integration\Joints\NavMenuJoint; |
8
|
|
|
|
9
|
|
|
class NavMenu extends BaseMenu |
10
|
|
|
{ |
11
|
|
|
public $ui = 'inverted nav menu'; |
12
|
|
|
|
13
|
|
|
public function init() |
14
|
|
|
{ |
15
|
|
|
parent::init(); |
16
|
|
|
|
17
|
|
|
$this->addHeader($this->app->title); |
18
|
|
|
|
19
|
|
|
$items = collect(); |
20
|
|
|
foreach(NavMenuJoint::collect() as $joint) { |
21
|
|
|
$items = $items->merge($joint->items()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$this->addItems($this, $items); |
25
|
|
|
|
26
|
|
|
// $this->js(true)->find('.toggle-group .header')->click(new jsFunction(['e'], [new jsExpression('$(e.target).next(".menu").slideToggle()')]))->click(); |
27
|
|
|
|
28
|
|
|
// $this->app->addStyle(' |
29
|
|
|
// .toggle-group .header { |
30
|
|
|
// cursor: pointer; |
31
|
|
|
// } |
32
|
|
|
// '); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function addItems($menu, Collection $items) |
36
|
|
|
{ |
37
|
|
|
$items->sort(function ($entry1, $entry2) { |
38
|
|
|
$weight1 = $entry1['weight']?? 10; |
39
|
|
|
$weight2 = $entry2['weight']?? 10; |
40
|
|
|
|
41
|
|
|
return $weight1 <=> $weight2; |
42
|
|
|
})->map(function($entry, $caption) use ($menu) { |
43
|
|
|
if (! ($entry['access'] ?? true)) return; |
44
|
|
|
|
45
|
|
|
if (!is_array($entry)) { |
46
|
|
|
$entry = ['action' => $entry]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$entry['item'] = $entry['item'] ?? $caption; |
50
|
|
|
|
51
|
|
|
if (is_array($entry['item'])) { |
52
|
|
|
$entry['item'] = [$caption] + $entry['item']; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if ($subitems = $entry['menu'] ?? []) { |
56
|
|
|
$submenu = $menu->addMenu($entry['item']); |
57
|
|
|
|
58
|
|
|
self::addItems($submenu, collect($subitems)); |
59
|
|
|
} |
60
|
|
|
elseif ($subitems = $entry['group'] ?? []) { |
61
|
|
|
$subgroup = $menu->addGroup($entry['item']); |
62
|
|
|
|
63
|
|
|
self::addItems($subgroup, collect($subitems)); |
64
|
|
|
} |
65
|
|
|
else { |
66
|
|
|
$menu->addItem($entry['item'], $entry['action'] ?? ''); |
67
|
|
|
} |
68
|
|
|
}); |
69
|
|
|
} |
70
|
|
|
} |