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