Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
1d14679c
Commit
1d14679c
authored
Nov 16, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the menu dynammicaly
parent
a7548229
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
32 deletions
+59
-32
MenuController.php
Http/Controllers/Admin/MenuController.php
+15
-3
edit.blade.php
Resources/views/admin/menus/edit.blade.php
+4
-29
MenuRenderer.php
Services/MenuRenderer.php
+40
-0
No files found.
Http/Controllers/Admin/MenuController.php
View file @
1d14679c
...
...
@@ -9,6 +9,7 @@ use Modules\Menu\Http\Requests\CreateMenuRequest;
use
Modules\Menu\Http\Requests\UpdateMenuRequest
;
use
Modules\Menu\Repositories\MenuItemRepository
;
use
Modules\Menu\Repositories\MenuRepository
;
use
Modules\Menu\Services\MenuRenderer
;
class
MenuController
extends
AdminBaseController
{
...
...
@@ -24,13 +25,22 @@ class MenuController extends AdminBaseController
* @var MenuItemRepository
*/
private
$menuItem
;
/**
* @var MenuRenderer
*/
private
$menuRenderer
;
public
function
__construct
(
MenuRepository
$menu
,
MenuItemRepository
$menuItem
,
Redirector
$redirector
)
{
public
function
__construct
(
MenuRepository
$menu
,
MenuItemRepository
$menuItem
,
Redirector
$redirector
,
MenuRenderer
$menuRenderer
)
{
parent
::
__construct
();
$this
->
menu
=
$menu
;
$this
->
redirector
=
$redirector
;
$this
->
menuItem
=
$menuItem
;
$this
->
menuRenderer
=
$menuRenderer
;
}
public
function
index
()
...
...
@@ -57,7 +67,9 @@ class MenuController extends AdminBaseController
{
$menuItems
=
$this
->
menuItem
->
roots
();
return
View
::
make
(
'menu::admin.menus.edit'
,
compact
(
'menu'
,
'menuItems'
));
$menuStructure
=
$this
->
menuRenderer
->
renderForMenu
(
$menu
->
id
,
$menuItems
);
return
View
::
make
(
'menu::admin.menus.edit'
,
compact
(
'menu'
,
'menuStructure'
));
}
public
function
update
(
Menu
$menu
,
UpdateMenuRequest
$request
)
...
...
Resources/views/admin/menus/edit.blade.php
View file @
1d14679c
...
...
@@ -27,36 +27,11 @@
</a>
</div>
</div>
<?php if (!
$menuItems->isEmpty
()): ?>
<div class="
box
box
-
info
" style="
overflow
:
hidden
;
">
<div class="
box
-
body
">
<div class="
dd
">
<ol class="
dd
-
list
">
<?php foreach(
$menuItems
as
$menuItem
): ?>
<li class="
dd
-
item
" data-id="
{{
$menuItem
->
id
}}
">
<a href="
{{
URL
::
route
(
'dashboard.menuitem.edit'
,
[
$menu
->
id
,
$menuItem
->
id
])
}}
" class="
btn
btn
-
sm
btn
-
info
" style="
float
:
left
;
margin
-
right
:
15
px
;
">Edit</a>
<div class="
dd
-
handle
">
{{
$menuItem->title
}}
</div>
<?php if (!
$menuItem->children
()->get()->isEmpty()): ?>
<ol class="
dd
-
list
">
<?php foreach(
$menuItem->children
()->get() as
$leaf
): ?>
<li class="
dd
-
item
" data-id="
{{
$leaf
->
id
}}
">
<a href="
{{
URL
::
route
(
'dashboard.menuitem.edit'
,
[
$menu
->
id
,
$leaf
->
id
])
}}
" class="
btn
btn
-
sm
btn
-
info
" style="
float
:
left
;
margin
-
right
:
15
px
;
">Edit</a>
<div class="
dd
-
handle
">
{{
$leaf->title
}}
</div>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ol>
</div>
</div>
<div class="
box
box
-
info
" style="
overflow
:
hidden
;
">
<div class="
box
-
body
">
{!!
$menuStructure
!!}
</div>
<
?php endif; ?
>
<
/div
>
</div>
<div class="
col
-
md
-
6
">
<div class="
box
box
-
info
">
...
...
Services/MenuRenderer.php
0 → 100644
View file @
1d14679c
<?php
namespace
Modules\Menu\Services
;
use
Illuminate\Support\Facades\URL
;
class
MenuRenderer
{
private
$startTag
=
'<div class="dd">'
;
private
$endTag
=
'</div>'
;
private
$menu
=
''
;
public
function
renderForMenu
(
$menuId
,
$menuItems
)
{
$this
->
menu
.=
$this
->
startTag
;
$this
->
renderItemsForMenu
(
$menuId
,
$menuItems
);
$this
->
menu
.=
$this
->
endTag
;
return
$this
->
menu
;
}
private
function
renderItemsForMenu
(
$menuId
,
$items
)
{
$this
->
menu
.=
'<ol class="dd-list">'
;
foreach
(
$items
as
$item
)
{
$this
->
menu
.=
"<li class=
\"
dd-item
\"
data-id=
\"
{
$item
->
id
}
\"
>"
;
$this
->
menu
.=
'<a class="btn btn-sm btn-info"
style="float:left; margin-right: 15px;"
href="'
.
URL
::
route
(
'dashboard.menuitem.edit'
,
[
$menuId
,
$item
->
id
])
.
'">Edit</a>'
;
$this
->
menu
.=
"<div class=
\"
dd-handle
\"
>
{
$item
->
title
}
</div>"
;
if
(
!
$item
->
children
()
->
get
()
->
isEmpty
())
{
$this
->
renderItemsForMenu
(
$menuId
,
$item
->
children
()
->
get
());
}
$this
->
menu
.=
'</li>'
;
}
$this
->
menu
.=
'</ol>'
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment