1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\Core\Layout\Seeds; |
4
|
|
|
|
5
|
|
|
use atk4\ui\Menu as BaseMenu; |
6
|
|
|
use atk4\ui\FormField\Input; |
7
|
|
|
use Illuminate\Support\Facades\URL; |
8
|
|
|
use Epesi\Core\Layout\Integration\Joints\UserMenuJoint; |
9
|
|
|
use Illuminate\Support\Facades\Auth; |
10
|
|
|
|
11
|
|
|
class RightMenu extends BaseMenu |
12
|
|
|
{ |
13
|
|
|
protected $entries; |
14
|
|
|
protected $tools; |
15
|
|
|
|
16
|
|
|
protected $userMenu; |
17
|
|
|
|
18
|
|
|
protected $userMenuLabel; |
19
|
|
|
|
20
|
|
|
public function init() |
21
|
|
|
{ |
22
|
|
|
parent::init(); |
23
|
|
|
|
24
|
|
|
$this->entries = collect(); |
25
|
|
|
|
26
|
|
|
$this->tools = collect(); |
27
|
|
|
|
28
|
|
|
$this->addItem()->add(new Input([ |
29
|
|
|
'placeholder' => 'Search', |
30
|
|
|
'icon' => 'search' |
31
|
|
|
]))->addClass('transparent'); |
32
|
|
|
|
33
|
|
|
// $messageMenu = $this->menuRight->addMenu(['', 'icon' => 'envelope outline']); |
34
|
|
|
|
35
|
|
|
$this->addItem([ |
36
|
|
|
'icon' => 'th' |
37
|
|
|
], new LaunchPad($this))->setAttr([ |
|
|
|
|
38
|
|
|
'title' => __('Launchpad'), |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
foreach(UserMenuJoint::collect() as $joint) { |
42
|
|
|
foreach ($joint->tools()?: [] as $tool) { |
43
|
|
|
$this->addTool($tool); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
foreach ($joint->entries()?: [] as $entry) { |
47
|
|
|
$this->addEntry($entry); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->userMenu = $this->addMenu([ |
52
|
|
|
$this->getUserMenuLabel(), |
53
|
|
|
'icon' => 'user' |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
$this->addEntry(['Perspective', 'icon' => 'users']); |
57
|
|
|
$this->addEntry(['My Contact', 'icon' => 'contact']); |
58
|
|
|
$this->addEntry(['My Company', 'icon' => 'users']); |
59
|
|
|
|
60
|
|
|
$this->addEntry([ |
61
|
|
|
'item' => ['Logout', 'icon' => 'sign out', 'attr' => ['onclick' => "event.preventDefault();$('#logout-form').submit();"]], |
62
|
|
|
'action' => url('logout'), |
63
|
|
|
'group' => '10000:user', |
64
|
|
|
'callback' => function ($item){ |
65
|
|
|
$logoutForm = $item->add(['View', 'attr' => ['method' => 'POST', 'action' => URL::to('logout')]])->setElement('form')->addStyle(['display' => 'none']); |
66
|
|
|
$logoutForm->id = 'logout-form'; |
67
|
|
|
$logoutForm->add(['View', 'attr' => ['type' => 'hidden', 'name' => '_token', 'value' => csrf_token()]])->setElement('input'); |
68
|
|
|
}, |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setUserMenuLabel($label) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$label = $this->userMenuLabel; |
|
|
|
|
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getUserMenuLabel() |
80
|
|
|
{ |
81
|
|
|
return $this->userMenuLabel?: Auth::user()->name; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function addEntry($entry) |
85
|
|
|
{ |
86
|
|
|
$entry = collect(array_merge(['item' => $entry, 'group' => '00500:general', 'weight' => 10], $entry)); |
87
|
|
|
|
88
|
|
|
if (! $entry->get('item')) return; |
89
|
|
|
|
90
|
|
|
$this->entries->add($entry); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function addTool($tool) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function renderView() |
99
|
|
|
{ |
100
|
|
|
$this->addRegisteredEntries(); |
101
|
|
|
|
102
|
|
|
parent::renderView(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
protected function addRegisteredEntries() |
106
|
|
|
{ |
107
|
|
|
$empty = true; |
108
|
|
|
foreach ($this->entries->groupBy('group')->sortKeys() as $group) { |
109
|
|
|
if (!$empty) $this->userMenu->addDivider(); |
110
|
|
|
|
111
|
|
|
foreach ($group->sortBy('weight') as $entry) { |
112
|
|
|
$empty = false; |
113
|
|
|
|
114
|
|
|
$item = $this->userMenu->addItem($entry['item'], $entry->get('action')); |
115
|
|
|
|
116
|
|
|
if (! $callback = $entry->get('callback')) continue; |
117
|
|
|
|
118
|
|
|
$callback($item); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |