[WIP] Setup of skeleton
This commit is contained in:
94
app/Repositories/Core/Menu/Builder.php
Normal file
94
app/Repositories/Core/Menu/Builder.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Menu;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Support\Collection;
|
||||
use Lavary\Menu\Builder as LavaryMenuBuilder;
|
||||
|
||||
use App\Repositories\Users;
|
||||
|
||||
/**
|
||||
* Class Builder.
|
||||
*
|
||||
* @property Collection $items;
|
||||
*/
|
||||
class Builder extends LavaryMenuBuilder
|
||||
{
|
||||
private $root = [];
|
||||
|
||||
/**
|
||||
* Adds an item to the menu.
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $options
|
||||
*
|
||||
* @return \Lavary\Menu\Item|Item
|
||||
*/
|
||||
public function add($title, $options = '')
|
||||
{
|
||||
$title = sprintf('<span>%s</span>', $title);
|
||||
|
||||
$id = isset($options['id']) ? $options['id'] : $this->id();
|
||||
|
||||
$item = new Item($this, $id, $title, $options);
|
||||
|
||||
if (isset($options['icon'])) {
|
||||
$item->icon($options['icon']);
|
||||
}
|
||||
|
||||
if (isset($options['role']) || isset($options['permission'])) {
|
||||
$ability = ['admin'];
|
||||
if (isset($options['role'])) {
|
||||
$ability = $ability + explode(',', $options['role']);
|
||||
}
|
||||
|
||||
$permission = null;
|
||||
if (isset($options['permission'])) {
|
||||
$permission = explode(',', $options['permission']);
|
||||
}
|
||||
|
||||
$currentUser = Auth::user();
|
||||
|
||||
if ($currentUser && $currentUser->ability($ability, $permission)) {
|
||||
$this->items->push($item);
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->items->push($item);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to a existing menu item as a submenu item.
|
||||
*
|
||||
* @param $id Id of the menu item to attach to
|
||||
* @param $title Title of the sub item
|
||||
* @param string $options
|
||||
*
|
||||
* @return Lavary\Menu\Item
|
||||
*/
|
||||
public function addTo($id, $title, $options = '')
|
||||
{
|
||||
$parent = $this->whereId($id)->first();
|
||||
|
||||
if (isset($parent)) {
|
||||
if (!isset($this->root[$parent->id])) {
|
||||
$parent->attr(['url' => '#', 'class' => 'treeview']);
|
||||
// $str = '<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>';
|
||||
// $parent->append($str);
|
||||
$this->root[$parent->id] = true;
|
||||
}
|
||||
|
||||
$item = $parent->add($title, $options);
|
||||
} else {
|
||||
$item = $this->add($title, $options);
|
||||
}
|
||||
|
||||
$item->icon('circle-o');
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
77
app/Repositories/Core/Menu/Item.php
Normal file
77
app/Repositories/Core/Menu/Item.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Menu;
|
||||
|
||||
use Lavary\Menu\Item as LavaryMenuItem;
|
||||
|
||||
class Item extends LavaryMenuItem
|
||||
{
|
||||
/**
|
||||
* Set the item icon using font-awesome.
|
||||
*
|
||||
* @param $icon
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function icon($icon)
|
||||
{
|
||||
$this->prepend(sprintf('<i class="%s"></i>', $icon));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item order.
|
||||
*
|
||||
* @param $order
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function order($order)
|
||||
{
|
||||
$this->data('order', $order);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the item active.
|
||||
*
|
||||
* @param string|array $routes
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function activeIfRoute($routes = null)
|
||||
{
|
||||
if (!empty($routes)) {
|
||||
if (is_string($routes)) {
|
||||
$routes = [$routes];
|
||||
}
|
||||
|
||||
foreach ($routes as $pattern) {
|
||||
$arr = [$pattern];
|
||||
if (if_route_pattern($arr)) {
|
||||
$this->activate();
|
||||
|
||||
if (strstr($this->title, 'circle-o')) {
|
||||
$this->title = str_replace('fa-circle-o', 'fa-dot-circle-o', $this->title);
|
||||
}
|
||||
// dump($this);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$activeClass = $this->builder->conf('active_class');
|
||||
$this->attributes['class'] = Builder::formatGroupClass(['class' => $activeClass], $this->attributes);
|
||||
$this->isActive = true;
|
||||
|
||||
if (strstr($this->title, 'circle-o')) {
|
||||
$this->title = str_replace('fa-circle-o', 'fa-dot-circle-o', $this->title);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
27
app/Repositories/Core/Menu/Logs.php
Normal file
27
app/Repositories/Core/Menu/Logs.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Sebastienheyd\Boilerplate\Menu;
|
||||
|
||||
use Sebastienheyd\Boilerplate\Menu\Builder as Builder;
|
||||
|
||||
class Logs
|
||||
{
|
||||
public function make(Builder $menu)
|
||||
{
|
||||
$menu->add(__('boilerplate::logs.menu.category'), ['permission' => 'logs', 'icon' => 'list'])
|
||||
->id('logs')
|
||||
->order(1100);
|
||||
|
||||
$menu->addTo('logs', __('boilerplate::logs.menu.stats'), [
|
||||
'route' => 'boilerplate.logs.dashboard',
|
||||
'permission' => 'logs', ])
|
||||
->order(1110)
|
||||
->activeIfRoute('boilerplate.logs.dashboard');
|
||||
|
||||
$menu->addTo('logs', __('boilerplate::logs.menu.reports'), [
|
||||
'route' => 'boilerplate.logs.list',
|
||||
'permission' => 'logs', ])
|
||||
->order(1120)
|
||||
->activeIfRoute(['boilerplate.logs.list', 'boilerplate.logs.show', 'boilerplate.logs.filter']);
|
||||
}
|
||||
}
|
||||
29
app/Repositories/Core/Menu/Menu.php
Normal file
29
app/Repositories/Core/Menu/Menu.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Menu;
|
||||
|
||||
use Lavary\Menu\Menu as LavaryMenu;
|
||||
use View;
|
||||
|
||||
class Menu extends LavaryMenu
|
||||
{
|
||||
public function make($name, $callback)
|
||||
{
|
||||
if (is_callable($callback)) {
|
||||
if (!array_key_exists($name, $this->menu)) {
|
||||
$this->menu[$name] = new Builder($name, $this->loadConf($name));
|
||||
}
|
||||
|
||||
// Registering the items
|
||||
call_user_func($callback, $this->menu[$name]);
|
||||
|
||||
// Storing each menu instance in the collection
|
||||
$this->collection->put($name, $this->menu[$name]);
|
||||
|
||||
// Make the instance available in all views
|
||||
View::share($name, $this->menu[$name]);
|
||||
|
||||
return $this->menu[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
33
app/Repositories/Core/Menu/Users.php
Normal file
33
app/Repositories/Core/Menu/Users.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Menu;
|
||||
|
||||
use App\Repositories\Core\Menu\Builder as Builder;
|
||||
|
||||
class Users
|
||||
{
|
||||
public function make(Builder $menu)
|
||||
{
|
||||
$menu->add(__('boilerplate::layout.access'), ['icon' => 'users'])
|
||||
->id('access')
|
||||
->order(1000);
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.list.title'), [
|
||||
'route' => 'boilerplate.users.index',
|
||||
'permission' => 'users_crud', ])
|
||||
->activeIfRoute(['boilerplate.users.index', 'boilerplate.users.edit']);
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.create.title'), [
|
||||
'route' => 'boilerplate.users.create',
|
||||
'permission' => 'users_crud', ])
|
||||
->activeIfRoute('boilerplate.users.create');
|
||||
|
||||
$menu->addTo('access', __('boilerplate::layout.role_management'), [
|
||||
'route' => 'boilerplate.roles.index',
|
||||
'permission' => 'roles_crud', ])
|
||||
->activeIfRoute('boilerplate.roles.*');
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.profile.title'), ['route' => 'boilerplate.user.profile'])
|
||||
->activeIfRoute('boilerplate.user.profile');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user