-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed composer package kodicms/laravel-navigation Example AdminSection::addMenuPage(\App\Model\News::class)->setItems(function() { AdminSection::addMenuPage()->setTitle('test')->setUrl('user/profile'); });
- Loading branch information
1 parent
78e56c6
commit 3b7f298
Showing
10 changed files
with
385 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
resources/views/default/_partials/navigation/navigation.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@foreach($pages as $page) | ||
{!! $page->render() !!} | ||
@endforeach |
22 changes: 22 additions & 0 deletions
22
resources/views/default/_partials/navigation/page.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@if($hasChild) | ||
<li class="treeview @if($isActive) active @endif"> | ||
<a href="#"> | ||
{!! $icon !!} | ||
<span>{!! $title !!}</span> | ||
<i class="fa fa-angle-left pull-right"></i> | ||
</a> | ||
|
||
<ul class="treeview-menu"> | ||
@foreach($pages as $page) | ||
{!! $page->render() !!} | ||
@endforeach | ||
</ul> | ||
</li> | ||
@else | ||
<li @if($isActive) class="active" @endif> | ||
<a href="{{ $url }}"> | ||
{!! $icon !!} | ||
<span>{!! $title !!}</span> | ||
</a> | ||
</li> | ||
@endif |
24 changes: 0 additions & 24 deletions
24
resources/views/default/_partials/navigation/sections.blade.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace SleepingOwl\Admin; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Contracts\Support\Renderable; | ||
use Illuminate\Support\Collection; | ||
use SleepingOwl\Admin\Navigation\Page; | ||
|
||
class Navigation implements Renderable, Arrayable | ||
{ | ||
/** | ||
* @var Page | ||
*/ | ||
protected static $currentPage; | ||
|
||
/** | ||
* @var Collection | ||
*/ | ||
protected $items; | ||
|
||
public function __construct() | ||
{ | ||
$this->items = new Collection(); | ||
} | ||
|
||
/** | ||
* @param string|null $class | ||
* | ||
* @return Page | ||
*/ | ||
public function addPage($class = null) | ||
{ | ||
$page = new Page($class); | ||
|
||
if (is_null(static::$currentPage)) { | ||
static::$currentPage = $this; | ||
} | ||
|
||
static::$currentPage->getItems()->push($page); | ||
|
||
return $page; | ||
} | ||
|
||
/** | ||
* @return Collection | ||
*/ | ||
public function getItems() | ||
{ | ||
return $this->items; | ||
} | ||
|
||
/** | ||
* @param \Closure $callback | ||
* | ||
* @return $this | ||
*/ | ||
public function setItems(\Closure $callback) | ||
{ | ||
$oldPage = static::$currentPage; | ||
static::$currentPage = $this; | ||
call_user_func($callback); | ||
static::$currentPage = $oldPage; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasChild() | ||
{ | ||
return $this->getItems()->count() > 0; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return $this->getItems(); | ||
} | ||
|
||
protected function findActive() | ||
{ | ||
$this->getItems()->each(function(Page $page) { | ||
if ($page->getUrl() == url()->current()) { | ||
$page->setActive(); | ||
} | ||
$page->findActive(); | ||
}); | ||
} | ||
|
||
/** | ||
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory | ||
*/ | ||
public function render() | ||
{ | ||
$this->items = $this->getItems()->sortBy(function ($page, $key) { | ||
return $page->getPriority(); | ||
}); | ||
|
||
$this->findActive(); | ||
|
||
return app('sleeping_owl.template')->view('_partials.navigation.navigation', [ | ||
'pages' => $this->toArray() | ||
])->render(); | ||
} | ||
} |
Oops, something went wrong.